Git branches for content and output
Github supports static website publishing of gh-pages branch in your repository. It can even support CNAME entries to point your domain to it. This idea is pretty good if you want to maintain content and output in two separate branches. The following note explains the flow of commands to set this up in a local repository. You will need to add a push to remote step for Github repositories.
Essentially, the steps are:
- Create a git repository.
- Add a main branch.
- Add a gh-pages branch.
- Add some content in main branch and run some transformation to create an output file.
- Switch to gh-pages and commit output files.
The main branch has content only and gh-pages have generated output only.
Note that I use this to convert my org-mode files to html. Since org may not be as widely used as markdown sharing the examples with markdown instead. If you do want to use org, just fix the makefile below for extensions and the pandoc invocation.
After I wrote this, I found out Sean Coughlin’s blog on npm gh-pages. This is very informative and explains setting up your Github repository to enable pages and subsequent automation.
Commands
We will assume we are using pandoc to convert markdown to html.
#setup basic folder and main branch
#create output branch
#setup complementary gitignores
#Let us create content
#Repeat
Or we can use a Makefile to make the process of generation easier. This can be added to the main branch. Whenever you update content, simply run make, test and then switch to gh-pages branch to commit generated files.
SRCS =
OUTS =
:
: :
:
Here is how the folder looks after all this.
;
;
As you can see, the two branches have different files.
Issues
Testing generated content
If you want to add assets like css to support generated content, you can add that to gh-pages individually - however, this will require switching to that branch to fully test generated output. I prefer it that way because then main branch will have pure generated pages only which is much easier to debug without added styles.
Additional branching and merging
These are parallel branches without overlapping files. So, if you want to support multiple authors and their branches with their own merging, it is little bit easier to manage merges to main branch only and one person generates gh-pages.
This article was published on linked.in as well.