add rss 🎉

This commit is contained in:
rhiannon morris 2024-09-15 17:49:23 +02:00
parent 3ac457b1ec
commit 9284365c72
4 changed files with 70 additions and 12 deletions

View file

@ -15,7 +15,7 @@ POSTS != find $(POSTSDIR) -name '*.md'
OUTPUTPOSTS = \ OUTPUTPOSTS = \
$(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \ $(patsubst $(POSTSDIR)/%.md,$(BUILDDIR)/%.html,$(POSTS)) \
$(addprefix $(BUILDDIR)/,$(STATICS)) \ $(addprefix $(BUILDDIR)/,$(STATICS)) \
$(BUILDDIR)/index.html $(BUILDDIR)/index.html $(BUILDDIR)/rss.xml
STYLE != find style -type f STYLE != find style -type f
OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE)) OUTPUTSTYLE = $(patsubst %,$(BUILDDIR)/%,$(STYLE))
@ -57,21 +57,26 @@ $(TMPDIR)/all-tags.md $(TMPDIR)/tags.mk &: $(POSTS) $(ALL_TAGS)
build: $(BUILDDIR)/all-tags.html build: $(BUILDDIR)/all-tags.html
include $(TMPDIR)/tags.mk include $(TMPDIR)/tags.mk
$(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post) $(BUILDDIR)/%.html: $(POSTSDIR)/%.md $(POSTDEPS) ; $(call pandoc,post.html)
$(BUILDDIR)/%.html: $(TMPDIR)/%.md $(POSTDEPS) ; $(call pandoc,meta) $(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 .PHONY: langfilter laantas-script
langfilter laantas-script: %: ; cabal build $@ langfilter laantas-script: %: ; cabal build $@
# $(1): template file
# $(2): extra flags
define pandoc define pandoc
@echo "[pandoc] $<" @echo "[pandoc] $(subst $(TMPDIR)/,,$(subst $(BUILDDIR)/,,$@))"
mkdir -p $(dir $@) mkdir -p $(dir $@)
mkdir -p $(basename $@) mkdir -p $(basename $@)
LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" \ LAANTAS_SCRIPT="$(LAANTAS_SCRIPT)" LANG_COLOR="#325" \
DIRNAME="$(basename $@)" \ DIRNAME="$(basename $@)" \
FILENAME="$@" \ FILENAME="$@" \
pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1).html -o $@ $< \ pandoc -s --toc --toc-depth=2 --template $(TEMPLATEDIR)/$(1) -o $@ $< \
-f markdown+emoji \ -f markdown+emoji $(2) \
$(SYNTAXFLAGS) \ $(SYNTAXFLAGS) \
--filter $(LANGFILTER) --filter $(NICE_DATE) --filter $(SLUG_TAGS) \ --filter $(LANGFILTER) --filter $(NICE_DATE) --filter $(SLUG_TAGS) \
--mathml --citeproc --csl=apa-eu.csl --mathml --citeproc --csl=apa-eu.csl

View file

@ -89,18 +89,29 @@ data PostInfo =
instance YAML.ToYAML PostInfo where instance YAML.ToYAML PostInfo where
toYAML (Info file title date tags summary) = YAML.obj toYAML (Info file title date tags summary) = YAML.obj
[("date" ##= date), [("date" ##= date),
("date-rss" ##= toRss date),
("title" ##= title), ("title" ##= title),
("tags" ##= tags), ("tags" ##= tags),
("file" ##= Text.pack (fixup file)), ("file" ##= Text.pack (fixup file)),
("summary" ##= summary)] ("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 instance YAML.FromYAML BlogDate where
parseYAML = YAML.withStr "YYYY-MM-DD" $ parseYAML = fmap (\(RD d) -> BD d) . YAML.parseYAML
fmap D . parseTimeM True defaultTimeLocale "%F" . Text.unpack
instance YAML.ToYAML BlogDate where 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 formatTime defaultTimeLocale "%a %-d %B %Y" d

13
rss.yaml Normal file
View file

@ -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: nisss blog
# overall blog description
blogdesc: lizards posting, on line
# base path. it's uploaded to `$baseurl$/rss.xml`
baseurl: https://blog.niss.website

29
templates/rss.xml Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><![CDATA[$blogtitle$—$title$]]></title>
<link>$baseurl$</link>
<description><![CDATA[$blogdesc$]]></description>
<atom:link href="$baseurl$/rss.xml" rel="self" />
$for(posts)$
<item>
<title><![CDATA[$it.title$]]></title>
<link>$baseurl$/$it.file$</link>
<guid>$baseurl$/$it.file$</guid>
<dc:creator><![CDATA[$author$]]></dc:creator>
<pubDate>$it.date-rss$</pubDate>
<description>
<![CDATA[
<p>tags: $it.tags[, ]$</p>
$if(it.summary)$
$it.summary$
$endif$
]]>
</description>
</item>
$endfor$
</channel>
</rss>