aboutsummaryrefslogtreecommitdiff
path: root/_extensions/ruc-play/stylish-roles/stylish-roles.lua
blob: 50caf714b3d48024bed23426e1017bf43a0f2cff (plain)
  1. --[[
  2. stylish-roles - provide existence hints for attributes and CrediT roles
  3. as authors[*].metadata.credit[role], by-author[*].metadata.credit[role],
  4. some-author-has[*].credit[role] and some-author-has.attributes[attribute].
  5. Copyright: © 2024 Jonas Smedegaard <dr@jones.dk
  6. License: MIT – see LICENSE file for details
  7. ]]
  8. function Meta(meta)
  9. local attributes = {"corresponding", "equal-contributor"}
  10. for _, author in ipairs(meta.authors) do
  11. if author.roles then
  12. local _by = meta["by-author"][tonumber(author.number)]
  13. local _some = meta["some-author-has"]
  14. for _, role in ipairs(author.roles) do
  15. if role["vocab-term"] then
  16. -- create if missing
  17. author.metadata.credit = author.metadata.credit or {}
  18. _by.metadata.credit = _by.metadata.credit or {}
  19. meta["some-author-has"] = meta["some-author-has"] or {}
  20. meta["some-author-has"].credit = meta["some-author-has"].credit or {}
  21. author.metadata.credit[role["vocab-term"]] = true
  22. _by.metadata.credit[role["vocab-term"]] = true
  23. meta["some-author-has"].credit[role["vocab-term"]] = true
  24. -- debugging aid
  25. --error(pandoc.utils.stringify(author.name.literal)
  26. -- .. " does " .. role["vocab-term"] .. ".")
  27. end
  28. end
  29. for _, attr in ipairs(attributes) do
  30. if author.attributes and author.attributes[attr] then
  31. -- create if missing
  32. meta["some-author-has"].attributes = meta["some-author-has"].attributes or {}
  33. meta["some-author-has"].attributes[attr] = true
  34. end
  35. end
  36. end
  37. end
  38. -- debugging aid
  39. --quarto.utils.dump(meta)
  40. --quarto.utils.dump(meta["authors"])
  41. --quarto.utils.dump(meta["by-author"])
  42. --quarto.utils.dump(meta["some-author-has"])
  43. return meta
  44. end