cram tags for files and headings in to the Atom Feed Generator

main
Ryan Rix 2022-12-28 12:37:27 -08:00
parent 6691e0a646
commit b400ddcfd5
3 changed files with 100 additions and 3 deletions

View File

@ -93,7 +93,19 @@ I had some real trouble figuring out how to get Pandoc to spit out [[https://val
local utils = require 'pandoc.utils'
local entries = {}
local vars = {}
local keywords = {}
local variables = {}
set_meta_from_raw = function (raw)
-- Don't do anything unless the block contains *org* markup.
if raw.format ~= 'org' then return nil end
-- extract variable name and value
local name, value = raw.text:match '#%+(%w+):%s*(.+)$'
if name and value then
variables[name] = value
end
end
-- thanks random github users https://gist.github.com/zwh8800/9b0442efadc97408ffff248bc8573064
local epoch = os.time{year=1970, month=1, day=1, hour=0}
@ -105,10 +117,30 @@ end
rfc3339ish = "%Y-%m-%dT%TZ"
set_entries_and_date = function(m)
for name, value in pairs(variables) do
m[name] = value
end
if m["FILETAGS"] ~= nil then
kw_str = utils.stringify(m["FILETAGS"])
kw_str:gsub("([^:]*)", function(tag)
if tag ~= "" then
table.insert(keywords, tag)
end
end)
end
if m["keywords"] ~= nil then
kw_str = utils.stringify(m["keywords"])
kw_str:gsub("([^, ]*)", function(tag)
if tag ~= "" then
table.insert(keywords, tag)
end
end)
end
if m.date == nil then
m.date = os.date(rfc3339ish) --current time in iso8601/rfc3339
end
m.entries = entries
m.keywords = keywords
return m
end
@ -121,8 +153,14 @@ extract_entries = function (blocks)
header.attributes.pubdate = nil
header.attributes.number = nil
div.attributes.number = nil
header_tags = {}
title_subbed = utils.stringify(header.content)
for k,v in pairs(header.content) do
if v.tag == "Span" and v.attributes["tag-name"] ~= nil then
table.insert(header_tags, v.attributes["tag-name"])
end
end
entry = {
content=div,
@ -130,6 +168,9 @@ extract_entries = function (blocks)
rel=div.attributes.id,
pubdate=os.date(rfc3339ish, parse_org_date(div.attributes.pubdate))
}
if #header_tags > 0 then
entry["categories"] = header_tags
end
table.insert(entries, entry)
end
end
@ -138,6 +179,7 @@ end
return {
{
RawBlock = set_meta_from_raw,
Blocks = extract_entries,
Meta = set_entries_and_date
}
@ -170,6 +212,12 @@ $for(entries)$
<link href="{ARCOLOGY_FEED_PAGE}#${it.rel}"/>
<id>{ARCOLOGY_FEED_PAGE}#${it.rel}</id>
<updated>${it.pubdate}</updated>
$for(it.categories)$
<category term="${it}" />
$endfor$
$for(keywords)$
<category term="${it}" />
$endfor$
<summary type="html">${it.content}</summary>
</entry>
$endfor$
@ -183,7 +231,8 @@ And this can be confirmed to work with e.g. [[id:20220523T154158.992219][The Lio
pandoc ../thelionsrear_updates.org --lua-filter=arcology/pandoc/make-atom.lua --template=arcology/pandoc/atom.xml -s
#+end_src
#+results:
Notice that it still has to go through the process of [[id:arcology/arroyo/hydrate][Rewriting and Hydrating]] that the HTML docs have to go through so that links and whatnot work. This is handled in =hydrate_feed= above.
* Listing the Arcology Feeds
Since the feeds exist in the [[id:arroyo/system-cache][Arroyo Cache]] K/V/F store, they can be extracted to shove in to the <head> for example.

View File

@ -19,6 +19,12 @@ $for(entries)$
<link href="{ARCOLOGY_FEED_PAGE}#${it.rel}"/>
<id>{ARCOLOGY_FEED_PAGE}#${it.rel}</id>
<updated>${it.pubdate}</updated>
$for(it.categories)$
<category term="${it}" />
$endfor$
$for(keywords)$
<category term="${it}" />
$endfor$
<summary type="html">${it.content}</summary>
</entry>
$endfor$

View File

@ -1,7 +1,19 @@
local utils = require 'pandoc.utils'
local entries = {}
local vars = {}
local keywords = {}
local variables = {}
set_meta_from_raw = function (raw)
-- Don't do anything unless the block contains *org* markup.
if raw.format ~= 'org' then return nil end
-- extract variable name and value
local name, value = raw.text:match '#%+(%w+):%s*(.+)$'
if name and value then
variables[name] = value
end
end
-- thanks random github users https://gist.github.com/zwh8800/9b0442efadc97408ffff248bc8573064
local epoch = os.time{year=1970, month=1, day=1, hour=0}
@ -13,10 +25,30 @@ end
rfc3339ish = "%Y-%m-%dT%TZ"
set_entries_and_date = function(m)
for name, value in pairs(variables) do
m[name] = value
end
if m["FILETAGS"] ~= nil then
kw_str = utils.stringify(m["FILETAGS"])
kw_str:gsub("([^:]*)", function(tag)
if tag ~= "" then
table.insert(keywords, tag)
end
end)
end
if m["keywords"] ~= nil then
kw_str = utils.stringify(m["keywords"])
kw_str:gsub("([^, ]*)", function(tag)
if tag ~= "" then
table.insert(keywords, tag)
end
end)
end
if m.date == nil then
m.date = os.date(rfc3339ish) --current time in iso8601/rfc3339
end
m.entries = entries
m.keywords = keywords
return m
end
@ -29,8 +61,14 @@ extract_entries = function (blocks)
header.attributes.pubdate = nil
header.attributes.number = nil
div.attributes.number = nil
header_tags = {}
title_subbed = utils.stringify(header.content)
for k,v in pairs(header.content) do
if v.tag == "Span" and v.attributes["tag-name"] ~= nil then
table.insert(header_tags, v.attributes["tag-name"])
end
end
entry = {
content=div,
@ -38,6 +76,9 @@ extract_entries = function (blocks)
rel=div.attributes.id,
pubdate=os.date(rfc3339ish, parse_org_date(div.attributes.pubdate))
}
if #header_tags > 0 then
entry["categories"] = header_tags
end
table.insert(entries, entry)
end
end
@ -46,6 +87,7 @@ end
return {
{
RawBlock = set_meta_from_raw,
Blocks = extract_entries,
Meta = set_entries_and_date
}