Like many static site's we use markdown + github for all of our blog content.
Having content under version control comes with some great benefits:
It's Open - Anyone can submit/update content & fix typos via pull requests
Version control - Roll back & see the history of any given post
No CMS lock in - We can easily port to any static site generator
It's just simple - No user accounts to manage, no CMS software to upgrade, no plugins to install.
All that said, there are some missing features when it comes to running your site or blog via a static site generator.
Lacking the ability to schedule posts to publish at a specific time is a pain. Publishing content to our static site & blog have been a manual process.
We had to physically be at our keyboards & use our meat sticks to click the "merge" button in github.
How antiquated...
So I thought to myself:
There has got to be a better way... a better serverless way.
#Introducing the Post Scheduler for Static Websites
The post scheduler is a serverless project that gives static site owners the ability to schedule posts (or other site content).
It works with any static site setup (Jekyll, Hugo, Phenomic, Gatsby etc.)
How much does it cost?:
It's free & open source project. You can easily run under this under the generous free tier of AWS.
Just clone it down, add in your repo details and sls deploy it into your AWS account.
Before:
Late night manual merges 🙈
After:
Sipping margaritas on the beach while posts are being published automatically. 🎉
A github webhook fires when a pull request (aka new posts or site content) is updated.
If the pull request comment has a comment matching schedule(MM/DD/YYYY H:MM pm) & the person is a collaborator on the project, the post/content gets scheduled for you.
A serverless cron job runs every hour to check if a post is ready to be published.
When the post is ready to be published, the cron function automatically merges the branch into master and your site, if you have CI/CD built in, will redeploy itself.
To cancel scheduled posts, delete the scheduled comment and it will unschedule the branch.
serviceName - name of the service that will appear in your AWS account
region - AWS region to deploy the functions and database in
TIMEZONE - Timezone the cron runs on. See timezone.json for available options
CRON - How often you want to check for scheduled posts? See the AWS cron docs or serverless schedule docs for more information. Default: every hour on the hour
GITHUB_REPO - The owner/repoName of your repository
GITHUB_WEBHOOK_SECRET - Any string you want. This gets plugged into your webhook settings
GITHUB_API_TOKEN - Personal access token. See below for additonal info
GITHUB_USERNAME - Your github username. Used for requests to github
#3. Deploy the service with serverless deploy. If you need to setup serverless, please see these install instructions.
Static Site Post Scheduler: Using AWS Lambda and Serverless to Schedule Blog Posts
http://ift.tt/2mxlnM2
Like many static site's we use markdown + github for all of our blog content.
Having content under version control comes with some great benefits:
All that said, there are some missing features when it comes to running your site or blog via a static site generator.
Lacking the ability to schedule posts to publish at a specific time is a pain. Publishing content to our static site & blog have been a manual process.
We had to physically be at our keyboards & use our meat sticks to click the "merge" button in github.
How antiquated...
So I thought to myself:
#Introducing the Post Scheduler for Static Websites
The post scheduler is a serverless project that gives static site owners the ability to schedule posts (or other site content).
It works with any static site setup (Jekyll, Hugo, Phenomic, Gatsby etc.)
How much does it cost?:
It's free & open source project. You can easily run under this under the generous free tier of AWS.
Just clone it down, add in your repo details and
sls deploy
it into your AWS account.Before:
Late night manual merges 🙈
After:
Sipping margaritas on the beach while posts are being published automatically. 🎉
#Show me the 💸 (demo)
VIDEOWatch the rest of the playlist on youtube
#How does it work?
VIDEOA github webhook fires when a pull request (aka new posts or site content) is updated.
If the pull request comment has a comment matching
schedule(MM/DD/YYYY H:MM pm)
& the person is a collaborator on the project, the post/content gets scheduled for you.A serverless cron job runs every hour to check if a post is ready to be published.
When the post is ready to be published, the cron function automatically merges the branch into
master
and your site, if you have CI/CD built in, will redeploy itself.To cancel scheduled posts, delete the scheduled comment and it will unschedule the branch.
#Github Webhook Architecture
#Cron Job Architecture
#How to Install
VIDEO#1. Clone down the repository and run
npm install
to install the dependencies#2. Duplicate
config.prod.example.json
into a new file calledconfig.prod.json
and insert your Github username, API token, and webhook secret// config.prod.json { "serviceName": "blog-scheduler", "region": "us-west-2", "TIMEZONE": "America/Los_Angeles", "CRON": "cron(0 * * * ? *)", "GITHUB_REPO": "serverless/blog", "GITHUB_WEBHOOK_SECRET": "YOUR_GITHUB_WEBHOOK_SECRET_HERE", "GITHUB_API_TOKEN": "YOUR_GITHUB_API_TOKEN_HERE", "GITHUB_USERNAME": "YOUR_GITHUB_USERNAME_HERE" }
serviceName
- name of the service that will appear in your AWS accountregion
- AWS region to deploy the functions and database inTIMEZONE
- Timezone the cron runs on. Seetimezone.json
for available optionsCRON
- How often you want to check for scheduled posts? See the AWS cron docs or serverlessschedule
docs for more information. Default: every hour on the hourGITHUB_REPO
- Theowner/repoName
of your repositoryGITHUB_WEBHOOK_SECRET
- Any string you want. This gets plugged into your webhook settingsGITHUB_API_TOKEN
- Personal access token. See below for additonal infoGITHUB_USERNAME
- Your github username. Used for requests to github#3. Deploy the service with
serverless deploy
. If you need to setup serverless, please see these install instructions.#4. Take the POST endpoint returned from deploy and plug it into your repositories settings in github
Add your github webhook listener URL into the
Payload URL
and choose typeapplication/json
Plugin your
GITHUB_WEBHOOK_SECRET
defined in your config fileSelect which github events will trigger your webhook
Select Issue comments, these will be where you insert
schedule(MM/DD/YYYY H:MM pm)
comments in a given PR#5. Submit a PR and give it a go!
#Contributions Welcome
Have an idea on how we can improve the static site post scheduler?
Leave us a comment below, submit a PR, or tweet @DavidWells
#Was this post scheduled?
How did you guess it?
This post was scheduled!
Technology
via Hacker News http://ift.tt/YV9WJO
March 7, 2017 at 03:01AM