diff options
Diffstat (limited to '')
-rwxr-xr-x | v2/src/bin/absolute | 30 | ||||
-rwxr-xr-x | v2/src/bin/categories | 80 | ||||
-rwxr-xr-x | v2/src/bin/category | 80 | ||||
-rwxr-xr-x | v2/src/bin/collection-for | 83 | ||||
-rwxr-xr-x | v2/src/bin/conf | 69 | ||||
-rwxr-xr-x | v2/src/bin/feed | 44 | ||||
-rwxr-xr-x | v2/src/bin/index | 128 | ||||
-rwxr-xr-x | v2/src/bin/indexentry | 73 | ||||
-rwxr-xr-x | v2/src/bin/makemake | 37 |
9 files changed, 574 insertions, 50 deletions
diff --git a/v2/src/bin/absolute b/v2/src/bin/absolute index ecf5a64..f475901 100755 --- a/v2/src/bin/absolute +++ b/v2/src/bin/absolute @@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - absolute < STDIN + absolute [CONTENT...] absolute -h EOF } @@ -16,9 +16,13 @@ help() { Options: -h, --help show this message + CONTENT a literal string to be prefixed - Read URL from STDIN and adds the FQDN prefix. Meant to be used - in conjunction with `url-for`. + + Add domain prefix to build a full URL. If CONTENT is not given, + get data from STDIN. + + Usually used in conjunction with url-for(1). Examples: @@ -27,6 +31,12 @@ help() { $ url-for 'static/style.css' | absolute https://euandre.org/static/style.css + + + Get the absolute variant of a relative URL: + + $ absolute "$homepage_url" + https://euandre.org/pt/ EOF } @@ -64,4 +74,16 @@ shift $((OPTIND - 1)) . src/lib/base.conf -printf 'https://%s%s' "$domain" "$(cat)" + +prefix() { + sed "s|^/\?|https://$domain/|" +} + + +if [ $# = 0 ]; then + prefix +else + for s in "$@"; do + printf '%s\n' "$s" | prefix + done +fi diff --git a/v2/src/bin/categories b/v2/src/bin/categories new file mode 100755 index 0000000..bc08704 --- /dev/null +++ b/v2/src/bin/categories @@ -0,0 +1,80 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + categories FILENAME + categories -h + EOF +} + +help() { + cat <<-'EOF' + Options: + -h, --help show this message + + FILENAME the target categories index to be built + + + Generate FILENAME as the indexed list of articles by category. + + + Examples: + + Generate the index.categories entry for english pastebins: + + $ categories src/en/pastebins/index.categories + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + +FILENAME="${1:-}" +eval "$(assert_arg "$FILENAME" 'FILENAME')" +DIR="$(dirname "$FILENAME")" + + +mkdir -p "$DIR" +printf '' > "$FILENAME" +find "$DIR"/*.categorysort 2>/dev/null | + awk -F. '{ print $(NF-1) }' | + sort | + uniq | + while read -r category; do + find "$DIR"/*."$category".categorysort | + sort -nr | + xargs cat > "$DIR/$category.category" + printf '%s\n' "$category" >> "$FILENAME" + done diff --git a/v2/src/bin/category b/v2/src/bin/category new file mode 100755 index 0000000..2a2fdea --- /dev/null +++ b/v2/src/bin/category @@ -0,0 +1,80 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + category FILENAME + html -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + FILENAME the name of the input file .md file + + + Process the FILENAME, and generate a the derived category files. + + + Examples: + + Generate the categories for a pastebin: + + $ categories src/a-paste.md > src/a-paste.categoryentry + EOF +} + + +for f in "$@"; do + case "$f" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + +FILENAME="${1:-}" +eval "$(assert_arg "$FILENAME" 'FILENAME')" + + +# shellcheck source=/dev/null +. "${FILENAME%.md}.conf" +DIR="$(dirname "$FILENAME")" + + + +echo "${categories:-}" | tr ' ' '\n' | grep . | while read -r category; do + echo "$FILENAME" > "$DIR/${date_iso:?}.$category.categorysort" +done + +envsubst < src/lib/category.html diff --git a/v2/src/bin/collection-for b/v2/src/bin/collection-for new file mode 100755 index 0000000..b3fc211 --- /dev/null +++ b/v2/src/bin/collection-for @@ -0,0 +1,83 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + collection-for FILE + collection-for -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + FILE the path of the file to get the collection for + + + Say the collection of the given file, using the path of FILE. + + + Examples: + + Get "tils" for "src/en/tils/some-pt.md": + + $ collection-for src/en/tils/some-pt.md + tils + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + + +FILE="${1:-}" +eval "$(assert_arg "$FILE" 'FILE')" + + +# echo "${FILE#"$CONTENT_PREFIX"/}" | cut -d/ -f1 +# echo "${FILE#"$CONTENT_PREFIX"/}" | awk '{ + # awk -F/ '$3 && $0=$2 { print; next } $0' + +ATTEMPT="$(echo "${FILE#"$CONTENT_PREFIX"/}" | cut -d/ -f2-)" + +if [ "$ATTEMPT" = 'index.html' ]; then + echo articles +else + NAME="$(echo "$ATTEMPT" | cut -d/ -f1)" + collections | grep "$NAME" +fi diff --git a/v2/src/bin/conf b/v2/src/bin/conf index 5717039..62ef97a 100755 --- a/v2/src/bin/conf +++ b/v2/src/bin/conf @@ -5,7 +5,7 @@ set -eu usage() { cat <<-'EOF' Usage: - conf FILENAME + conf [FILENAME] conf -h EOF } @@ -21,7 +21,8 @@ help() { Separate the content from the "frontmatter", and emit the - selected one, given the FILENAME. + selected one, given the FILENAME. If FILENAME is not given, + generate the global config. Examples: @@ -65,11 +66,36 @@ shift $((OPTIND - 1)) . src/lib.sh + FILENAME="${1:-}" -eval "$(assert_arg "$FILENAME" 'FILENAME')" +if [ -z "$FILENAME" ]; then + printf 'export style_url="%s"\n' "$(url-for 'style.css')" + printf 'export pubkey_url="%s"\n' "$(url-for 'public.asc.txt')" + printf 'export pubkey_id="%s"\n' "$( + LANG=C.UTF-8 gpg --list-key "$EMAIL" | + awk 'NR==2 { print substr($1, length($1) - 15) }' | + shesc + )" + + for f in "$CONTENT_PREFIX"/img/*.svg; do + name="$(basename "$f" .svg | sed 's|-|_|g')" + printf 'export icon_%s_url="%s"\n' "$name" "$(url-for "img/$(basename "$f")")" + done + for l in $(langs); do + for f in "$CONTENT_PREFIX"/img/*.svg; do + name="$(basename "$f" .svg | sed 's|-|_|g')" + printf 'export icon_%s_alt="%s"\n' "$name" "$(shesc < "$CONTENT_PREFIX/img/alt/$(basename "$f" .svg).$l.txt" )" + done > src/lib/generated."$l".conf + done + exit +fi + +lang="$(lang-for "$FILENAME")" +export lang -tee "$FILENAME".tmp < src/lib/base.conf +cat src/lib/base.conf src/lib/generated.conf src/lib/generated."$lang".conf | + tee "$FILENAME".tmp DELIMITER=0 while read -r line; do if [ "$line" = '---' ]; then @@ -92,14 +118,17 @@ done < "$FILENAME" | tee -a "$FILENAME".tmp rm -f "$FILENAME".tmp +collection="$(collection-for "$FILENAME" ||:)" +if [ -n "$collection" ]; then + export collection + printf 'export collection="%s"\n' "$collection" +fi + if [ -z "${layout:-}" ]; then - if [ "$(dirname "$(dirname "$FILENAME")")" = "$CONTENT_PREFIX" ]; then + if [ -z "$collection" ]; then layout=page else layout=post - collection="$(basename "$(dirname "$FILENAME")")" - export collection - printf 'export collection="%s"\n' "$collection" custom_layout="$(echo "$LAYOUTS" | grep . | awk -v coll="$collection" '$1 == coll { print $2 }' @@ -131,10 +160,10 @@ if [ -n "${date:-}" ]; then formatted_date="$(LANG="$lang" date -ud "${date:?}" +"${date_fmt:?}")" export formatted_date + printf 'export formatted_date_html="%s"\n' "$(htmlesc "$formatted_date" | shesc)" printf 'export date_html="%s"\n' "$(envsubst < src/lib/date."$lang".html | shesc)" - echo "${FILENAME%.md}.xmlentry" > "$(dirname "$FILENAME")/$date_iso.sortdata" - touch "${FILENAME%.md}.sortref" + echo "$FILENAME" > "$(dirname "$FILENAME")/$date_iso.sortdata" fi if [ -n "${update:-}" ]; then @@ -149,31 +178,19 @@ if [ -n "${update:-}" ]; then fi -url_part="$(printf '%s' "${FILENAME%.md}.html" | sed "s|^$CONTENT_PREFIX||")" +url_part="$(printf '%s' "${FILENAME%.md}.html" | sed "s|^$CONTENT_PREFIX/||")" +url="$(url-for "$url_part")" title_uri="$(uri "$title")" printf 'export title_html="%s"\n' "$(printf '%s' "$title" | htmlesc | shesc)" printf 'export filename="%s"\n' "$FILENAME" printf 'export url_part="%s"\n' "$url_part" -printf 'export url="%s"\n' "$(url-for "$url_part" | absolute)" +printf 'export url="%s"\n' "$url" +printf 'export url_absolute="%s"\n' "$(absolute "$url")" printf 'export mailto_uri="%s%s"\n' "${mailto_uri_prefix:?}" "$title_uri" printf 'export discussions_url="%s%s"\n' "${discussions_url_prefix:?}" "$title_uri" printf 'export sourcecode_url="%s%s"\n' "${sourcecode_url_prefix:?}" "$FILENAME" -printf 'export style_url="%s"\n' "$(url-for 'style.css')" -printf 'export favicon_url="%s"\n' "$(url-for 'favicon.svg')" -printf 'export pubkey_url="%s"\n' "$(url-for 'public.asc.txt')" - -for f in "$CONTENT_PREFIX"/img/*.svg; do - name="$(basename "$f" .svg | sed 's|-|_|g')" - printf 'export icon_%s_url="%s"\n' "$name" "$(url-for "img/$(basename "$f")")" -done - -# FIXME: special treatment of root -printf 'export homepage_url="%s"\n' "$(url-for '/')" - -printf 'export about_url="%s"\n' "$(url-for "${about_url_name:?}")" - if [ "${layout:-}" = 'post' ]; then export mailto_uri="$mailto_uri_prefix$title_uri" diff --git a/v2/src/bin/feed b/v2/src/bin/feed index 0488c86..52c6199 100755 --- a/v2/src/bin/feed +++ b/v2/src/bin/feed @@ -27,7 +27,7 @@ help() { Generate a feed for TILs: - $ feed src/en/feeds/til.xml + $ feed src/en/tils/feed.xml EOF } @@ -68,24 +68,44 @@ FILENAME="${1:-}" eval "$(assert_arg "$FILENAME" 'FILENAME')" -COLLECTION="$(basename "$FILENAME" '.xml')" -LANGUAGE="$(lang-for "$FILENAME")" -DIR="$(dirname "$(dirname "$FILENAME")")/$COLLECTION" - - . src/lib/base.conf # shellcheck source=/dev/null -. src/lib/base."$LANGUAGE".conf +. src/lib/base."$(lang-for "$FILENAME")".conf + now="$(date -uIs)" -url="$(url-for "${FILENAME#"$CONTENT_PREFIX"}" | absolute)" +url_absolute="$(url-for "${FILENAME#"$CONTENT_PREFIX"/}" | absolute)" site_name_html="$(htmlesc "${site_name:?}")" -export now url site_name_html +collection="$(collection-for "$FILENAME")" +collection_url_absolute="$(url-for "${lang:?}/$collection/" | absolute)" +feed_title_html="$(eval "echo \"\$feed_${collection}_title\"" | htmlesc)" +export now url_absolute site_name_html collection_url_absolute feed_title_html - -mkdir -p "$(dirname "$FILENAME")" +DIR="$(dirname "$FILENAME")" +mkdir -p "$DIR" { envsubst < src/lib/feed.xml - find "$DIR"/*.sortdata 2>/dev/null | sort -nr | xargs cat | xargs cat + find "$DIR"/*.sortdata 2>/dev/null | + sort -nr | + xargs cat | + sed 's|\.md$|.xmlentry|' | + xargs cat printf '</feed>\n' } > "$FILENAME" + +printf '' > "$DIR"/index.extrafeeds +while read -r category; do + url_absolute="$(url-for "${DIR#"$CONTENT_PREFIX"/}/feed.$category.xml" | absolute)" + collection_url_absolute="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_part:?}#$category" | absolute)" + feed_title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)" + export url_absolute collection_url_absolute feed_title_html + + { + envsubst < src/lib/feed.xml + < "$DIR/$category.category" \ + sed 's|\.md$|.xmlentry|' | + xargs cat + printf '</feed>\n' + } > "$DIR/feed.$category.xml" + echo "$DIR/feed.$category.xml" >> "$DIR"/index.extrafeeds +done < "$DIR"/index.categories diff --git a/v2/src/bin/index b/v2/src/bin/index new file mode 100755 index 0000000..36750b3 --- /dev/null +++ b/v2/src/bin/index @@ -0,0 +1,128 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + collection FILENAME + collection -h + EOF +} + +help() { + cat <<-'EOF' + Options: + -h, --help show this message + + FILENAME the target collection HTML page to be generated + + + Generate FILENAME as a collection index. The collection type + and language are inferred by the name of FILENAME. + + + Examples: + + Generate an index.html entry for english pastebins: + + $ collection src/en/pastebins/index.html + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + +FILENAME="${1:-}" +eval "$(assert_arg "$FILENAME" 'FILENAME')" +DIR="$(dirname "$FILENAME")" + + +l="$(lang-for "$FILENAME")" +. src/lib/base.conf +. src/lib/generated.conf +# shellcheck source=/dev/null +. src/lib/generated."$l".conf +# shellcheck source=/dev/null +. src/lib/base."$l".conf + +url_part="$(printf '%s' "${FILENAME#"$CONTENT_PREFIX"/}" | sed "s|\.md$|.html|")" +url_absolute="$(url-for "$url_part" | absolute)" +collection="$(collection-for "$FILENAME")" +feed_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}"/feed.xml)" +by_category_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_part:?}")" +title_html="$(eval "echo \"\$index_${collection}_title\"" | htmlesc)" +index_recent_title_html="$(eval "echo \"\$index_recent_${collection}_title\"" | htmlesc)" +index_category_title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)" +export url_absolute feed_url by_category_url title_html index_recent_title_html \ + index_category_title_html + + + +mkdir -p "$DIR" +{ + cat src/lib/preamble.html src/lib/index-preamble.html | envsubst + find "$DIR"/*.sortdata 2>/dev/null | + sort -nr | + xargs cat | + sed 's|\.md$|.indexentry|' | + xargs cat + cat src/lib/index-postamble.html src/lib/postamble.html | envsubst +} > "$FILENAME" + + +CATEGORY_FILENAME="$CONTENT_PREFIX$by_category_url" +echo "$CATEGORY_FILENAME" > "${FILENAME%.html}.extrahtml" + +url_absolute="$(absolute "$by_category_url")" +title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)" +export url_absolute title_html + + +DIR="$(dirname "$CATEGORY_FILENAME")" +mkdir -p "$DIR" +{ + envsubst < src/lib/preamble.html + while read -r category; do + feed_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/feed.$category.xml")" + index_recent_title_html="$category" + export category feed_url index_recent_title_html + + envsubst < src/lib/category-header.html + echo ' <ul>' + < "$DIR/$category.category" \ + sed 's|\.md$|.categoryentry|' | + xargs cat + echo ' </ul>' + done < "$DIR"/index.categories + envsubst < src/lib/postamble.html +} > "$CATEGORY_FILENAME" diff --git a/v2/src/bin/indexentry b/v2/src/bin/indexentry new file mode 100755 index 0000000..03bf771 --- /dev/null +++ b/v2/src/bin/indexentry @@ -0,0 +1,73 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + indexentry FILENAME + indexentry -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + FILENAME the name of the input .md file + + + Process FILE, and generate an index collection entry. + + + Examples: + + Generate the index entry for a TIL: + + $ indexentry src/tils/a-til.md > src/tils/a-til.indexentry + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +. src/lib.sh + +FILENAME="${1:-}" +eval "$(assert_arg "$FILENAME" 'FILENAME')" + + +# shellcheck source=/dev/null +. "${FILENAME%.md}.conf" + +envsubst < src/lib/entry.html diff --git a/v2/src/bin/makemake b/v2/src/bin/makemake index 665bb84..20fd6dd 100755 --- a/v2/src/bin/makemake +++ b/v2/src/bin/makemake @@ -74,7 +74,8 @@ EXTENSIONS=' ' COLL_EXTENSIONS=' -.sortref +.categoryentry +.indexentry .xmlentry ' @@ -116,16 +117,20 @@ for lang in $(langs); do exts | sed "s|^\(.*\)\$|\$($c.$lang\1)|" | varlist "$c.$lang" mds | sed 's/^\(.*\)\.md$/\1.conf \1.content: \1.md/' - mds | sed 's/^\(.*\)\.md$/\1.snippets \1.htmlbody \1.html: \1.conf \1.content/' + mds | sed 's/^\(.*\)\.md$/\1.categoryentry \1.indexentry \1.html: \1.conf \1.content/' + mds | sed 's/^\(.*\)\.md$/\1.snippets \1.htmlbody: \1.html/' if [ "$c" = 'pages' ]; then continue fi - mds | sed 's/^\(.*\)\.md$/\1.sortref: \1.md/' - mds | sed 's/^\(.*\)\.md$/\1.xmlentry: \1.html/' + mds | sed 's/^\(.*\)\.md$/\1.xmlentry: \1.htmlbody/' - echo "$CONTENT_PREFIX/$lang/feeds/$c.xml: \$($c.$lang.xmlentry)" + echo "$CONTENT_PREFIX/$lang/$c/index.categories: \$($c.$lang.categoryentry)" + echo "$CONTENT_PREFIX/$lang/$c/index.html: \$($c.$lang.indexentry) $CONTENT_PREFIX/$lang/$c/index.categories" + echo "$CONTENT_PREFIX/$lang/$c/feed.xml: \$($c.$lang.xmlentry) $CONTENT_PREFIX/$lang/$c/index.categories" + echo "$CONTENT_PREFIX/$lang/$c/index.extrahtml: $CONTENT_PREFIX/$lang/$c/index.html" + echo "$CONTENT_PREFIX/$lang/$c/index.extrafeeds: $CONTENT_PREFIX/$lang/$c/feed.xml" printf '\n\n' done @@ -141,17 +146,33 @@ for lang in $(langs); do done collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/feeds/\1.xml|" | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.categories|" | + varlist "all-generated.$lang.categories" + + collections | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.extrahtml|" | + varlist "all-generated.$lang.extrahtml" + + collections | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.extrafeeds|" | + varlist "all-generated.$lang.extrafeeds" + + collections | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.html|" | + varlist "all-generated.$lang.index" + + collections | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/feed.xml|" | varlist "all-generated.$lang.xml" - extensions '.xml' | + extensions '.categories' '.extrahtml' '.extrafeeds' '.index' '.xml' | sed "s|^\(.*\)\$|\$(all-generated.$lang\1)|" | varlist "all-generated.$lang" printf '\n' done -for e in $(extensions .xml); do +for e in $(extensions '.categories' '.extrahtml' '.extrafeeds' '.index' '.xml'); do langs | sed "s|^\(.*\)\$|\$(all-generated.\1$e)|" | varlist "all-generated$e" |