diff options
Diffstat (limited to '')
-rwxr-xr-x | v2/src/bin/categories | 2 | ||||
-rwxr-xr-x | v2/src/bin/category | 2 | ||||
-rwxr-xr-x | v2/src/bin/coll2path | 88 | ||||
-rwxr-xr-x | v2/src/bin/collection-for | 29 | ||||
-rwxr-xr-x | v2/src/bin/collections | 4 | ||||
-rwxr-xr-x | v2/src/bin/conf | 2 | ||||
-rwxr-xr-x | v2/src/bin/feed | 9 | ||||
-rwxr-xr-x | v2/src/bin/html | 10 | ||||
-rwxr-xr-x | v2/src/bin/index | 8 | ||||
-rwxr-xr-x | v2/src/bin/indexentry | 4 | ||||
-rwxr-xr-x | v2/src/bin/makemake | 47 | ||||
-rwxr-xr-x | v2/src/bin/xmlentry | 8 |
12 files changed, 163 insertions, 50 deletions
diff --git a/v2/src/bin/categories b/v2/src/bin/categories index bc08704..de65acb 100755 --- a/v2/src/bin/categories +++ b/v2/src/bin/categories @@ -24,7 +24,7 @@ help() { Generate the index.categories entry for english pastebins: - $ categories src/en/pastebins/index.categories + $ categories src/en/pastebin/index.categories EOF } diff --git a/v2/src/bin/category b/v2/src/bin/category index 2a2fdea..16eea0e 100755 --- a/v2/src/bin/category +++ b/v2/src/bin/category @@ -68,7 +68,7 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" # shellcheck source=/dev/null -. "${FILENAME%.md}.conf" +. "${FILENAME%.*}.conf" DIR="$(dirname "$FILENAME")" diff --git a/v2/src/bin/coll2path b/v2/src/bin/coll2path new file mode 100755 index 0000000..79b2f53 --- /dev/null +++ b/v2/src/bin/coll2path @@ -0,0 +1,88 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + coll2path LANGUAGE COLLECTION + coll2path -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + LANGUAGE in which language to list the collections + names for + COLLECTION what collection to get the path for + + + Get the path for the COLLECTION, doing the proper translation + on the way, and checking if is "article". + + + Examples: + + Get the path for "TIL" in portuguese: + + $ coll2path pt til + hea/ + + + Get the path for "articles" in english + + $ collections en articles + + 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 + + +LANGUAGE="${1:-}" +COLLECTION="${2:-}" +eval "$(assert_arg "$LANGUAGE" 'LANGUAGE')" + +# shellcheck source=/dev/null +. src/lib/commencement."$LANGUAGE".conf + +if [ -z "$COLLECTION" ]; then + echo "${article_collection_name:-}" +else + NAME="$(eval "echo \"\$${COLLECTION}_collection_name\"")" + echo "$NAME${NAME:+/}" +fi diff --git a/v2/src/bin/collection-for b/v2/src/bin/collection-for index b3fc211..87f1204 100755 --- a/v2/src/bin/collection-for +++ b/v2/src/bin/collection-for @@ -24,10 +24,10 @@ help() { Examples: - Get "tils" for "src/en/tils/some-pt.md": + Get "til" for "src/en/til/some-pt.md": - $ collection-for src/en/tils/some-pt.md - tils + $ collection-for src/en/til/some-pt.md + til EOF } @@ -69,15 +69,18 @@ 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 +lang="$(lang-for "$FILE")" +DIR="$(dirname "$FILE")" +if [ "$DIR" = "$CONTENT_PREFIX/$lang" ]; then + echo else - NAME="$(echo "$ATTEMPT" | cut -d/ -f1)" - collections | grep "$NAME" + NAME="$(basename "$DIR")" + NTH="$( + collections | + xargs -I% coll2path "$lang" % | + awk '{ print NR, substr($0, 1, length($0) - 1) }' | + grep " $NAME$" | + cut -d' ' -f1 + )" + collections | awk -vNTH="$NTH" 'NR == NTH' fi diff --git a/v2/src/bin/collections b/v2/src/bin/collections index 1df0c39..0a8e156 100755 --- a/v2/src/bin/collections +++ b/v2/src/bin/collections @@ -28,8 +28,8 @@ help() { Just run it: $ collections - tils - pastebins + til + pastebin EOF } diff --git a/v2/src/bin/conf b/v2/src/bin/conf index 62ef97a..92ecc68 100755 --- a/v2/src/bin/conf +++ b/v2/src/bin/conf @@ -178,7 +178,7 @@ if [ -n "${update:-}" ]; then fi -url_part="$(printf '%s' "${FILENAME%.md}.html" | sed "s|^$CONTENT_PREFIX/||")" +url_part="$(printf '%s' "${FILENAME%.*}.html" | sed "s|^$CONTENT_PREFIX/||")" url="$(url-for "$url_part")" title_uri="$(uri "$title")" diff --git a/v2/src/bin/feed b/v2/src/bin/feed index 52c6199..f55ba89 100755 --- a/v2/src/bin/feed +++ b/v2/src/bin/feed @@ -27,7 +27,7 @@ help() { Generate a feed for TILs: - $ feed src/en/tils/feed.xml + $ feed src/en/til/feed.xml EOF } @@ -76,8 +76,9 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" now="$(date -uIs)" url_absolute="$(url-for "${FILENAME#"$CONTENT_PREFIX"/}" | absolute)" site_name_html="$(htmlesc "${site_name:?}")" -collection="$(collection-for "$FILENAME")" -collection_url_absolute="$(url-for "${lang:?}/$collection/" | absolute)" +collection="$(sh src/bin/collection-for "$FILENAME")" +coll_path="$(coll2path "${lang:?}" "$collection")" +collection_url_absolute="$(url-for "${lang:?}/$coll_path" | absolute)" feed_title_html="$(eval "echo \"\$feed_${collection}_title\"" | htmlesc)" export now url_absolute site_name_html collection_url_absolute feed_title_html @@ -96,7 +97,7 @@ mkdir -p "$DIR" 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)" + collection_url_absolute="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_name:?}#$category" | absolute)" feed_title_html="$(eval "echo \"\$index_category_${collection}_title\"" | htmlesc)" export url_absolute collection_url_absolute feed_title_html diff --git a/v2/src/bin/html b/v2/src/bin/html index f995753..578c539 100755 --- a/v2/src/bin/html +++ b/v2/src/bin/html @@ -68,7 +68,7 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" # shellcheck source=/dev/null -. "${FILENAME%.md}.conf" +. "${FILENAME%.*}.conf" # # Utility functions @@ -99,7 +99,7 @@ markdown_to_html() { } extract_plaintext_snippets() ( - SNIPPETS="${FILENAME%.md}.snippets" + SNIPPETS="${FILENAME%.*}.snippets" printf '' > "$SNIPPETS" F="$(mkstemp)" cat > "$F" @@ -117,7 +117,7 @@ extract_plaintext_snippets() ( if printf '%s' "$line" | grep -q "^$INDENT<pre><code"; then IN_BLOCK=1 - OUT="${FILENAME%.md}.html.$BLOCK_NUMBER.txt" + OUT="${FILENAME%.*}.html.$BLOCK_NUMBER.txt" BLOCK_NUMBER=$((BLOCK_NUMBER + 1)) printf '%s\n' "$line" | sed "s|^\($INDENT<pre><code.*>\)\(.*\)$|\2|" | @@ -205,7 +205,7 @@ warn_duplicate_ids() { } emit_body() { - < "${FILENAME%.md}.content" \ + < "${FILENAME%.*}.content" \ markdown_to_html | extract_plaintext_snippets | add_line_numbers | @@ -214,5 +214,5 @@ emit_body() { } envsubst < src/lib/preamble.html -emit_body | tee "${FILENAME%.md}.htmlbody" +emit_body | tee "${FILENAME%.*}.htmlbody" envsubst < src/lib/postamble.html diff --git a/v2/src/bin/index b/v2/src/bin/index index 36750b3..46e0c88 100755 --- a/v2/src/bin/index +++ b/v2/src/bin/index @@ -4,8 +4,8 @@ set -eu usage() { cat <<-'EOF' Usage: - collection FILENAME - collection -h + index FILENAME + index -h EOF } @@ -25,7 +25,7 @@ help() { Generate an index.html entry for english pastebins: - $ collection src/en/pastebins/index.html + $ index src/en/pastebin/index.html EOF } @@ -79,7 +79,7 @@ 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:?}")" +by_category_url="$(url-for "${DIR#"$CONTENT_PREFIX"/}/${by_category_url_name:?}")" 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)" diff --git a/v2/src/bin/indexentry b/v2/src/bin/indexentry index 03bf771..f971a30 100755 --- a/v2/src/bin/indexentry +++ b/v2/src/bin/indexentry @@ -26,7 +26,7 @@ help() { Generate the index entry for a TIL: - $ indexentry src/tils/a-til.md > src/tils/a-til.indexentry + $ indexentry src/til/a-til.md > src/til/a-til.indexentry EOF } @@ -68,6 +68,6 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" # shellcheck source=/dev/null -. "${FILENAME%.md}.conf" +. "${FILENAME%.*}.conf" envsubst < src/lib/entry.html diff --git a/v2/src/bin/makemake b/v2/src/bin/makemake index 20fd6dd..06041b0 100755 --- a/v2/src/bin/makemake +++ b/v2/src/bin/makemake @@ -98,14 +98,17 @@ for lang in $(langs); do for c in pages $(collections); do if [ "$c" = 'pages' ]; then filter="$page_ext_filter" - dir="$CONTENT_PREFIX/$lang" + src='page' + coll_path='' else filter='^$' - dir="$CONTENT_PREFIX/$lang/$c" + src='md' + coll_path="$(coll2path "$lang" "$c")" fi mds() { - find "$dir"/*.md 2>/dev/null + git ls-files "$CONTENT_PREFIX/$lang/$coll_path"*."$src" | + sed 's|\.page$|.md|' } exts() { @@ -120,17 +123,19 @@ for lang in $(langs); do 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 + mds | sed 's|\.md$|\.page|' | varlist "pages.$lang.page" + mds | sed "s|^\(.*\).md$|\1.md: \1.page|" continue fi mds | sed 's/^\(.*\)\.md$/\1.xmlentry: \1.htmlbody/' - 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/${coll_path}index.categories: \$($c.$lang.categoryentry)" + echo "$CONTENT_PREFIX/$lang/${coll_path}index.html: \$($c.$lang.indexentry) $CONTENT_PREFIX/$lang/${coll_path}index.categories" + echo "$CONTENT_PREFIX/$lang/${coll_path}feed.xml: \$($c.$lang.xmlentry) $CONTENT_PREFIX/$lang/${coll_path}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" + echo "$CONTENT_PREFIX/$lang/${coll_path}index.extrahtml: $CONTENT_PREFIX/$lang/${coll_path}index.html" + echo "$CONTENT_PREFIX/$lang/${coll_path}index.extrafeeds: $CONTENT_PREFIX/$lang/${coll_path}feed.xml" printf '\n\n' done @@ -146,23 +151,28 @@ for lang in $(langs); do done collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.categories|" | + xargs -I% coll2path "$lang" % | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1index.categories|" | varlist "all-generated.$lang.categories" collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.extrahtml|" | + xargs -I% coll2path "$lang" % | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1index.extrahtml|" | varlist "all-generated.$lang.extrahtml" collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.extrafeeds|" | + xargs -I% coll2path "$lang" % | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1index.extrafeeds|" | varlist "all-generated.$lang.extrafeeds" collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/index.html|" | + xargs -I% coll2path "$lang" % | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1index.html|" | varlist "all-generated.$lang.index" collections | - sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1/feed.xml|" | + xargs -I% coll2path "$lang" % | + sed "s|^\(.*\)\$|$CONTENT_PREFIX/$lang/\1feed.xml|" | varlist "all-generated.$lang.xml" extensions '.categories' '.extrahtml' '.extrafeeds' '.index' '.xml' | @@ -172,6 +182,11 @@ for lang in $(langs); do printf '\n' done +git ls-files | + grep '\.page' | + sed "s|^$CONTENT_PREFIX\(.*\)\.page|\1.md|" > "$CONTENT_PREFIX"/.gitignore + + for e in $(extensions '.categories' '.extrahtml' '.extrafeeds' '.index' '.xml'); do langs | sed "s|^\(.*\)\$|\$(all-generated.\1$e)|" | @@ -180,6 +195,11 @@ done # shellcheck disable=2016 langs | + sed 's|^\(.*\)$|$(pages.\1.md)|' | + varlist 'pages-mds' + +# shellcheck disable=2016 +langs | sed 's|^\(.*\)$|$(all-generated.\1)|' | varlist 'all-generated' @@ -190,4 +210,5 @@ git ls-files src/ | git ls-files "$CONTENT_PREFIX"/ | grep -v '\.md$' | + grep -v '\.page$' | varlist 'static-content' diff --git a/v2/src/bin/xmlentry b/v2/src/bin/xmlentry index b0760ae..f6fb6ea 100755 --- a/v2/src/bin/xmlentry +++ b/v2/src/bin/xmlentry @@ -26,7 +26,7 @@ help() { Generate the XML entry for a TIL: - $ xmlentry src/tils/a-til.md > src/tils/a-til.xml + $ xmlentry src/til/a-til.md > src/til/a-til.xml EOF } @@ -68,14 +68,14 @@ eval "$(assert_arg "$FILENAME" 'FILENAME')" # shellcheck source=/dev/null -. "${FILENAME%.md}.conf" +. "${FILENAME%.*}.conf" envsubst < src/lib/entry.xml -head -n1 < "${FILENAME%.md}.htmlbody" | htmlesc +head -n1 < "${FILENAME%.*}.htmlbody" | htmlesc printf ' </summary>\n' printf ' <content type="html" xml:base="%s">\n' "${url:?}" -htmlesc < "${FILENAME%.md}.htmlbody" +htmlesc < "${FILENAME%.*}.htmlbody" printf ' </content>\n' printf ' </entry>\n' |