Website creation using Github Pages
by Don Mahurin, 2022-09-17
This article gives some simple steps on how to use github pages for your website.
Previously, I used just plain html for openright.org, then to make the pages easier to edit, some were converted to simple markup (textile).
I was aware that my pages were boring, and not pretty. I also knew of github pages, and decided to try it for my website.
Some desired conditions of the pages:
- Stored in git
- Simple markdown
- Easy to edit
- Easy to view locally
- Looks "good/ok"
The first step, creating a github pages project, is easy enough. (https://pages.github.com/). Just create a 'something.github.io' project, and enable github pages.
And by default, one can just put markdown files there (index.md, or README.md), and they show up.
But they do not look like a web page.
For pages, github is using Jekyll. It looked like I needed to set that up more properly.
In experimenting with Jekyll, there were some things to note:
- Jekyll assumed the use of "Front Matter" headers on markup pages to get meta data like title, date ...
- Github pages uses a specific version of Jekyll with a select group of plugins available
- To view locally, the plugins and versions used need to align
"Front Matter" is not in any markdown standard, including Github's. If possible, I wanted to avoid it, and keep with simple markdown.
And we needed a simple way to use the github aligned Jekyll and plugins.
Fast-forwarding to the solution...
The following Gemfile depends on 'github-pages', which depends on the same Jekyll versions and plugins that github uses.
It also includes a plugin which makes front matter optional.
Gemfile
source "https://rubygems.org"
gem "webrick"
gem "jekyll-remote-theme"
gem "jekyll-default-layout"
gem "jekyll-optional-front-matter"
gem "github-pages", group: :jekyll_plugins
The following config file:
- Uses GFM markdown (rather than kramdown)
- Uses Minima theme
- Enables proper functionality without front matter
_config.yml
markdown: GFM
remote_theme: jekyll/minima
minima:
skin: auto
plugins:
- jekyll-remote-theme
- jekyll-optional-front-matter
- jekyll-default-layout
To setup your site, add the Gemfile and _config.yml above, then add some markdown (index.md or README.md).
To get GFM markdown from existing html pages, you may use:
markdownify | pandoc -f markdown -t gfm
Then run
bundle config set --local path vendor/bundle
bundle install --path vendor/bundle
bundle exec jekyll serve
My pages are likely still boring, though I hope you have learned something new about setting up github/jekyll pages.
2023-04-08
Separate Front Matter
Jekyll currently assumes that meta data about pages and posts stored as a "front matter" block at the top of the document.
There have been a few requests about keeping this meta data in a separate yaml file, but currently, this is not implemented.
Front matter is not part of any markdown standard, which is a valid reason to avoid it in your markdown pages.
One way to avoid using front matter is by using the "optional-front-matter" plugin. In this case, the title comes from the page heading.
But if you would like additional page attributes, this is not sufficient.
There is a simple way to acheive external meta data. In each page directory, we can use a convention where the page document is stored in README.md, and a a front matter wrapper is in index.md.
The index.md would have front matter definitions, followed by a include_relative README.md.
This works because index.md takes precedence over README.md in jekyll, and jekyll properly generates html from the included README.md.
2023-04-09
Combining Pages and Posts
The common way to use jekyll is to separately view pages and posts.
Instead, we can merge pages and posts together. In this way, the page is the main article, and the posts are the followup articles.
To implement this, we display the page content as usual, then we find and display posts with a post url matching the page url.
To get a separation bar, the "site-footer" div is used. This works with the minima theme.
In page.html:
{{ content }}
{% for post in site.posts reversed %}
{% if post.url contains page.url %}
<div class="site-footer"/>
<p>{{ post.date | date: "%Y-%m-%d" }}</p>
<p>{{ post.content }}</p>
{% endif %}
{% endfor %}
2023-05-07
Allow page/post comments
To allow comments, we can use github issues, as demonstrated in this article.
https://aristath.github.io/blog/static-site-comments-using-github-issues-api
And just adding one file in our _includes, updated for our site
https://github.com/aristath/aristath.github.com/blob/master/_includes/comments.html
Then we just add comments_ids for our pages, and add this to page.html
{% if page.comments_id %}
{% include comments.html %}
{% endif %}
Comments
No comments found for this article.
Join the discussion for this article on this ticket. Comments appear on this page instantly.