From e3240a57eef6bf0afa193ae83ecd8c5cf627c72f Mon Sep 17 00:00:00 2001 From: Volpeon Date: Wed, 26 May 2021 08:54:19 +0200 Subject: Category list improvements, generate ATOM feeds --- Makefile | 67 ++++++++++++++++++++--------- content/9thPK7O3xn/dreams/index.md | 1 + content/9thPK7O3xn/index.md | 10 +++-- content/9thPK7O3xn/misc/index.md | 3 +- content/9thPK7O3xn/posts/index.md | 4 ++ scripts/metadata_filter.lua | 76 ++++++++++++++++++++++++--------- templates/base.html | 4 ++ templates/feed.xml | 50 +++++++--------------- templates/feed_entry.xml | 30 +++++++++++++ templates/layouts/categorized_list.html | 46 ++++++++++---------- 10 files changed, 191 insertions(+), 100 deletions(-) create mode 100644 content/9thPK7O3xn/posts/index.md create mode 100644 templates/feed_entry.xml diff --git a/Makefile b/Makefile index aa4ecf3..b4a58e8 100644 --- a/Makefile +++ b/Makefile @@ -6,27 +6,31 @@ export DEPLOY_TARGET = vulpes@94.130.78.123:/srv/http/volpeon.ink/ # FILE GROUPS # -PANDOC_FILTERS := $(patsubst %,--lua-filter %,$(wildcard filters/*.lua)) -GLOBAL_METADATA := $(patsubst %,--metadata-file %,$(wildcard metadata/*.yaml)) - -CONTENT_SRC := $(shell find content -type f -name "*.md") -TEMPLATES_SRC := $(shell find templates -type f -name "*.html") -CSS_SRC := $(shell find assets/css -type f -name "*.scss") - -CONTENT_META := $(patsubst content/%.md,.cache/meta/%.json,$(CONTENT_SRC)) -CONTENT_FILES := $(patsubst content/%.md,out/%.html,$(CONTENT_SRC)) -FONT_FILES := $(patsubst assets/fonts/%.ttf,out/%.woff2,$(wildcard assets/fonts/*.ttf)) -CSS_FILES := $(patsubst assets/css/%.scss,out/%.css,$(wildcard assets/css/style.scss)) -STATIC_FILES := $(patsubst content/%,out/%,$(shell find content -type f ! -name "*.md")) +PANDOC_FILTERS := $(patsubst %,--lua-filter %,$(wildcard filters/*.lua)) +GLOBAL_METADATA := $(patsubst %,--metadata-file %,$(wildcard metadata/*.yaml)) + +CONTENT_SRC := $(shell find content -type f -name "*.md") +FEED_SRC := $(shell grep -l "^create_feed: *true$$" $(CONTENT_SRC)) +CONTENT_TEMPLATES_SRC := $(shell find templates -type f -name "*.html") +FEED_TEMPLATES_SRC := $(shell find templates -type f -name "*.xml") +CSS_SRC := $(shell find assets/css -type f -name "*.scss") + +CONTENT_META := $(patsubst content/%.md,.cache/meta/%.json,$(CONTENT_SRC)) +CONTENT_FILES := $(patsubst content/%.md,out/%.html,$(CONTENT_SRC)) +FEED_FILES := $(patsubst content/%.md,out/%.xml,$(FEED_SRC)) +FONT_FILES := $(patsubst assets/fonts/%.ttf,out/%.woff2,$(wildcard assets/fonts/*.ttf)) +CSS_FILES := $(patsubst assets/css/%.scss,out/%.css,$(wildcard assets/css/style.scss)) +STATIC_FILES := $(patsubst content/%,out/%,$(shell find content -type f ! -name "*.md")) # # TARGETS # -all: content_meta content_files static_files font_files css_files +all: content_meta content_files feed_files static_files font_files css_files content_meta: $(CONTENT_META) content_files: $(CONTENT_FILES) +feed_files: $(FEED_FILES) static_files: $(STATIC_FILES) font_files: $(FONT_FILES) css_files: $(CSS_FILES) @@ -43,14 +47,13 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) -.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq | .cache/meta +.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta $(info [META] $< -> $@) mkdir -p $(@D) $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) - $(eval PAGES = $(shell mktemp)) $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) - $(file >$(PAGES),$(if $(PAGES_FILES),$(shell jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES)),)) + $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",touch "$@.pages") pandoc \ -f markdown-citations \ -t plain \ @@ -58,11 +61,18 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ --template scripts/metadata_tpl.json \ --metadata namespace="$(NAMESPACE)" \ --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ - --metadata-file "$(PAGES)" \ + --metadata-file "$@.pages" \ -o "$@" "$<" - rm "$(PAGES)" - -out/%.html: content/%.md .cache/meta/%.json $(TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua out/style.css | out +# pandoc \ + -f markdown-citations \ + -t markdown \ + -o "$@.content" "$<" +# jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" + rm "$@.pages" +# rm "$@.meta" +# rm "$@.content" + +out/%.html: content/%.md .cache/meta/%.json $(CONTENT_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua out/style.css | out $(info [MARK] $< -> $@) mkdir -p $(@D) @@ -74,10 +84,27 @@ out/%.html: content/%.md .cache/meta/%.json $(TEMPLATES_SRC) metadata/*.yaml fil --lua-filter scripts/metadata_filter.lua \ $(GLOBAL_METADATA) \ --metadata-file "$(filter .cache/meta/%.json,$^)" \ + --metadata file_out="$@" \ --metadata style_hash="$(shell sha256sum out/style.css | cut -d ' ' -f 1)" \ $(PANDOC_FILTERS) \ -o "$@" "$<" +out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out + $(info [FEED] $< -> $@) + + mkdir -p $(@D) + pandoc \ + -f markdown-citations \ + -t html5 \ + --no-highlight \ + --template templates/feed.xml \ + --lua-filter scripts/metadata_filter.lua \ + $(GLOBAL_METADATA) \ + --metadata-file "$(filter .cache/meta/%.json,$^)" \ + --metadata file_out="$@" \ + $(PANDOC_FILTERS) \ + -o "$@" "$<" + out/%: content/% | out $(info [COPY] $< -> $@) diff --git a/content/9thPK7O3xn/dreams/index.md b/content/9thPK7O3xn/dreams/index.md index a204f42..fbe9a45 100644 --- a/content/9thPK7O3xn/dreams/index.md +++ b/content/9thPK7O3xn/dreams/index.md @@ -1,4 +1,5 @@ --- title: Dream Journal show_dates: true +position: 9 --- diff --git a/content/9thPK7O3xn/index.md b/content/9thPK7O3xn/index.md index 2545092..ce07a22 100644 --- a/content/9thPK7O3xn/index.md +++ b/content/9thPK7O3xn/index.md @@ -1,7 +1,11 @@ --- -title: Personal -layout: categorized_list +title: Personal +layout: categorized_list +create_feed: true --- Welcome to the personal section of my website! -Here you can find content I don't want to be easily accessible for all visitors, which is why I haven't linked this section anywhere. +The content in this section are things I don't feel belong in the public section of my website. +Partly because it's test pages I use for development purposes, and partly because it's content that's too personal in nature. + +I don't forbid you to share content from here -- not that I could stop you anyway --, but please avoid sharing it with larger audiences. diff --git a/content/9thPK7O3xn/misc/index.md b/content/9thPK7O3xn/misc/index.md index 24cd717..0fc9e44 100644 --- a/content/9thPK7O3xn/misc/index.md +++ b/content/9thPK7O3xn/misc/index.md @@ -1,3 +1,4 @@ --- -title: Other stuff +title: Other stuff +position: 10 --- diff --git a/content/9thPK7O3xn/posts/index.md b/content/9thPK7O3xn/posts/index.md new file mode 100644 index 0000000..592e730 --- /dev/null +++ b/content/9thPK7O3xn/posts/index.md @@ -0,0 +1,4 @@ +--- +title: Posts +position: 0 +--- diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index 000fda6..ebbd6d4 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua @@ -5,7 +5,7 @@ function format_date(date) local year, month, day = date:match("(%d%d%d%d)-(%d%d)-(%d%d)") if not year then return nil end - local time = os.time({year = tonumber(year), month = tonumber(month), day = tonumber(day)}) + local time = os.time({ year = tonumber(year), month = tonumber(month), day = tonumber(day) }) return { yyyy_mm_dd = os.date("%F", time), yyyy = os.date("%Y", time), @@ -21,7 +21,7 @@ function table_to_list(t, kv, cmp) local l = pandoc.List() if kv then - for key, value in pairs(t) do l:insert({key = key, value = value}) end + for key, value in pairs(t) do l:insert({ key = key, value = value }) end else for _, value in pairs(t) do l:insert(value) end end @@ -34,7 +34,7 @@ end function group_by(l, field, insert) insert = insert or function(group, _, item) if not group then - group = l:new({item}) + group = l:new({ item }) return group end group:insert(item) @@ -101,13 +101,13 @@ function resolve_url(site_url, ref_file, target_file) local abs = target_file local rel = relative_to(ref_base_dir, abs):gsub("/index%.html$", "/") - return {abs = abs, rel = rel, full = (site_url .. abs)} + return { abs = abs, rel = rel, full = (site_url .. abs) } end function resolve_layout(layout) if layout then layout = pandoc.utils.stringify(layout) - return {id = layout, ["is_" .. layout] = true} + return { id = layout, ["is_" .. layout] = true } end end @@ -117,7 +117,7 @@ function resolve_namespace(namespace) local root = "index" if namespace ~= "" then root = namespace:gsub("^/([^/]*).*$", "%1") end - return {root = {id = root, ["is_" .. root] = true}, full = namespace} + return { root = { id = root, ["is_" .. root] = true }, full = namespace } end function prep_menu(active_id, main_menu) @@ -137,17 +137,22 @@ function prep_menu(active_id, main_menu) end function process_pages(global, pages_by_id) - if not pages_by_id then pages_by_id = {} end + if not pages_by_id then return nil end local pages_list = pandoc.List() - for _, page in pairs(pages_by_id) do - page = process(global, page) - pages_list:insert(page) - end + for _, page in pairs(pages_by_id) do pages_list:insert(process(global, page)) end pages_list:sort(function(p1, p2) - if p1.date then + if p1.position then + if p2.position then + return p1.position < p2.position + else + return true + end + elseif p2.position then + return false + elseif p1.date then if p2.date then return p1.date.yyyy_mm_dd > p2.date.yyyy_mm_dd else @@ -166,7 +171,7 @@ function process_pages(global, pages_by_id) if not data then local l = pandoc.List() l:insert(p) - return {name = pandoc.utils.stringify(p.category.name), pages = l} + return { name = pandoc.utils.stringify(p.category.name), pages = l } else data.pages:insert(p) end @@ -174,11 +179,24 @@ function process_pages(global, pages_by_id) pages_by_category = table_to_list(pages_by_category, false, function(i1, i2) return i1.name < i2.name end) - local pages_data = {all = pages_list, by_id = pages_by_id, by_category = pages_by_category} + local pages_data = { all = pages_list, by_id = pages_by_id, by_category = pages_by_category } return pages_data end +function pages_last_update(all_pages) + local last_update = format_date("1990-01-01") + + for i = 1, #all_pages do + local page = all_pages[i] + if page.last_update and page.last_update.yyyy_mm_dd > last_update.yyyy_mm_dd then + last_update = page.last_update + end + end + + return last_update +end + function process(global, meta) meta.namespace = resolve_namespace(meta.namespace) meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") @@ -186,6 +204,22 @@ function process(global, meta) meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" + if meta.position then meta.position = pandoc.utils.stringify(meta.position) end + + if meta.create_feed then + if meta.file_out:match(".html$") then + meta.feed = { + url = resolve_url(global.site.url, global.file_out, + meta.file_out:gsub(".html$", ".xml")), + } + else + meta.page = { + url = resolve_url(global.site.url, global.file_out, + meta.file_out:gsub(".xml$", ".html")), + } + end + end + if meta.preview then meta.preview = make_absolute(pandoc.utils.stringify(meta.preview), meta.file_out) meta.preview = resolve_url(global.site.url, global.file_out, meta.preview) @@ -193,18 +227,20 @@ function process(global, meta) if meta.date then meta.date = format_date(meta.date) end - if meta.last_update then - meta.last_update = format_date(meta.last_update) - else - meta.last_update = meta.date - end - if meta.menus and meta.menus.main then meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) end meta.pages = process_pages(global, meta.pages) + if meta.last_update then + meta.last_update = format_date(meta.last_update) + elseif meta.date then + meta.last_update = meta.date + elseif meta.pages then + meta.last_update = pages_last_update(meta.pages.all) + end + return meta end diff --git a/templates/base.html b/templates/base.html index 5dc57e2..6c0c4a9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -19,6 +19,10 @@ $endif$ + $if(feed)$ + + $endif$ + $if(namespace.root.is_index)$$else$$title$ – $endif$$site.title$ diff --git a/templates/feed.xml b/templates/feed.xml index a968205..ad665d2 100644 --- a/templates/feed.xml +++ b/templates/feed.xml @@ -1,10 +1,10 @@ - $if(section.is_index)$$else$$title$ – $endif$$site.title$ - - - $pages.last_update.rfc3339$ - $url.full$ + $if(namespace.root.is_index)$$else$$title$ – $endif$$site.title$ + + + $last_update.rfc3339$ + $url.abs$ $for(author)$ $it.name$ @@ -14,33 +14,15 @@ $endfor$ - $for(pages.all_dated)$ - - $it.url.full$ - <![CDATA[$it.title$]]> - $if(it.author)$ - $for(it.author)$ - - $it.name$ - $if(it.email)$ - $it.email$ - $endif$ - - $endfor$ - $else$ - $for(author)$ - - $author.name$ - $if(author.email)$ - $author.email$ - $endif$ - - $endfor$ - $endif$ - - $it.date.rfc3339$ - $it.last_update.rfc3339$ - - - $endfor$ + $if(layout.is_categorized_list)$ + $for(pages.all)$ + $for(it.pages.all)$ + $it:feed_entry()$ + $endfor$ + $endfor$ + $else$ + $for(pages.all)$ + $it:feed_entry()$ + $endfor$ + $endif$ diff --git a/templates/feed_entry.xml b/templates/feed_entry.xml new file mode 100644 index 0000000..f4c5d47 --- /dev/null +++ b/templates/feed_entry.xml @@ -0,0 +1,30 @@ + + $it.url.abs$ + $it.title$ + + $if(it.author)$ + $for(it.author)$ + + $it.name$ + $if(it.email)$ + $it.email$ + $endif$ + + $endfor$ + $else$ + $for(author)$ + + $author.name$ + $if(author.email)$ + $author.email$ + $endif$ + + $endfor$ + $endif$ + $if(it.date)$ + $it.date.rfc3339$ + $endif$ + $if(it.last_update)$ + $it.last_update.rfc3339$ + $endif$ + diff --git a/templates/layouts/categorized_list.html b/templates/layouts/categorized_list.html index 8f39229..6e72194 100644 --- a/templates/layouts/categorized_list.html +++ b/templates/layouts/categorized_list.html @@ -8,28 +8,30 @@ $body$
$for(pages.all)$ -

- $it.title$ -

-
- $for(it.pages.all)$ - -
- $it.title$ -
- $if(pages.all.show_dates)$ - - $endif$ -
- $endfor$ -
+ $if(it.pages)$ +

+ $it.title$ +

+
+ $for(it.pages.all)$ + +
+ $it.title$ +
+ $if(pages.all.show_dates)$ + + $endif$ +
+ $endfor$ +
+ $endif$ $endfor$
-- cgit v1.2.3-54-g00ecf