commit 46bdc5393b4ed237e8de57c2a514274b363bc648
parent 7140b79479ba3c9ab01099f2261b0d7cc639bb58
Author: Hugo Soucy <hs0ucy@users.noreply.github.com>
Date: Tue, 2 Oct 2018 15:51:55 -0400
Merge pull request #2 from hs0ucy/feed_refactoring
Feed refactoring
Diffstat:
9 files changed, 134 insertions(+), 139 deletions(-)
diff --git a/config.lua b/config.lua
@@ -30,7 +30,13 @@ local config = {
"inspect",
"mimetypes"
}
- }
+ },
+
+ feedtypes = {
+ "atom",
+ "rss2",
+ "json",
+ },
}
return config
diff --git a/ferron.lua b/ferron.lua
@@ -33,7 +33,6 @@ Ferron.init = {
Ferron.build = {
page.makepage,
list.makelist,
- feed.makefeed,
link.makeshorts,
link.makerewritemap,
static.move
diff --git a/ferron/feed.lua b/ferron/feed.lua
@@ -1,54 +1,31 @@
--
+local config = require "config"
local path = require "path"
local fileutils = require "ferron.utilities.file-utils"
local tableutils = require "ferron.utilities.table-utils"
local templateutils = require "ferron.utilities.template-utils"
local feed = {}
-function feed.makefeed()
- local feed_tb = {}
- local feedtemplate = path.isfile(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/feed.mustache")
- local feedrsstemplate = path.isfile(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/rss2.mustache")
+function feed.makefeed(entries, destination)
+ local feedtypes = (not Ferron.site.siteconfig.feedtypes and config.feedtypes or Ferron.site.siteconfig.feedtypes)
local feedpartials = path.isdir(Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/partials")
- local feedfile = Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/feed.atom.xml"
- local feedrssfile = Ferron.site.path .. Ferron.site.siteconfig.paths.html .. "/feed.rss.xml"
- print("§ Make an ATOM feed with all the pages of the site ...")
-
- feed_tb["site"] = Ferron.site.siteconfig
- feed_tb["entries"] = {}
-
- for k, v in tableutils.sortdescendingpairs(Ferron.site.pagestable) do
- table.insert(feed_tb["entries"], v)
- end
-
- feed_tb["lastupdate"] = feed_tb["entries"][1].updated
-
- -- Build the Atom XML file
- fileutils.pushfilecontent(
- feedfile,
- templateutils.processmustache(
- fileutils.pullfilecontent(feedtemplate),
- feedpartials,
- feed_tb
- )
- )
-
- -- Build the RSS 2 XML file
- fileutils.pushfilecontent(
- feedrssfile,
- templateutils.processmustache(
- fileutils.pullfilecontent(feedrsstemplate),
- feedpartials,
- feed_tb
- )
- )
-
- if not path.isfile(feedfile) then
- print(" !! /feed.atom.xml - error!")
+ for i, v in ipairs(feedtypes) do
+ local feedtemplate = Ferron.site.path .. Ferron.site.siteconfig.paths.templates .. "/feed/" .. v .. ".mustache"
+
+ if path.isfile(feedtemplate) then
+ fileutils.pushfilecontent(
+ destination .. "/feed." .. v,
+ templateutils.processmustache(
+ fileutils.pullfilecontent(feedtemplate),
+ feedpartials,
+ entries
+ )
+ )
+ else
+ print("*** Warning! The `" .. feedtemplate .. "` template is missing!")
+ end
end
-
- print("==========")
end
return feed
diff --git a/ferron/list.lua b/ferron/list.lua
@@ -5,6 +5,7 @@ local path = require "path"
local fileutils = require "ferron.utilities.file-utils"
local tableutils = require "ferron.utilities.table-utils"
local templateutils = require "ferron.utilities.template-utils"
+local feed = require "ferron.feed"
local static = require "ferron.static"
local list = {}
@@ -37,7 +38,7 @@ local function setentries(directory, list_mt)
path.each(
directory .. "/*.md",
function(entry)
- if path.basename(entry) ~= "index.md" or entry == contentpath .. "/index.md" then
+ if path.basename(entry) ~= "index.md" then
local entry_metadatas = json.decode(fileutils.pullfilecontent(fileutils.removeextension(entry) .. ".json"))
local entry_key = entry_metadatas.date .. "|" .. entry_metadatas.datetime .. "|" .. fileutils.getrelpath(fileutils.removeextension(entry))
@@ -63,56 +64,60 @@ function list.makelist()
path.each(
contentpath .. "/index.md",
function(list)
- if list ~= contentpath .. "/index.md" then
- local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(path.dirname(list)))
- local list_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(list) .. ".json"))
- local list_conf_mt = setmetatable({}, { __index = list_conf })
-
- print("§ Make a list page for the `" .. fileutils.getrelpath(path.dirname(list)) .. "` subdirectory ...")
-
- -- Convert the markdown file to HTML
- list_conf_mt.content = markdown(fileutils.pullfilecontent(list))
- -- Set a dynamic permalink
- list_conf_mt.permalink = Ferron.site.siteconfig.baseurl .. path.dirname(fileutils.getrelpath(fileutils.removeextension(list)))
- -- Import site configuration in the metatable
- list_conf_mt["site"] = Ferron.site.siteconfig
- -- Set a table for the list of entries
- list_conf_mt["entries"] = {}
-
- -- Set and get entries of the list
- setentries(path.dirname(list), list_conf_mt)
-
- if not path.isdir(list_htmlpath) then
- fileutils.mkdir(list_htmlpath)
- end
-
- static.dispatch(list)
-
- -- Build the HTML file
- fileutils.pushfilecontent(
- list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html",
- templateutils.processmustache(
- fileutils.pullfilecontent(templatespath .. "/" .. (list_conf.template ~= nil and list_conf.template or "default-index") .. ".mustache"),
- templatespath .. "/partials",
- list_conf_mt
- )
- )
-
- if not path.isfile(list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html") then
- print(" !! " .. fileutils.getrelpath(fileutils.removeextension(list)) .. ".html - error!")
- end
+ local list_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(path.dirname(list)))
+ local list_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(list) .. ".json"))
+ local list_conf_mt = setmetatable({}, { __index = list_conf })
+
+ print("§ Make a list page for the `" .. fileutils.getrelpath(path.dirname(list)) .. "` subdirectory ...")
+
+ -- Convert the markdown file to HTML
+ list_conf_mt.content = markdown(fileutils.pullfilecontent(list))
+ -- Set a dynamic permalink
+ list_conf_mt.permalink = Ferron.site.siteconfig.baseurl .. path.dirname(fileutils.getrelpath(fileutils.removeextension(list)))
+ -- Import site configuration in the metatable
+ list_conf_mt["site"] = Ferron.site.siteconfig
+ -- Set a table for the list of entries
+ list_conf_mt["entries"] = {}
+
+ -- Set and get entries of the list
+ setentries(path.dirname(list), list_conf_mt)
+
+ if not path.isdir(list_htmlpath) then
+ fileutils.mkdir(list_htmlpath)
+ end
- print("==========")
+ -- Create syndication feeds for each list
+ if list_conf.feed ~= false then
+ feed.makefeed(list_conf_mt, list_htmlpath)
+ end
- -- Update the JSON file data
- list_conf["entries"] = nil
- list_conf["site"] = nil
+ -- Move static files in the public HTML folder
+ static.dispatch(list)
- fileutils.pushfilecontent(
- fileutils.removeextension(list) .. ".json",
- json.encode(list_conf, {indent = true, keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","template","title","updated"}})
+ -- Build the HTML file
+ fileutils.pushfilecontent(
+ list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html",
+ templateutils.processmustache(
+ fileutils.pullfilecontent(templatespath .. "/" .. (list_conf.template ~= nil and list_conf.template or "default-index") .. ".mustache"),
+ templatespath .. "/partials",
+ list_conf_mt
)
+ )
+
+ if not path.isfile(list_htmlpath .. "/" .. fileutils.getplainname(list) .. ".html") then
+ print(" !! " .. fileutils.getrelpath(fileutils.removeextension(list)) .. ".html - error!")
end
+
+ print("==========")
+
+ -- Update the JSON file data
+ list_conf["entries"] = nil
+ list_conf["site"] = nil
+
+ fileutils.pushfilecontent(
+ fileutils.removeextension(list) .. ".json",
+ json.encode(list_conf, {indent = true, keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","template","title","updated"}})
+ )
end,
{
delay = true; -- use snapshot of directory
diff --git a/ferron/page.lua b/ferron/page.lua
@@ -20,7 +20,7 @@ function page.makepage()
path.each(
contentpath .. "/*.md",
function(page)
- if path.basename(page) ~= "index.md" or page == contentpath .. "/index.md" then
+ if path.basename(page) ~= "index.md" then
local page_htmlpath = fileutils.sethtmlpath(fileutils.getrelpath(path.dirname(page)))
local page_conf = json.decode(fileutils.pullfilecontent(fileutils.removeextension(page) .. ".json"))
local page_conf_mt = setmetatable({}, { __index = page_conf })
@@ -45,7 +45,7 @@ function page.makepage()
Ferron.site.pagestable[page_key] = page_conf_mt
- -- If the ancestors of the page dosen't exists make it
+ -- If the ancestors of the page dosen't exists make it
if not path.isdir(page_htmlpath) then
fileutils.mkdir(page_htmlpath)
end
@@ -66,14 +66,14 @@ function page.makepage()
-- Update the JSON file data
fileutils.pushfilecontent(
- fileutils.removeextension(page) .. ".json",
- json.encode(
- page_conf, {
- indent = true,
- keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","shortlink","template","title"}
- }
- )
- )
+ fileutils.removeextension(page) .. ".json",
+ json.encode(
+ page_conf, {
+ indent = true,
+ keyorder = {"bridgy","cite","citeurl","content","date","datetime","description","id","keywords","permalink","shortlink","template","title"}
+ }
+ )
+ )
end
end,
{
diff --git a/sites/ferron-ssg.tld/templates/feed.mustache b/sites/ferron-ssg.tld/templates/feed.mustache
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<feed xmlns="http://www.w3.org/2005/Atom">
- <title>Atom Feed of {{{ site.domainname }}}</title>
- <subtitle>{{{ site.description }}}</subtitle>
- <id>tag:{{{ site.domainname }}},2014-01-01:{{{ site.author.email }}}</id>
- <link href="{{{ site.url }}}/feed.atom.xml" rel="self" type="application/atom+xml"/>
- <link href="{{{ site.url }}}" rel="alternate" />
- <author>
- <name>{{{ site.author.name }}}</name>
- <email>{{{ site.author.email }}}</email>
- <uri>{{{ site.author.uri }}}</uri>
- </author>
-
- {{# entries }}
- <entry>
- <title>{{{ title }}}</title>
- <id>{{{ id }}}</id>
- <link href="{{{ permalink }}}" hreflang="{{{ site.language }}}" rel="alternate" />
- <updated>{{{ date }}}T{{{ datetime }}}Z</updated>
- </entry>
- {{/ entries }}
-</feed>
diff --git a/sites/ferron-ssg.tld/templates/feed/atom.mustache b/sites/ferron-ssg.tld/templates/feed/atom.mustache
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>Flux Atom de {{{ site.domainname }}}</title>
+ <subtitle>{{{ site.metas.description }}}</subtitle>
+ <id>tag:{{{ site.domainname }}},{{{ site.created }}}:{{{ site.author.nickname }}}</id>
+ <link href="{{{ site.url }}}/feed.atom.xml" rel="self" type="application/atom+xml"/>
+ <!-- PubSubHubbub Discovery -->
+ <link href="https://bridgy-fed.superfeedr.com/" rel="hub" />
+ <link href="https://pubsubhubbub.superfeedr.com" rel="hub" />
+ <!-- End Of PubSubHubbub Discovery -->
+ <link href="{{{ site.url }}}" rel="alternate" />
+ <updated>{{{ lastupdate }}}Z</updated>
+ <author>
+ <name>{{{ site.author.name }}}</name>
+ <email>{{{ site.author.email }}}</email>
+ <uri>{{{ site.author.uri }}}</uri>
+ </author>
+
+ {{# entries }}
+ <entry>
+ <title>{{{ title }}}</title>
+ <id>{{{ id }}}</id>
+ <link href="{{{ permalink }}}" hreflang="{{{ site.language }}}" rel="alternate" />
+ <updated>{{ updated }}Z</updated>
+ <content type="html" xml:base="{{{ permalink }}}">
+ {{ content }}
+ </content>
+ </entry>
+ {{/ entries }}
+</feed>
diff --git a/sites/ferron-ssg.tld/templates/feed/rss2.mustache b/sites/ferron-ssg.tld/templates/feed/rss2.mustache
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0">
+ <channel>
+ <title>Flux RSS 2 de {{{ site.domainname }}}</title>
+ <description>{{{ site.metas.description }}}</description>
+ <lastBuildDate>{{{ lastupdate }}}Z</lastBuildDate>
+ <link>{{{ site.url }}}</link>
+
+ {{# entries }}
+ <item>
+ <title></title>
+ <description>{{ content }}</description>
+ <pubDate>{{ updated }}Z</pubDate>
+ <link>{{{ permalink }}}</link>
+ </item>
+ {{/ entries }}
+ </channel>
+</rss>
diff --git a/sites/ferron-ssg.tld/templates/rss2.mustache b/sites/ferron-ssg.tld/templates/rss2.mustache
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<rss version="2.0">
- <channel>
- <title>RSS Feed of {{{ site.domainname }}}</title>
- <description>{{{ site.metas.description }}}</description>
- <lastBuildDate>{{{ lastupdate }}}Z</lastBuildDate>
- <link>{{{ site.url }}}</link>
-
- {{# entries }}
- <item>
- <title>{{{ title }}}</title>
- <description>{{ content }}</description>
- <pubDate>{{ updated }}Z</pubDate>
- <link>{{{ permalink }}}</link>
- </item>
- {{/ entries }}
- </channel>
-</rss>