~hristoast/hristoast

fdd9c829b13c24fbdd4674e3ceaab37f3591bb60 — Hristos N. Triantafillou 4 months ago 47cae06
Add and use a sitemap plugin

For generating a sitemap.xml file, silly!

I've also used single-quotes for regexes to avoid needing double
escapes.
2 files changed, 57 insertions(+), 3 deletions(-)

A plugins/sitemap.lua
M soupault.conf
A plugins/sitemap.lua => plugins/sitemap.lua +47 -0
@@ 0,0 1,47 @@
--[[
    Sitemap generator, based on dmbaturin's atom generator.

    Requires a "site_url" value as seen below:

    [custom_options]
      site_url = "https://domain.tld"

    Sample widget configuration:

    [widgets.sitemap]
      widget = "sitemap"
      sitemap_file = "sitemap.xml"

]]
Plugin.require_version("2.2.0")

config["site_url"] = soupault_config["custom_options"]["site_url"]

local c = 1
local count = size(site_index)
local file = config["sitemap_file"]
local all_pages = {}

while (c <= count) do
  local p = site_index[c]
  all_pages[c] = p
  c = c + 1
end

config["all_pages"] = all_pages

-- From: https://developers.google.com/search/docs/advanced/sitemaps/build-sitemap
local sitemap_template = [[
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- for p in all_pages -%}
  <url>
    <loc>{{ site_url }}{{ p.url }}</loc>
   <lastmod>{%- if p.date -%}{{ p.date }}{%- else -%}{{ p.git_timestamp }}{%- endif -%}</lastmod>
  </url>
{%- endfor -%}
</urlset>
]]
local sitemap = String.render_template(sitemap_template, config)

Sys.write_file(Sys.join_path(soupault_config["settings"]["build_dir"], file), String.trim(sitemap))

M soupault.conf => soupault.conf +10 -3
@@ 36,23 36,25 @@
[index]
  index = true
  dump_json = "index.json"
  path_regex = "^site\\/(audio\\/covers|blog)\\/(.*)\\.html$"
  path_regex = '^site\/((contact|cv-resume|init\.el|privacy|projects)\.html$|(audio\/covers|blog)\/(.*)\.html$)'
  sort_by = "date"
  date_formats = ["%F"]
  extract_after_widgets = ['last-modified']

[index.fields]
  date = { selector = [ "#post-date", "time" ] }
  excerpt = { selector = [ "#post-excerpt", "p" ] }
  git_timestamp = { selector = [ "#git-timestamp" ] }
  title = { selector = [ "#title", "h1" ] }

[index.views.index]
  path_regex = "^site\\/(audio\\/covers|blog)\\/(.*)\\.html$"
  path_regex = '^site\/(audio\/covers|blog)\/(.*)\.html$'
  index_processor = "scripts/index.py"
  index_selector = "div#blog-index"
  section = "blog"

[index.views.blog]
  path_regex = "^site\\/(audio\\/covers|blog)\\/(.*)\\.html$"
  path_regex = '^site\/(audio\/covers|blog)\/(.*)\.html$'
  index_selector = "div#blog-all"
  index_item_template = """
<div class="entry">


@@ 75,6 77,11 @@
  feed_subtitle = "The personal website of Hristos N. Triantafillou"
  feed_logo = "https://hristos.co/img/slime.png"

[widgets.sitemap]
  widget = "sitemap"
  profile = "live"
  sitemap_file = "sitemap.xml"

[widgets.asciinema-player-css]
  widget = "insert-if"
  html = "<link rel='stylesheet' type='text/css' href='/asciinema/asciinema-player.css' />"