hscc

Soure code of <https://hugo.soucy.cc>.
git clone git://soucy.cc/hscc.git
Log | Files | Refs

commit 254a2aa7d5c3b48941589fc0f3e241e1060e0974
parent 54fc7991bd6650938d2688d8164a660d913f5b96
Author: Hugo Soucy <hugo@soucy.cc>
Date:   Mon, 27 Sep 2021 18:54:21 -0400

Add a script to create a tag page

Diffstat:
Darchetypes/tag.lua.mustache | 7-------
Darchetypes/tag.md.mustache | 1-
Aarchetypes/tags.html | 14++++++++++++++
Mbin/tags | 44+++++++++++++++++++++++++++++++++-----------
4 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/archetypes/tag.lua.mustache b/archetypes/tag.lua.mustache @@ -1,7 +0,0 @@ -return { -title = "{{ title }}", -url = "{{{ url }}}", -date = "{{ date }}", -datetime = "{{ datetime }}", -posttype = "", -} diff --git a/archetypes/tag.md.mustache b/archetypes/tag.md.mustache @@ -1 +0,0 @@ -{{{ title }}} diff --git a/archetypes/tags.html b/archetypes/tags.html @@ -0,0 +1,14 @@ +<h1><%= title -%></h1> + +<dl class="tags"> + <% for tag, tag_table in pairs(tags) do %> + <dt id="<%= tag:gsub("%s+", "-") -%>"><%= tag -%></dt> + <% for _, tb in pairs(tag_table) do %> + <dd> + <a href="<%= tb.rellink -%>"> + <%= tb.title -%> + </a> + </dd> + <% end %> + <% end %> +</dl> diff --git a/bin/tags b/bin/tags @@ -7,21 +7,26 @@ do local dirtree = require 'utils.dirtree' local file = require 'utils.file' local inspect = require 'inspect' - local lfs = require 'lfs' - local lume = require 'utils.lume.lume' - local lustache = require 'lustache' + local etlua = require 'etlua' - local tagstable = {} + local tags_table = {} + local tags_model + local tags_template + local tags_html + local tags_dir -- Insert all the keywords as key of an empty subtable for filepath in dirtree.get('content/') do - if file.is_markdown(filepath) or file.is_html(filepath) then + if file.is_markdown(filepath) + or file.is_html(filepath) + and file.get_metafile(filepath) + then local metafile = file.get_metafile(filepath) if metafile.keywords ~= nil then for _, keyword in pairs(file.get_metafile(filepath).keywords) do if keyword ~= '' then - tagstable[keyword] = {} + tags_table[keyword] = {} end end end @@ -30,25 +35,42 @@ do -- After insert relative links in each keyword's table for filepath in dirtree.get('content/') do - if file.is_markdown(filepath) or file.is_html(filepath) then + if file.is_markdown(filepath) + or file.is_html(filepath) + and file.get_metafile(filepath) + then local metafile = file.get_metafile(filepath) if metafile.keywords ~= nil then for _, keyword in pairs(file.get_metafile(filepath).keywords) do - if tagstable[keyword] then + if tags_table[keyword] then local tagtable = { title = metafile.title, rellink = file.get_rellink(filepath, config.paths.content) } - table.insert(tagstable[keyword], tagtable) + table.insert(tags_table[keyword], tagtable) end end end end end - --print(inspect(tagstable)) + --table.sort(tags_table, function(a, b) return a < b end) + --table.sort(tags_table, function(a, b) return tags_table[a] < tags_table[b] end) - return print(inspect(tagstable)) + -- Set the structure of the data file + tags_model = { + title = 'Mots Cl├ęs', + time_modification = os.date('%Y-%m-%dT%H:%M:%S'), + tags = tags_table + } + + tags_template = etlua.compile(file.read('archetypes/tags.html')) + tags_html = tags_template(tags_model) + tags_dir = 'content/' + + -- Write the HTML in a file + file.write(tags_dir .. 'tg.html', tags_html) + return --print(inspect(tags_table)) end