diff options
author | Kenny Ballou <kballou@devnulllabs.io> | 2018-08-17 22:30:27 -0600 |
---|---|---|
committer | Kenny Ballou <kballou@devnulllabs.io> | 2018-08-19 08:11:29 -0600 |
commit | c818f2b61c75195cf7adb542dd443e37feea7b59 (patch) | |
tree | 6f7c89e834e1973209187abd668eaa360cb367a6 | |
parent | 28da2aee6b587e751d1ee60d9da80d9c9f200181 (diff) | |
download | blog.kennyballou.com-c818f2b61c75195cf7adb542dd443e37feea7b59.tar.gz blog.kennyballou.com-c818f2b61c75195cf7adb542dd443e37feea7b59.tar.xz |
Convert to Org-mode and Pandoc
Create some fairly straight-forward conversion scripts to generate a
static site from Emacs Org-mode files using Pandoc to generate HTML
files.
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile | 61 | ||||
-rwxr-xr-x | scripts/generate_index_html.sh | 13 | ||||
-rwxr-xr-x | scripts/generate_post_html.sh | 22 | ||||
-rwxr-xr-x | scripts/generate_post_preview.sh | 10 | ||||
-rwxr-xr-x | scripts/generate_post_summary_html.sh | 24 | ||||
-rwxr-xr-x | scripts/generate_post_summary_xml.sh | 21 | ||||
-rwxr-xr-x | scripts/generate_rss.sh | 19 | ||||
-rwxr-xr-x | scripts/org-get-slug.sh | 8 | ||||
-rwxr-xr-x | scripts/org-metadata.sh | 20 | ||||
-rwxr-xr-x | scripts/site-templates.sh | 6 | ||||
-rw-r--r-- | templates/html_footer.html | 14 | ||||
-rw-r--r-- | templates/html_header.html | 23 | ||||
-rw-r--r-- | templates/html_sub_header.html | 42 |
14 files changed, 275 insertions, 11 deletions
@@ -1 +1,4 @@ build/ +posts/*.preview.org +posts/*.html +posts/*.xml @@ -1,15 +1,54 @@ -OUTPUT=`pwd`/build +PROJ_ROOT:=$(shell git rev-parse --show-toplevel) +SCRIPTS_DIR:=$(PROJ_ROOT)/scripts +STATIC_DIR:=static +IMAGES_DIR:=$(STATIC_DIR)/media +VIDEOS_DIR:=$(STATIC_DIR)/media/videos +BUILD_DIR:=build +blog_dir = $(shell $(SCRIPTS_DIR)/org-get-slug.sh $(1)) +POSTS_ORG_INPUT:=$(wildcard posts/*.org) +POSTS_ORG_SUM_XML_OUTPUT:=$(patsubst posts/%.org, posts/%.sum.xml, $(POSTS_ORG_INPUT)) +POSTS_ORG_SUM_OUTPUT:=$(patsubst posts/%.org, posts/%.sum.html, $(POSTS_ORG_INPUT)) +POSTS_ORG_HTML_OUTPUT:=$(foreach post,$(POSTS_ORG_INPUT),$(BUILD_DIR)$(call blog_dir,$(post))/index.html) +STATIC_FILES:=$(shell find $(STATIC_DIR) -type f) +STATIC_FILES_OUT:=$(patsubst $(STATIC_DIR)/%,$(BUILD_DIR)/%,$(STATIC_FILES)) -all: build +.PHONY: all +all: $(BUILD_DIR)/index.html \ + $(BUILD_DIR)/index.xml \ + $(POSTS_ORG_HTML_OUTPUT) \ + $(STATIC_FILES_OUT) -.PHONY: build -build: - @hugo -d ${OUTPUT} +posts/%.preview.org: posts/%.org + $(SCRIPTS_DIR)/generate_post_preview.sh $< > $@ -.PHONY: deploy -deploy: build - @rsync -avz ${OUTPUT}/ kennyballou.com:/srv/www/blog/. +posts/%.sum.html: posts/%.org posts/%.preview.org + $(SCRIPTS_DIR)/generate_post_summary_html.sh $^ > $@ -.PHONY: serve -serve: - -hugo -d ${OUTPUT} serve +posts/%.sum.xml: posts/%.org posts/%.preview.org + $(SCRIPTS_DIR)/generate_post_summary_xml.sh $^ > $@ + +$(BUILD_DIR): + mkdir -p $@ + +$(BUILD_DIR)/index.html: $(POSTS_ORG_SUM_OUTPUT) | $(BUILD_DIR) + $(SCRIPTS_DIR)/generate_index_html.sh $^ > $@ + +$(BUILD_DIR)/index.xml: $(POSTS_ORG_SUM_XML_OUTPUT) | $(BUILD_DIR) + $(SCRIPTS_DIR)/generate_rss.sh $^ > $@ + +define BLOG_BUILD_DEF +$(BUILD_DIR)$(call blog_dir,$T): + mkdir -p $$@ +$(BUILD_DIR)$(call blog_dir,$T)/index.html: $T | $(BUILD_DIR)$(call blog_dir,$T) + $(SCRIPTS_DIR)/generate_post_html.sh $$< > $$@ +endef + +$(foreach T,$(POSTS_ORG_INPUT),$(eval $(BLOG_BUILD_DEF))) + +$(BUILD_DIR)/%: $(STATIC_DIR)/% | $(BUILD_DIR) + mkdir -p $(dir $@) + cp $< $@ + +.PHONY: clean +clean: + -rm -r $(BUILD_DIR) diff --git a/scripts/generate_index_html.sh b/scripts/generate_index_html.sh new file mode 100755 index 0000000..0a2196a --- /dev/null +++ b/scripts/generate_index_html.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# Generate index.html page + +INPUT_FILES=${@} +PROJ_ROOT=$(git rev-parse --show-toplevel) +source ${PROJ_ROOT}/scripts/site-templates.sh + +cat "${HTML_HEADER_FILE}" +echo "<body>" +cat "${HTML_SUB_HEADER_FILE}" +cat ${INPUT_FILES} | sort -r -n -k1 -k2 -k3 | awk -F' ' '{print $4}' +echo "</body>" +cat "${HTML_FOOTER_FILE}" diff --git a/scripts/generate_post_html.sh b/scripts/generate_post_html.sh new file mode 100755 index 0000000..42608dc --- /dev/null +++ b/scripts/generate_post_html.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Generate HTML for blog post + +ORGIN=${1} +PROJ_ROOT=$(git rev-parse --show-toplevel) +source ${PROJ_ROOT}/scripts/site-templates.sh +source ${PROJ_ROOT}/scripts/org-metadata.sh +DISPLAY_DATE=$(date -d ${DATE} +'%a %b %d, %Y') +SORT_DATE=$(date -d ${DATE} +'%Y %m %d ') + +cat ${HTML_HEADER_FILE} +cat ${HTML_SUB_HEADER_FILE} +echo -n "<h1 class=\"title\">${TITLE}</h1>" +echo -n "<div class=\"post-meta\">" +echo -n '<ul class="tags"><li><i class="fa fa-tags"></i></li>' +echo -n "${TAGS}" | awk '{ printf "<li>%s</li>", $0}' +echo -n '</ul>' +echo -n "<h4>${DISPLAY_DATE}</h4></div>" +pandoc --from org \ + --to html \ + ${ORGIN} +cat ${HTML_FOOTER_FILE} diff --git a/scripts/generate_post_preview.sh b/scripts/generate_post_preview.sh new file mode 100755 index 0000000..2590787 --- /dev/null +++ b/scripts/generate_post_preview.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Generate HTML post summary tags + +ORGIN=${1} +PROJ_ROOT=$(git rev-parse --show-toplevel) + +source ${PROJ_ROOT}/scripts/org-metadata.sh + +echo "${LINKS}" +echo "${PREVIEW}" diff --git a/scripts/generate_post_summary_html.sh b/scripts/generate_post_summary_html.sh new file mode 100755 index 0000000..b184246 --- /dev/null +++ b/scripts/generate_post_summary_html.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Generate HTML post summary tags + +ORGIN=${1} +GENERATED_PREVIEW_FILE=${2} +PROJ_ROOT=$(git rev-parse --show-toplevel) + +source ${PROJ_ROOT}/scripts/org-metadata.sh +DISPLAY_DATE=$(date -d ${DATE} +'%a %b %d, %Y') +SORT_DATE=$(date -d ${DATE} +'%Y %m %d ') +PREVIEW_CONTENT=$(cat ${GENERATED_PREVIEW_FILE} | pandoc -f org -t html) + +echo -n "${SORT_DATE}" +echo -n '<article class="post"><header>' +echo -n "<h2><a href=\"${SLUG}\">${TITLE}</a></h2>" +echo -n "<div class=\"post-meta\">${DISPLAY_DATE}</div></header>" +echo -n "<blockquote>$(echo ${PREVIEW_CONTENT})</blockquote>" +echo -n '<ul class="tags"><li><i class="fa fa-tags"></i></li>' +echo -n "${TAGS}" | awk '{ printf "<li>%s</li>", $0}' +echo -n '</ul>' +echo -n '<footer>' +echo -n "<a href=\"${SLUG}\">Read More</a>" +echo -n "</footer>" +echo "" diff --git a/scripts/generate_post_summary_xml.sh b/scripts/generate_post_summary_xml.sh new file mode 100755 index 0000000..b409209 --- /dev/null +++ b/scripts/generate_post_summary_xml.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Generate HTML post summary tags + +ORGIN=${1} +GENERATED_PREVIEW_FILE=${2} +PROJ_ROOT=$(git rev-parse --show-toplevel) + +source ${PROJ_ROOT}/scripts/org-metadata.sh +DISPLAY_DATE=$(date -d ${DATE} +'%a %b %d, %Y') +SORT_DATE=$(date -d ${DATE} +'%Y %m %d ') +PREVIEW_CONTENT=$(cat ${GENERATED_PREVIEW_FILE} | pandoc -f org -t html) + +echo -n "${SORT_DATE}" +echo -n "<item>" +echo -n "<title>${TITLE}</title>" +echo -n "<link>https://kennyballou.com${SLUG}</link>" +echo -n "<guid>${SLUG}</guid>" +echo -n "<pubDate>${DISPLAY_DATE}</pubDate>" +echo -n "<description>${DESCRIPTION}</description>" +echo -n "</item>" +echo "" diff --git a/scripts/generate_rss.sh b/scripts/generate_rss.sh new file mode 100755 index 0000000..17b0395 --- /dev/null +++ b/scripts/generate_rss.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Generate index.html page + +INPUT_FILES=${@} +PROJ_ROOT=$(git rev-parse --show-toplevel) +source ${PROJ_ROOT}/scripts/site-templates.sh + +echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">" +echo "<channel>" +echo "<title>~kballou/blog</title>" +echo "<link>https://kennyballou.com</link>" +echo "<language>en-us</language>" +echo "<author>Kenny Ballou</author>" +echo "<copyright>Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</copyright>" +echo "<updated>$(date --utc --rfc-3339='date')</updated>" +cat ${INPUT_FILES} | sort -r -n -k1 -k2 -k3 | awk -F' ' '{print $4}' +echo "</channel>" +echo "</rss>" diff --git a/scripts/org-get-slug.sh b/scripts/org-get-slug.sh new file mode 100755 index 0000000..07d77cd --- /dev/null +++ b/scripts/org-get-slug.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Generate blog directory structure + +ORGIN=${1} +PROJ_ROOT=$(git rev-parse --show-toplevel) +source ${PROJ_ROOT}/scripts/org-metadata.sh + +echo -n ${SLUG} diff --git a/scripts/org-metadata.sh b/scripts/org-metadata.sh new file mode 100755 index 0000000..ff527ee --- /dev/null +++ b/scripts/org-metadata.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Extract ORG metadata + +ORGIN=${1} +LC_TIME="C" + +STUB=$(awk -F': ' '/^#\+SLUG:/ { printf "%s", $2}' ${ORGIN}) +DATE=$(awk -F': ' '/^#\+DATE:/ { printf "%s", $2}' ${ORGIN}) +YEAR=$(echo ${DATE} | awk -F'-' '{ print $1 }') +MONTH=$(echo ${DATE} | awk -F'-' '{ print $2 }') +SLUG="/blog/${YEAR}/${MONTH}/${STUB}" +TITLE=$(awk -F': ' '/^#\+TITLE:/ { printf "%s", $2}' ${ORGIN}) +PREVIEW=$(sed -n \ + '/^#+BEGIN_PREVIEW/,/^#+END_PREVIEW/p' \ + ${ORGIN} \ + | head -n-1 \ + | tail -n+2) +DESCRIPTION=$(awk -F': ' '/^#\+DESCRIPTION:/ { printf "%s", $2}' ${ORGIN}) +TAGS=$(awk -F': ' '/^#\+TAGS:/ { $1 = ""; printf "%s\n", $0}' ${ORGIN}) +LINKS=$(sed -n -e '/^#+LINK:/p' ${ORGIN}) diff --git a/scripts/site-templates.sh b/scripts/site-templates.sh new file mode 100755 index 0000000..6ec4b86 --- /dev/null +++ b/scripts/site-templates.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +#template variables + +HTML_HEADER_FILE=${HTML_HEADER_FILE:-templates/html_header.html} +HTML_SUB_HEADER_FILE=${HTML_SUB_HEADER_FILE:-templates/html_sub_header.html} +HTML_FOOTER_FILE=${HTML_FOOTER_FILE:-templates/html_footer.html} diff --git a/templates/html_footer.html b/templates/html_footer.html new file mode 100644 index 0000000..9a99467 --- /dev/null +++ b/templates/html_footer.html @@ -0,0 +1,14 @@ +<footer> + <div id="footer"> + <div class="colleft"> + <p>© 2015-2018 Kenny Ballou. + <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Some rights + reserved.</a></p> + </div> + <div class="colright"> + <p>Powered by <a href="https://gnu.org">GNU/Linux</a></p> + </div> + </div> +</footer> +</body> +</html> diff --git a/templates/html_header.html b/templates/html_header.html new file mode 100644 index 0000000..9357d2d --- /dev/null +++ b/templates/html_header.html @@ -0,0 +1,23 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + + <meta name="author" content="Kenny Ballou"> + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> + + <base href="/" /> + <title>~kb/blog</title> + + <link rel="canonical" href="" /> + <link href="/index.xml" rel="alternate" type="application/rss+xml" + title="~kb/blog" /> + + <link rel="stylesheet" + href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> + <script type="text/javascript" async + src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML"></script> + + <link rel="stylesheet" href="/css/site.css" /> + <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> +</head> diff --git a/templates/html_sub_header.html b/templates/html_sub_header.html new file mode 100644 index 0000000..a1f3e03 --- /dev/null +++ b/templates/html_sub_header.html @@ -0,0 +1,42 @@ +<div id="header"> + <div class="colleft"> + <header> + <a class="fade" href="/">~kballou</a> + </header> + </div> + <div class="colright"> + <header> + <div id="author"> + <a href="https://git.devnulllabs.io" + target="_blank" + rel="noopener noreferrer"> + <i class="fade fa fa-git-square fa-1x"></i> + </a> + <a href="https://github.com/kennyballou" + target="_blank" + rel="noopener noreferrer"> + <i class="fade fa fa-github-square fa-1x"></i> + </a> + <a href="https://bitbucket.org/kballou" + target="_blank" + rel="noopener noreferrer"> + <i class="fade fa fa-bitbucket-square fa-1x"></i> + </a> + <a href="https://plus.google.com/+KennyBallou" + target="_blank" + rel="noopener noreferrer"> + <i class="fade fa fa-google-plus-square fa-1x"></i> + </a> + <a href="https://twitter.com/kennyballou" + target="_blank" + rel="noopener noreferrer"> + <i class="fade fa fa-twitter-square fa-1x"></i> + </a> + <a href="/index.xml" rel="alternate" + type="application/rss+xml"> + <i class="fade fa fa-rss-square fa-1x"></i> + </a> + </div> + </header> + </div> +</div> |