From 9284365c72fa4a23ce0605f3a1df5e92dab08551 Mon Sep 17 00:00:00 2001 From: rhiannon morris Date: Sun, 15 Sep 2024 17:49:23 +0200 Subject: [PATCH] =?UTF-8?q?add=20rss=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 19 ++++++++++++------- blog-meta/post-lists.hs | 21 ++++++++++++++++----- rss.yaml | 13 +++++++++++++ templates/rss.xml | 29 +++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 rss.yaml create mode 100644 templates/rss.xml diff --git a/Makefile b/Makefile index 3941f38..2e7dba0 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ POSTS != find $(POSTSDIR) -name '*.md' OUTPUTPOSTS = \ $(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \ $(addprefix $(BUILDDIR)/,$(STATICS)) \ - $(BUILDDIR)/index.html + $(BUILDDIR)/index.html $(BUILDDIR)/rss.xml STYLE != find style -type f OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE)) @@ -57,21 +57,26 @@ $(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk &: $(POSTS) $(ALL_TAGS) build: $(BUILDDIR)/all-tags.html include $(TMPDIR)/tags.mk -$(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post) -$(BUILDDIR)/%.html: $(TMPDIR)/%.md $(POSTDEPS) ; $(call pandoc,meta) +$(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post.html) +$(BUILDDIR)/%.html: $(TMPDIR)/%.md $(POSTDEPS) ; $(call pandoc,meta.html) + +$(BUILDDIR)/rss.xml: $(TMPDIR)/index.md $(POSTDEPS) + $(call pandoc,rss.xml,--metadata-file rss.yaml --write html) .PHONY: langfilter laantas-script langfilter laantas-script: %: ; cabal build $@ +# $(1): template file +# $(2): extra flags define pandoc - @echo "[pandoc] $<" + @echo "[pandoc] $(subst $(TMPDIR)/,,$(subst $(BUILDDIR)/,,$@))" mkdir -p $(dir $@) mkdir -p $(basename $@) - LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" \ + LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" LANG_COLOR="#325" \ DIRNAME="$(basename $@)" \ FILENAME="$@" \ - pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1).html -o $@ $< \ - -f markdown+emoji \ + pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1) -o $@ $< \ + -f markdown+emoji $(2) \ $(SYNTAXFLAGS) \ --filter $(LANGFILTER) --filter $(NICE_DATE) --filter $(SLUG_TAGS) \ --mathml --citeproc --csl=apa-eu.csl diff --git a/blog-meta/post-lists.hs b/blog-meta/post-lists.hs index 0919577..0da03a6 100644 --- a/blog-meta/post-lists.hs +++ b/blog-meta/post-lists.hs @@ -89,18 +89,29 @@ data PostInfo = instance YAML.ToYAML PostInfo where toYAML (Info file title date tags summary) = YAML.obj [("date" ##= date), + ("date-rss" ##= toRss date), ("title" ##= title), ("tags" ##= tags), ("file" ##= Text.pack (fixup file)), ("summary" ##= summary)] - where fixup f = Path.replaceExtension f "html" + where + fixup f = Path.replaceExtension f "html" + toRss (BD d) = RD d -newtype BlogDate = D Day deriving (Eq, Ord) +newtype BlogDate = BD Day deriving (Eq, Ord) +newtype RssDate = RD Day deriving (Eq, Ord) + +instance YAML.FromYAML RssDate where + parseYAML = YAML.withStr "YYYY-MM-DD" $ + fmap RD . parseTimeM True defaultTimeLocale "%F" . Text.unpack + +instance YAML.ToYAML RssDate where + toYAML (RD d) = YAML.str $ Text.pack $ + formatTime defaultTimeLocale "%a, %d %b %Y 00:00:01 UT" d instance YAML.FromYAML BlogDate where - parseYAML = YAML.withStr "YYYY-MM-DD" $ - fmap D . parseTimeM True defaultTimeLocale "%F" . Text.unpack + parseYAML = fmap (\(RD d) -> BD d) . YAML.parseYAML instance YAML.ToYAML BlogDate where - toYAML (D d) = YAML.str $ Text.pack $ map toLower $ + toYAML (BD d) = YAML.str $ Text.pack $ map toLower $ formatTime defaultTimeLocale "%a %-d %B %Y" d diff --git a/rss.yaml b/rss.yaml new file mode 100644 index 0000000..7642e6d --- /dev/null +++ b/rss.yaml @@ -0,0 +1,13 @@ +# info about name, path, etc for the rss feed + +# your name +author: niss + +# the rss feed will be called something like `$blogtitle$—all posts` +blogtitle: niss’s blog + +# overall blog description +blogdesc: lizards posting, on line + +# base path. it's uploaded to `$baseurl$/rss.xml` +baseurl: https://blog.niss.website diff --git a/templates/rss.xml b/templates/rss.xml new file mode 100644 index 0000000..42e5968 --- /dev/null +++ b/templates/rss.xml @@ -0,0 +1,29 @@ + + + + <![CDATA[$blogtitle$—$title$]]> + $baseurl$ + + + + $for(posts)$ + + <![CDATA[$it.title$]]> + $baseurl$/$it.file$ + $baseurl$/$it.file$ + + $it.date-rss$ + + tags: $it.tags[, ]$

+ + $if(it.summary)$ + $it.summary$ + $endif$ + ]]> +
+
+ $endfor$ +
+