Excuse me, I'm looking to get to Comment Town?
Comment Town hasn't been here for eighty years. (We incorporated into Comment City).
My blog is a static website. I want visitors to be able to leave comments, but I didn't want to use a bloated third party plugin (like disqus) or run a backend to store the comments. My solution is to store my comments directly in the same repository as the static site. Each blog page comes with a comments
file, and adding a comment would involve opening a pull request to that file, which would be incorporated into the blog during the build step. My static site is set up to deploy with each new commit, so after I merge the comment, it appears on the website after about a minute.
This serverless function recieves a comment via form submission from a static site, then opens a PR to the static site adding the comment.
I host this function on vercel and my static site on github, but I imagine setting it up on a different provider necessitates similar procedures.
- install the vercel cli, then run
vercel
once to log in. - set up environment variables in the project:
GITHUB_AUTH_TOKEN
, create a new gitub personal access tokenGITHUB_USER
, your github usernameGITHUB_REPO
, the repository name of your static site.
- run
vercel dev
from the root folder to host the function locally. Vercel has separate dev environment variables and production environment variables, so if you use vercel's local development feature (which is great, highly recommended) you will need to set the environment variables in both places.- download development local variables by running
vercel env pull
- download development local variables by running
You might need to restructure the files if you use a different cloud provider.
I tested the script by running curl
against the endpoint, I saved it in api/test.sh
.
I host this function on vercel. To deploy, run from the root folder: vercel --prod
. (you will have to set up the project the first time).
You can set up your vercel project to automatically deploy with every github commit (it's great!)