summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-04-29 19:23:58 -0300
committerEuAndreh <eu@euandre.org>2025-04-29 19:23:58 -0300
commit2dcdd72d693f9a886a2751ab65fc0e85c04d1e1a (patch)
tree98828e47ff4cccf4b480b77018a5f121097ea5c4
parentsrc/{conf,indexbody}: Replace $feedicon_url_prefix with $feedicon_url (diff)
downloadmkwb-2dcdd72d693f9a886a2751ab65fc0e85c04d1e1a.tar.gz
mkwb-2dcdd72d693f9a886a2751ab65fc0e85c04d1e1a.tar.xz
Add "mapentry" and "sitemap" subcommands
-rw-r--r--deps.mk2
-rwxr-xr-xsrc/conf12
-rwxr-xr-xsrc/mapentry19
-rwxr-xr-xsrc/sitemap22
4 files changed, 55 insertions, 0 deletions
diff --git a/deps.mk b/deps.mk
index 49c90a3..c65c232 100644
--- a/deps.mk
+++ b/deps.mk
@@ -10,6 +10,8 @@ libexec.sh = \
src/indexbody \
src/indexentry \
src/links \
+ src/mapentry \
+ src/sitemap \
src/snippets \
src/sortdata \
src/symlinks \
diff --git a/src/conf b/src/conf
index 16c43a8..6951462 100755
--- a/src/conf
+++ b/src/conf
@@ -168,6 +168,9 @@ cat -- "$CONF"
url="$(printf '%s\n' "${UNPREFIXED%.adoc}.html" | shesc)"
+
+lastmod_epoch="$(stat --printf='%Y' "$FILENAME" | shesc)"
+
collurl=
date_iso=
date_epoch=
@@ -180,15 +183,21 @@ if is_article; then
date_iso="$(dateiso "$lastdirnames" | shesc)"
date_epoch="$(dateepoch "$date_iso" | shesc)"
date_formatted="$(datefmt "$date_iso" | shesc)"
+ lastmod_epoch="$date_epoch"
if [ -n "${updatedat:-}" ]; then
updatedat_iso="$(dateiso "$updatedat" | shesc)"
updatedat_epoch="$(dateepoch "$updatedat_iso" | shesc)"
updatedat_formatted="$(datefmt "$updatedat_iso" | shesc)"
+ lastmod_epoch="$updatedat_epoch"
fi
file="$(basename "$url")"
collurl="$(printf '%s\n' "$lastdirnames" | sed 's|-|/|g' | shesc)/$file"
fi
+lastmod_iso="$(dateiso "@$lastmod_epoch" | shesc)"
+lastmod_formatted="$(datefmt "$lastmod_iso" | shesc)"
+
+
BASE_URL="$(base_url)"
TITLE_RAW="$(cat -- "$FILENAME" | grep '^= .*' | head -n1 | cut -d' ' -f2- ||
echo 'MISSING')"
@@ -257,6 +266,9 @@ cat <<-EOF
export title_html="$title_html"
export titlefull="$titlefull"
export titlefull_html="$titlefull_html"
+ export lastmod_iso="$lastmod_iso"
+ export lastmod_epoch="$lastmod_epoch"
+ export lastmod_formatted="$lastmod_formatted"
export date_iso="$date_iso"
export date_epoch="$date_epoch"
export date_formatted="$date_formatted"
diff --git a/src/mapentry b/src/mapentry
new file mode 100755
index 0000000..857d4bd
--- /dev/null
+++ b/src/mapentry
@@ -0,0 +1,19 @@
+#!/bin/sh
+set -euo pipefail
+
+
+usage() {
+ echo 'Usage: mapentry FILENAME.conf'
+}
+
+FILENAME="${1:-}"
+eval "$(assert-arg -- "$FILENAME" 'FILENAME.conf')"
+. ./"$FILENAME"
+
+
+cat <<EOF
+ <url>
+ <loc>$url_absolute</loc>
+ <lastmod>$lastmod_iso</lastmod>
+ </url>
+EOF
diff --git a/src/sitemap b/src/sitemap
new file mode 100755
index 0000000..48be5ea
--- /dev/null
+++ b/src/sitemap
@@ -0,0 +1,22 @@
+#!/bin/sh
+set -euo pipefail
+
+
+opening() {
+ cat <<'EOF'
+<?xml version="1.0" encoding="UTF-8"?>
+<urlset
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
+ xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
+EOF
+}
+
+closing() {
+ echo '</urlset>'
+}
+
+
+opening
+cat "$@"
+closing