summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-02-11 23:05:40 +0100
committerJonas Smedegaard <dr@jones.dk>2025-02-11 23:05:40 +0100
commit4fb31e49720f5b8b9fd9902fe031c74ee71dc19c (patch)
tree36db07803f81a6f46527e5908da5f33a5bc5ca1b
parent7e8217ca7b9033e98d10e0751d141b377b85cc67 (diff)
add and use extension stylish-roles
-rw-r--r--_extensions/ruc-play/stylish-roles/_extension.yaml6
-rw-r--r--_extensions/ruc-play/stylish-roles/stylish-roles.lua54
-rw-r--r--_quarto.yml3
3 files changed, 63 insertions, 0 deletions
diff --git a/_extensions/ruc-play/stylish-roles/_extension.yaml b/_extensions/ruc-play/stylish-roles/_extension.yaml
new file mode 100644
index 0000000..190c698
--- /dev/null
+++ b/_extensions/ruc-play/stylish-roles/_extension.yaml
@@ -0,0 +1,6 @@
+name: stylish-roles
+author: Jonas Smedegaard
+version: 0.0.1
+contributes:
+ filters:
+ - stylish-roles.lua
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
diff --git a/_quarto.yml b/_quarto.yml
index b96a8af..3a1b3cf 100644
--- a/_quarto.yml
+++ b/_quarto.yml
@@ -9,3 +9,6 @@ website:
href: report.qmd
lang: en-GB
+
+filters:
+ - stylish-roles