diff options
Diffstat (limited to '')
-rw-r--r-- | v2/.gitignore | 1 | ||||
-rw-r--r-- | v2/dynamic.mk | 14 | ||||
-rwxr-xr-x | v2/src/bin/makemake | 3 | ||||
-rwxr-xr-x | v2/src/bin/mapentry | 75 | ||||
-rwxr-xr-x | v2/src/bin/sitemap | 72 | ||||
-rw-r--r-- | v2/src/lib/mapentry.xml | 5 |
6 files changed, 166 insertions, 4 deletions
diff --git a/v2/.gitignore b/v2/.gitignore index 84d3bd9..ac25e0d 100644 --- a/v2/.gitignore +++ b/v2/.gitignore @@ -15,6 +15,7 @@ /src/content/**/*.html /src/content/**/*.extrahtml /src/content/**/*.i18n +/src/content/**/*.mapentry /src/content/**/*.md.next /src/content/**/*.md.prev /src/content/**/*.md.tmp diff --git a/v2/dynamic.mk b/v2/dynamic.mk index ef7d24c..c0a3132 100644 --- a/v2/dynamic.mk +++ b/v2/dynamic.mk @@ -7,7 +7,7 @@ include generated.mk .SUFFIXES: -.SUFFIXES: .page .md .content .conf .html .categoryentry .indexentry .xmlentry .uncolored +.SUFFIXES: .page .md .content .conf .html .categoryentry .indexentry .xmlentry .mapentry .uncolored .page.md: @@ -33,6 +33,9 @@ include generated.mk .md.xmlentry: xmlentry $< > $@ +.md.mapentry: + mapentry $< > $@ + .uncolored: printf '%s\n%s\n%s\n' \ "`head -n2 $<`" \ @@ -71,7 +74,9 @@ i18n-index.sentinel: po/i18n.mappings clean: rm -rf \ $(all-generated) $(pages-mds) $(svgs) public/ *.sentinel \ - generated.mk po/po4a.cfg src/content/.gitignore \ + generated.mk po/po4a.cfg po/*.mo \ + src/lib/generated.conf src/lib/generated.*.conf \ + src/content/.gitignore src/content/sitemap.xml \ src/content/*/*.category src/content/*/*/*.category \ src/content/*/*.categorysort src/content/*/*/*.categorysort \ src/content/*/*.html src/content/*/*/*.html \ @@ -83,7 +88,6 @@ clean: src/content/*/feed.*.xml src/content/*/*/feed.*.xml \ src/content/*/*.md.next src/content/*/*/*.md.next \ src/content/*/*.md.prev src/content/*/*/*.md.prev \ - src/lib/generated.conf src/lib/generated.*.conf po/*.mo \ public: symlink-mappings.sentinel copy-content.sentinel copy-containers.sentinel @@ -94,6 +98,7 @@ content = \ $(all-generated.xml) \ $(static-content) \ $(svgs) \ + src/content/sitemap.xml \ containers = \ $(all-generated.snippets) \ @@ -101,6 +106,9 @@ containers = \ $(all-generated.extrafeeds) \ +src/content/sitemap.xml: $(all-generated.mapentry) + sitemap > $@ + symlink-mappings.sentinel: src/redirect.mappings awk '{print $$2}' src/redirect.mappings | \ xargs dirname | \ diff --git a/v2/src/bin/makemake b/v2/src/bin/makemake index 22e92c9..c6e3407 100755 --- a/v2/src/bin/makemake +++ b/v2/src/bin/makemake @@ -71,6 +71,7 @@ EXTENSIONS=' .html .snippets .htmlbody +.mapentry ' COLL_EXTENSIONS=' @@ -119,7 +120,7 @@ for lang in $(langs); do exts | sed "s|^\(.*\)\$|$c.$lang\1 = \$($c.$lang.md:.md=\1)|" exts | sed "s|^\(.*\)\$|\$($c.$lang\1)|" | varlist "$c.$lang" - mds | sed 's/^\(.*\)\.md$/\1.conf \1.content: \1.md/' + mds | sed 's/^\(.*\)\.md$/\1.mapentry \1.conf \1.content: \1.md/' 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 diff --git a/v2/src/bin/mapentry b/v2/src/bin/mapentry new file mode 100755 index 0000000..34b6e75 --- /dev/null +++ b/v2/src/bin/mapentry @@ -0,0 +1,75 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + mapentry FILENAME + mapentry -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + FILENAME the name of the input .md file + + + Process FILENAME, and generate a "mapentry": an "<url>...</url>" + entry to be included into the final sitemap.xml + + + Examples: + + Generate the sitemap entry entry for a TIL: + + $ xmlentry src/til/a-til.md > src/til/a-til.mapentry + 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')" + + +url_absolute="$(url-for "$FILENAME" | absolute)" +lastmod="$(git log -1 --format=%ad --date=short "$FILENAME")" +export url_absolute lastmod + +envsubst < src/lib/mapentry.xml diff --git a/v2/src/bin/sitemap b/v2/src/bin/sitemap new file mode 100755 index 0000000..09f7eb1 --- /dev/null +++ b/v2/src/bin/sitemap @@ -0,0 +1,72 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + sitemap + sitemap -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + + Process all generate "*.mapentry" files, combine them all + together into the final "sitemap.xml" file. + + + Examples: + + Generate the final sitemap.xml: + + $ sitemap > src/sitemap.xml + 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)) + + + +printf '<?xml version="1.0" encoding="UTF-8"?>\n' +printf '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n' + +find "$CONTENT_PREFIX"/ -type f -name '*.mapentry' | + LANG=POSIX.UTF-8 sort | + xargs cat + +printf '</urlset>\n' diff --git a/v2/src/lib/mapentry.xml b/v2/src/lib/mapentry.xml new file mode 100644 index 0000000..5c715c0 --- /dev/null +++ b/v2/src/lib/mapentry.xml @@ -0,0 +1,5 @@ + <url> + <loc>$url_absolute</loc> + <lastmod>$lastmod</lastmod> + <changefreq>monthly</changefreq> + </url> |