commit f4cbd5c677ba14ec33b81a4095fc25964c469fb9
parent 6a549edeee479279e1d94d09968613b0c438edab
Author: zakaria <e-zk@users.noreply.github.com>
Date: Sun, 8 Aug 2021 19:49:30 +1000
Remove old scripts
Diffstat:
D | common.rc | | | 152 | ------------------------------------------------------------------------------- |
D | page.sh | | | 23 | ----------------------- |
D | update.sh | | | 84 | ------------------------------------------------------------------------------- |
3 files changed, 0 insertions(+), 259 deletions(-)
diff --git a/common.rc b/common.rc
@@ -1,152 +0,0 @@
-#!/bin/sh
-
-#
-# common variables
-#
-
-# site metadata
-fqdn=zakaria.org
-base_url="https://${fqdn}"
-onion_url="http://g5hwwozzm3co43bu6np2noyhsju7zuok3cqawlbeo4entvfoads5trqd.onion"
-site_name="zakaria's web log"
-
-# paths
-site_root="${HOME}/usr/src/www/blog"
-html_dir="${site_root}/html"
-posts_dir=posts
-posts_index="${site_root}/${posts_dir}/index.html"
-
-# feed location
-rss_feed="${site_root}/rss.xml"
-
-# options for lowdown
-lowdown_opts='--html-no-escapehtml --html-no-skiphtml'
-
-
-#
-# common functions
-#
-
-# log to stderr
-log() {
- printf '%s: %s\n' "$(basename $0)" "$1" >&2
-}
-
-# ded af
-die() {
- log "$1"
- exit 1
-}
-
-# is $1 in the list of excluded files?
-is_excluded() {
- case "$1" in
- index.*) return 0 ;;
- *) return 1 ;;
- esac
- return 1
-}
-
-# run lowdown on some input
-# $1 - markdown input
-run_lowdown() {
- echo "$@" | lowdown -Thtml ${lowdown_opts}
-}
-
-# separate a filename into parsable chunks (date:title)
-# $1 - filename (basename)
-parse_fname() {
- echo "$1" | \
- sed 's/\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\)-\(.*\)\..*/\1:\2/g'
-}
-
-# get title from markdown file
-# $1 - markdown file (path)
-md_title() {
- head -n 1 "$1" | sed 's/#\ \(.*\)/\1/g'
-}
-
-# convert markdown to plaintext:
-# remove code, links, use image alt-text
-# input is stdin
-md_to_txt() {
- sed -E \
- -e 's/`//g' \
- -e 's/!\[(.+)\]\(.+\)/\[img "\1"\]/g' \
- -e 's/\[(.+)\]\(.+\)/\1/g'
-}
-
-# generate navigation/header
-gen_nav() {
- printf '<header>\n'
- printf '<nav>\n'
- printf '<a href="%s">%s</a>\n' "/" "$fqdn"
- cat "${html_dir}/nav.html"
- printf '</nav>\n'
- printf '</header>\n'
-}
-
-# generate page footer
-# $1 - page markdown file location
-gen_footer() {
- page_file="$1"
-
- page_path="${page_file#${site_root}/*}"
- page_baseurl="${page_path%%.*}.html"
-
- printf '<footer>\n'
- printf '<a href="./%s">plaintext</a> ' "$(basename "$page_file")"
- printf '<a href="%s/%s">onion</a>\n' "$onion_url" "$page_baseurl"
- cat "${html_dir}/footer.html"
- printf '</footer>\n'
-}
-
-# extract post description (for opengraph)
-# takes the first fourlines, removes titles and empty lines, then
-# strips markdown to make it plain text
-# $1 - markdown file
-gen_desc() {
- post_file="$1"
- output="$(head -n 4 "$post_file" | sed -e '/#.*/d' -e '/^$/d' | md_to_txt | sed -e 's/\ *$//' | cut -f 1-50 -d' ' | tr -d '\n')"
- if [ -n "$output" ]; then
- printf '... [read more]'
- fi
-}
-
-# $1 - markdown file to generate head for
-# $2 - page title
-gen_head() {
- page_file="$1"
- page_title="$2"
-
- #post_bname="$(basename "$page_file")"
- #page_url="${base_url}/${posts_dir}/${post_bname%%.*}.html"
- page_path="${page_file#${site_root}/*}"
- page_url="${base_url}/${page_path%%.*}.html"
- page_desc="$(gen_desc "$page_file")"
-
- # START head
- printf '<head>\n'
-
- # static stuff is from the html/head file
- #printf '<meta http-equiv="content-type" content="text/html; charset=utf-8">\n'
- #printf '<meta name="viewport" content="width=device-width, initial-scale=1">\n'
- #printf '<meta name="theme-color" content="#101010">\n'
- #printf '<link rel="icon" href="/favicon.svg">\n'
- #printf '<link rel="alternate icon" href="/favicon.ico">\n'
- #printf '<link rel="stylesheet" href="/style.css">\n'
- cat "${html_dir}/head.html"
-
- # open graph tags
- printf '<meta property="og:type" content="article">\n'
- printf '<meta property="og:title" content="%s">\n' "${page_title:-${site_name}}"
- printf '<meta property="og:description" content="%s">\n' "${page_desc}"
- printf '<meta property="og:url" content="%s">\n' "$page_url"
-
- # title
- printf '<title>%s</title>\n' "$page_title"
-
- # END head
- printf '</head>\n'
-}
-
diff --git a/page.sh b/page.sh
@@ -1,23 +0,0 @@
-#!/bin/sh
-
-. ${XDG_CONFIG_HOME:-${HOME}/.config}/shite/common.rc
-
-gen_page() {
- post_file="$1"
- post_title="$2"
- post_content="$(run_lowdown "$(cat "$post_file")")"
-
- printf '<!DOCTYPE html>\n'
- printf '<html lang="en">\n'
- gen_head "$post_file" "${post_title}"
- printf '<body>\n'
- gen_nav
- printf '<main>\n'
- printf '%s\n' "$post_content"
- printf '</main>\n'
- gen_footer "$post_file"
- printf '</body>\n'
- printf '</html>\n'
-}
-
-gen_page "$1" "$3" > "$2"
diff --git a/update.sh b/update.sh
@@ -1,84 +0,0 @@
-#!/bin/sh
-
-. ${XDG_CONFIG_HOME:-${HOME}/.config}/shite/common.rc
-
-
-remove_title() {
- post_file="$1"
- cat "$post_file" | awk '{
- if (!(FNR==1) && !($0 ~ /^#.*\n/))
- print $0
- }'
-}
-
-gen_info() {
- post_created="$1"
-
- # a post is considered 'modified' when this script is run,
- # so use the current date
- post_modified="$(date '+%F')"
-
- printf '<p class="info">\n'
- printf 'created: %s<br>\n' "$post_created"
- printf 'modified: %s<br>\n' "$post_modified"
- printf '</p>\n'
-}
-
-gen_post() {
- post_file="$1"
-
- post_title_md="$(head -n 1 "$post_file")"
- post_title_html="$(run_lowdown "$post_title_md")"
- post_content="$(run_lowdown "$(remove_title "$post_file")")"
- post_date_parsed="$(parse_fname "${post_file##*/}")"
-
- # START html
- printf '<!DOCTYPE html>\n'
- printf '<html lang="en">\n'
-
- # generate the head
- gen_head "$post_file" "$(md_title "$post_file") - ${site_name}"
-
- # START body
- printf '<body>\n'
-
- # generate navigation
- gen_nav
-
- printf '<main>\n'
-
- # add title
- printf '%s\n' "$post_title_html"
- # add info block
- printf '%s\n\n' "$(gen_info "${post_date_parsed%%:*}")"
- # add article itself
- printf '%s\n' "$post_content"
-
- printf '</main>\n'
-
- # generate page footer
- gen_footer "$post_file"
-
- # END body
- printf '</body>\n'
-
- # END html
- printf '</html>\n'
-}
-
-for post in ${site_root}/${posts_dir}/*.md; do
- post_html="${post%%.*}.html"
-
- # if the html for this .md exists; do not include in list
- if [ -f "$post_html" ]; then
- continue
- fi
-
- # skip file if it is excluded
- if is_excluded "$(basename "$post")"; then
- continue
- fi
-
- log "adding "$post"..."
- gen_post "$post" > "$post_html"
-done