site

files for beauhilton.com
git clone https://git.beauhilton.com/site.git
Log | Files | Refs

atom.lua (2417B)


      1 -- Atom feed generator
      2 -- Still somewhat experimental -- do not steal for your site just yet
      3 
      4 Plugin.require_version("2.2.0")
      5 
      6 data = config
      7 
      8 date_input_formats = soupault_config["index"]["date_formats"]
      9 
     10 feed_file = config["feed_file"]
     11 
     12 data["site_url"] = soupault_config["custom_options"]["site_url"]
     13 data["feed_id"] = Sys.join_path(soupault_config["custom_options"]["site_url"], feed_file)
     14 
     15 data["soupault_version"] = Plugin.soupault_version()
     16 
     17 
     18 function in_section(entry)
     19   return (entry["nav_path"][1] == config["use_section"])
     20 end
     21 
     22 entries = {}
     23 
     24 -- Original, unfiltered entries inded
     25 local n = 1
     26 
     27 -- Index of the new array of entries we are building
     28 local m = 1
     29 
     30 local count = size(site_index)
     31 while (n <= count) do
     32   entry = site_index[n]
     33   if in_section(entry) then
     34     if entry["date"] then
     35       entry["date"] = Date.reformat(entry["date"], date_input_formats, "%Y-%m-%dT%H:%M:%S%:z")
     36     end
     37     entries[m] = entry
     38     m = m + 1
     39 
     40     -- Remove unwanted elements (e.g. footnotes) from the excerpt
     41     local excerpt = HTML.parse(entry["excerpt"])
     42     Table.iter_values(HTML.delete, HTML.select_all_of(excerpt, config["delete_elements"]))
     43     entry["excerpt"] = tostring(excerpt)
     44   end
     45   n = n + 1
     46 end
     47 
     48 if (soupault_config["index"]["sort_descending"] or
     49     (not Table.has_key(soupault_config["index"], "sort_descending")))
     50 then
     51   data["feed_last_updated"] = entries[1]["date"]
     52 else
     53   data["feed_last_updated"] = entries[size(entries)]["date"]
     54 end
     55 
     56 data["entries"] = entries
     57 
     58 feed_template = [[
     59 {%- autoescape false -%}
     60 <?xml version='1.0' encoding='UTF-8'?>
     61 <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
     62   <id>{{feed_id}}</id>
     63   <title>{{feed_title}}</title>
     64   <updated>{{feed_last_updated}}</updated>
     65   <author>
     66     <name>{{feed_author}}</name>
     67     <email>{{feed_author_email}}</email>
     68   </author>
     69   <generator uri="https://soupault.app" version="{{soupault_version}}">soupault</generator>
     70   <subtitle>{{feed_subtitle}}</subtitle>
     71   {%- for e in entries %}
     72   <entry>
     73     <id>{{site_url}}{{e.url}}</id>
     74     <title>{{e.title}}</title>
     75     <updated>{{e.date}}</updated>
     76     <content type="html">
     77     {{e.excerpt}}
     78     </content>
     79     <link href="{{site_url}}{{e.url}}" rel="alternate"/>
     80   </entry>
     81   {% endfor %}
     82 </feed>
     83 {% endautoescape -%}
     84 ]]
     85 
     86 feed = String.render_template(feed_template, data)
     87 
     88 Sys.write_file(Sys.join_path(soupault_config["settings"]["build_dir"], feed_file), String.trim(feed))