commit 4158b6af1c8a14e83b51249e18cdf9695760e744
parent 5c03007dad509760f0572bd5901c46bef4a6f6df
Auteur: Selve <selve@asteride.xyz>
Date: Thu, 26 Oct 2023 23:01:29 -0400
[cont] ajout de flux RSS (atom)
Youpi!
Diffstat:
4 files changed, 123 insertions(+), 2 deletions(-)
diff --git a/construire.sh b/construire.sh
@@ -69,12 +69,37 @@ copier() {
sitemap.txt() {
res="$DOS_DST/$1/sitemap.txt"
tous="$(find "$DOS_DST/$1/" -type f ! -name 'sitemap.*' \
- ! -name '*.gz' ! -name '*.css')"
- plus_jeune "$res" $tous || return 0
+ ! -name '*.gz' ! -name '*.css' ! -name '*.xml')"
echo "$res"
echo "$tous" | sed 's|^dst/\([^/]*\)|\1://'"$RACINE"'|' > "$res"
}
+# $1 fichier
+# $2 protocole
+# $3 destination
+# $4 flux
+# $+ fichiers
+flux() {
+ f="$1"
+ proto="$2"
+ dest="$3"
+ flux="$4"
+ shift 4
+ echo "$f -> $flux"
+ aplat <"$f" | exclure -vdest="$dest" | awk -v fichier="$DOS_LIENS/$proto" \
+ -f "$DOS_LIB/general.awk" -f "$DOS_LIB/liens/rempl.awk" |
+ awk -f "$DOS_LIB/general.awk" -f "$DOS_LIB/atom.awk" - "$@" \
+ >"$flux"
+}
+
+# $1 protocole
+# $2 destination
+flux_articles() {
+ fichiers="$(find "$DOS_SRC/articles" -type f -name "*.$1.aplat")"
+ flux "$DOS_SRC/flux/articles.special.debout" "$1" "$2" \
+ "$DOS_DST/$2/flux/articles_$1.xml" $fichiers
+}
+
# $1 protocole
# $2 destination
gen_aplat() {
@@ -114,6 +139,9 @@ gemini() {
gen_final "gemini" "gemtext" "gmi"
humans "gemini"
sitemap.txt "gemini"
+ flux_articles "gemini" "gemini"
+ flux_articles "https" "gemini"
+ flux_articles "http" "gemini"
}
http() {
@@ -126,6 +154,9 @@ http() {
humans "http"
sitemap.txt "http"
compresser "$DOS_DST/http"
+ flux_articles "gemini" "http"
+ flux_articles "https" "http"
+ flux_articles "http" "http"
}
https() {
@@ -138,6 +169,9 @@ https() {
humans "https"
sitemap.txt "https"
compresser "$DOS_DST/https"
+ flux_articles "gemini" "https"
+ flux_articles "https" "https"
+ flux_articles "http" "https"
}
# $1 protocol
@@ -160,6 +194,7 @@ tout() {
gemini
http
https
+ flux_tous
}
publier() {
diff --git a/lib/atom.awk b/lib/atom.awk
@@ -0,0 +1,60 @@
+etq("^:doc:$") && ouvrante() {
+ metadonnees_lire(meta)
+ type = meta[":doc:@:type:"]
+ titre = meta[":doc:@:titre:"]
+ sous_titre = meta[":doc:@:sous-titre:"]
+ uuid = meta[":doc:@:uuid:"]
+ auteur = meta[":doc:@:auteur:"]
+
+ if (type == "article") {
+ date_pub = meta[":doc:@:date-pub:"]
+ date_mod = meta[":doc:@:date-mod:"]
+ lien = meta[":doc:@:lien:"]
+ description = meta[":doc:@:description:"]
+ date_lire(date_pub, date)
+ uuid_date[uuid] = date_nombre(date)
+ tampons[uuid] = "\t<entry>\n\
+ <title>" titre "</title>\n\
+ <link href=\"" lien "\" />\n\
+ <id>urn:uuid:" uuid "</id>\n\
+ <published>" date_pub "</published>\n\
+ <author><name>" auteur "</name></author>\n"
+ if (date_mod)
+ tampons[uuid] = tampons[uuid] \
+" <updated>" date_mod "</updated>\n"
+ if (description)
+ tampons[uuid] = tampons[uuid] \
+" <summary>" description "</summary>\n"
+ tampons[uuid] = tampons[uuid] "\t</entry>\n\n"
+ } else if (type == "atom") {
+ cible = meta[":doc:@:cible:"]
+ entete = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\
+<feed xmlns=\"http://www.w3.org/2005/Atom\">\n\n\
+ <title>" titre "</title>\n\
+ <link href=\"" cible "\" />\n\
+ <id>urn:uuid:" uuid "</id>\n"
+ }
+ metadonnees_supp(meta, $1)
+}
+
+END {
+ i = 0
+ while (length(uuid_date)) {
+ max = 0
+ for (v in uuid_date) {
+ if (uuid_date[v] > max) {
+ max = uuid_date[v]
+ uuid = v
+ }
+ }
+ d = uuid_date[uuid]
+ delete uuid_date[uuid]
+ ordre[++i] = uuid
+ }
+ nombre_date(d, date)
+ printf("%s%s\n\n", entete,
+ "\t<updated>" date_nombre_formater(date) "</updated>")
+ for (j = 1; j <= i; j++)
+ printf("%s", tampons[ordre[j]])
+ print "</feed>"
+}
diff --git a/lib/general.awk b/lib/general.awk
@@ -131,6 +131,19 @@ function date_formater(DATE, phrase) {
return phrase
}
+function date_nombre_formater(DATE, chaine) {
+ chaine = DATE[1] "-" DATE[2] "-" DATE[3]
+ if (DATE[4] != -1) {
+ chaine = chaine "T" DATE[4]
+ if (DATE[5] != -1) {
+ chaine = chaine - DATE[5]
+ if (DATE[6] != -1)
+ chaine = chaine - DATE[6]
+ }
+ }
+ return chaine
+}
+
function noms_jours(N) {
if (N < 1 || N > 31)
return ""
diff --git a/src/flux/articles.special.debout b/src/flux/articles.special.debout
@@ -0,0 +1,13 @@
+(doc
+ (@ (type "atom")
+ (type-contenu "article")
+ (titre (si (@ (#dest=web "Le Site Internet"))
+ "La Capsule Gemini")
+ " de Selve")
+ (sous-titre "Les articles "
+ (si (@ (#dest=web "du site Internet"))
+ "de la capsule Gemini")
+ " de Selve")
+ (auteur "Selve")
+ (cible (ref-std "ACCUEIL"))
+ (uuid "f09e671b-34d3-4ea6-81a9-f71ef2e6277e")))