Code Monkey home page Code Monkey logo

jamstack-cfp's Introduction

JAMStack CFP

This is an example call for papers application, made to showcase how to make use of GitHub Actions to add user generated content to your JAMStack static site! It's built with Gridsome but the same approach can be done with Gatsby or any other static generator.

How it works

When a user submits the from, a serverless function triggers a GitHub workflow that generates a pull request that adds a json file to the repository. Once this PR is merged, Gridsome generates the site statically listing all the accepted submissions. Connecting the GitHub's GraphQL API to Gridsome, it also generates the pending submissions list from the open PRs. The result is a 100% static site that is able to handle user generated content!

Authentication

To make it easier to test and play with, I have not added any authentication method, but you can easily connect the app with a GitHub OAuth app or similar to prevent abuse and be able to communicate with users. Just take into consideration not to store any sensitive information if your repository is public (I'm not sure if storing it in a private repository has any legal issues).

When to use it

Obviously, this approach has some limitations. The submission process can take a few minutes, so if you need immediate feedback it's not a good option. Same if the amount of submissions you need to handle in a short period of time is super high. As a rule of thumb, this is a good usecase for a proof of concept, MVP or small app.

Fork the repository

Feel free to fork this repository and adapt it to your project. If you do, I'd love to hear about it! Open an issue or reach me on twitter.

You need to add a GH_TOKEN_PERSONAL secret in your repository settings, containing a token with repo scope. You can create the token in your GitHub settings. It's going to be used to run GitHub Action workflows, connect with GitHub's GraphQL API and to be able to trigger a repository dispatch event to your repository.

You will need to update the hardcoded owner and name values in src/pages/Pending.vue and functions/submit.js to match your GitHub's uername and repository name.

Run the project locally

Create an .env file containing the GH_TOKEN_PERSONAL variable, then run:

npm run develop

Deploy

Netlify

Deploying to Netlify is the easiest option, as we need a serverless function.

Add the GH_TOKEN_PERSONAL environment variable in your project settings.

You will also need to configure a hook if you want your page to be rebuilt when a new submission PR is opened. Create a Build hook in your settings. Copy the url, and go to your GitHub repository settings: https://github.com/your-username/your-repo/settings/hooks. Add a new webook, paste the URL and select Let me select individual events., then choose Pull requests.

Ready to go! ๐Ÿš€

GitHub pages

You can choose to deploy to GitHub pages too. The front-end deployment workflow is ready, including the trigger to rebuild the page after a PR is open, but you should handle yourself the deployment of the serverless function to AWS or similar.

If you are not serving the project from the root of your domain (usually the case when using GitHub pages, when deploying to https://your-username.github.io/your-repo), you should also a BASE_PATH variable with the correct path (/your-repo) to your repository's secrets in order to load the assets correctly.

jamstack-cfp's People

Contributors

nuria-fl avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.