|
1 | | -local function tag_strings (row) |
2 | | - return row[2][1].content:walk{ |
3 | | - Space = function (_) return {pandoc.Str',', pandoc.Space()} end, |
4 | | - Str = function (str) return pandoc.Code(str.text) end, |
5 | | - } |
| 1 | +local io = require 'io' |
| 2 | +local pandoc = require 'pandoc' |
| 3 | +local utils = require 'pandoc.utils' |
| 4 | +local stringify = utils.stringify |
| 5 | + |
| 6 | +local function tag_strings (tags) |
| 7 | + local result = pandoc.List{} |
| 8 | + |
| 9 | + for i = 1, #tags do |
| 10 | + result:insert(pandoc.Code(stringify(tags[i]))) |
| 11 | + if i < #tags then |
| 12 | + result:extend{pandoc.Str ',', pandoc.Space()} |
| 13 | + end |
| 14 | + end |
| 15 | + return result |
6 | 16 | end |
7 | 17 | function CodeBlock (cb) |
8 | 18 | if not cb.classes:includes 'supported-tags' then |
9 | 19 | return nil |
10 | 20 | end |
11 | 21 |
|
12 | | - -- get simple table from file |
13 | | - local fh = io.open 'versions.md' |
14 | | - local versions = pandoc.utils.to_simple_table( |
15 | | - pandoc.read(fh:read 'a').blocks[1] |
16 | | - ) |
| 22 | + -- get YAML as metadata from file |
| 23 | + local fh = io.open 'config.yaml' |
| 24 | + local config = pandoc.read(fh:read 'a').meta |
| 25 | + |
| 26 | + local release_numbers = pandoc.List{} |
| 27 | + for version in pairs(config.release) do |
| 28 | + release_numbers:insert(version) |
| 29 | + end |
| 30 | + release_numbers:sort(function (a, b) |
| 31 | + if a == 'main' then |
| 32 | + return true |
| 33 | + elseif b == 'main' then |
| 34 | + return false |
| 35 | + end |
| 36 | + local _, av = pcall(pandoc.types.Version, a) |
| 37 | + local _, bv = pcall(pandoc.types.Version, b) |
| 38 | + return av > bv |
| 39 | + end) |
17 | 40 |
|
18 | 41 | local result = pandoc.List() |
19 | | - for i, row in ipairs(versions.rows) do |
20 | | - local tags = tag_strings(row) |
| 42 | + for release_number in release_numbers:iter() do |
| 43 | + local release = config.release[release_number] |
| 44 | + local tags = tag_strings(release['version-tags']) |
21 | 45 | result:insert{pandoc.Plain(tags)} |
22 | 46 | end |
23 | 47 | return pandoc.BulletList(result) |
|
0 commit comments