aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKenny Ballou <kballou@devnulllabs.io>2018-08-17 22:30:27 -0600
committerKenny Ballou <kballou@devnulllabs.io>2018-08-19 08:11:29 -0600
commitc818f2b61c75195cf7adb542dd443e37feea7b59 (patch)
tree6f7c89e834e1973209187abd668eaa360cb367a6 /scripts
parent28da2aee6b587e751d1ee60d9da80d9c9f200181 (diff)
downloadblog.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.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate_index_html.sh13
-rwxr-xr-xscripts/generate_post_html.sh22
-rwxr-xr-xscripts/generate_post_preview.sh10
-rwxr-xr-xscripts/generate_post_summary_html.sh24
-rwxr-xr-xscripts/generate_post_summary_xml.sh21
-rwxr-xr-xscripts/generate_rss.sh19
-rwxr-xr-xscripts/org-get-slug.sh8
-rwxr-xr-xscripts/org-metadata.sh20
-rwxr-xr-xscripts/site-templates.sh6
9 files changed, 143 insertions, 0 deletions
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}