diff options
Diffstat (limited to '_extensions/ruc-play/stylish-roles/stylish-roles.lua')
-rw-r--r-- | _extensions/ruc-play/stylish-roles/stylish-roles.lua | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/_extensions/ruc-play/stylish-roles/stylish-roles.lua b/_extensions/ruc-play/stylish-roles/stylish-roles.lua new file mode 100644 index 0000000..50caf71 --- /dev/null +++ b/_extensions/ruc-play/stylish-roles/stylish-roles.lua @@ -0,0 +1,54 @@ +--[[ +stylish-roles - provide existence hints for attributes and CrediT roles +as authors[*].metadata.credit[role], by-author[*].metadata.credit[role], +some-author-has[*].credit[role] and some-author-has.attributes[attribute]. + +Copyright: © 2024 Jonas Smedegaard <dr@jones.dk +License: MIT – see LICENSE file for details +]] +function Meta(meta) + local attributes = {"corresponding", "equal-contributor"} + + for _, author in ipairs(meta.authors) do + if author.roles then + local _by = meta["by-author"][tonumber(author.number)] + local _some = meta["some-author-has"] + + for _, role in ipairs(author.roles) do + if role["vocab-term"] then + + -- create if missing + author.metadata.credit = author.metadata.credit or {} + _by.metadata.credit = _by.metadata.credit or {} + meta["some-author-has"] = meta["some-author-has"] or {} + meta["some-author-has"].credit = meta["some-author-has"].credit or {} + + author.metadata.credit[role["vocab-term"]] = true + _by.metadata.credit[role["vocab-term"]] = true + meta["some-author-has"].credit[role["vocab-term"]] = true + + -- debugging aid + --error(pandoc.utils.stringify(author.name.literal) + -- .. " does " .. role["vocab-term"] .. ".") + end + end + + for _, attr in ipairs(attributes) do + if author.attributes and author.attributes[attr] then + -- create if missing + meta["some-author-has"].attributes = meta["some-author-has"].attributes or {} + + meta["some-author-has"].attributes[attr] = true + end + end + end + end + + -- debugging aid + --quarto.utils.dump(meta) + --quarto.utils.dump(meta["authors"]) + --quarto.utils.dump(meta["by-author"]) + --quarto.utils.dump(meta["some-author-has"]) + + return meta +end |