From c06fecec4c4c8c4cced90272fb09a9eec29e300b Mon Sep 17 00:00:00 2001 From: Sven Vogel Date: Mon, 8 Jul 2024 14:25:56 +0200 Subject: [PATCH] changed: read glossary from YAML file --- src/glossary.typ | 60 +++++++++++++++++++++++++++++++++++++++++++ src/lib.typ | 3 ++- template/glossary.typ | 17 ------------ template/glossary.yml | 11 ++++++++ template/main.typ | 3 +-- 5 files changed, 74 insertions(+), 20 deletions(-) create mode 100644 src/glossary.typ delete mode 100644 template/glossary.typ create mode 100644 template/glossary.yml diff --git a/src/glossary.typ b/src/glossary.typ new file mode 100644 index 0000000..0439a5c --- /dev/null +++ b/src/glossary.typ @@ -0,0 +1,60 @@ + +// .--------------------------------------------------------------------------. +// | Glossary Utilities | +// '--------------------------------------------------------------------------' + +// Author: Sven Vogel +// Edited: 08.07.2024 +// License: MIT + +#let glossary(entries) = { + + assert( + type(entries) == dictionary, + message: "The glossary is not a dictionary", + ) + + for (k, v) in entries.pairs() { + assert( + type(v) == dictionary, + message: "The glossary entry `" + k + "` is not a dictionary") + + for key in v.keys() { + assert( + key in ("short", "long", "desc", "group"), + message: "Found unexpected key `" + key + "` in glossary entry `" + k) + } + + assert( + type(v.short) == str, + message: "The short form of glossary entry `" + k + "` is not a string") + + if "long" in v { + assert( + type(v.long) == str, + message: "The long form of glossary entry `" + k + "` is not a string") + } + + if "desc" in v { + assert( + type(v.desc) == str, + message: "The description of glossary entry `" + k + "` is not a string") + } + + if "group" in v { + assert( + type(v.group) == str, + message: "The optional group of glossary entry `" + k + "` is not a string") + } else { + panic("Missing group for glossary entry: `" + k + "`") + } + } + + return entries.pairs().map(((key, entry)) => ( + key: key, + short: eval(entry.short, mode: "markup"), + long: eval(entry.at("long", default: ""), mode: "markup"), + desc: eval(entry.at("desc", default: ""), mode: "markup"), + group: entry.at("group", default: "") + )) +} \ No newline at end of file diff --git a/src/lib.typ b/src/lib.typ index b61dcb8..905e383 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -10,6 +10,7 @@ #import "conf.typ": validate-config #import "branding.typ": * #import "style.typ": global_styled_doc, content_styled, end_styled + #import "glossary.typ": glossary #import "pages/titlepage.typ": new_title_page #import "pages/declaration-of-authorship.typ": new_declaration_of_authorship #import "pages/confidentiality-statement.typ": new_confidentiality_statement_page @@ -67,7 +68,7 @@ print-glossary( disable-back-references: true, enable-group-pagebreak: true, - config.thesis.glossary) + glossary(config.thesis.glossary)) pagebreak(weak: true) } diff --git a/template/glossary.typ b/template/glossary.typ deleted file mode 100644 index 9afb9c1..0000000 --- a/template/glossary.typ +++ /dev/null @@ -1,17 +0,0 @@ - -#let glossary = ( - ( - key: "oidc", - short: "OIDC", - long: "OpenID Connect", - desc: [OpenID is an open standard and decentralized authentication protocol promoted by the non-profit #link("https://en.wikipedia.org/wiki/OpenID#OpenID_Foundation")[OpenID Foundation].], - group: "Akronyme" - ), - ( - key: "potato", - short: "EDDI/EDDP", - plural: "potatoes", - desc: [#lorem(10)], - group: "Akronyme" - ) -) diff --git a/template/glossary.yml b/template/glossary.yml new file mode 100644 index 0000000..83548c7 --- /dev/null +++ b/template/glossary.yml @@ -0,0 +1,11 @@ + +oidc: + short: OIDC + long: OpenID Connect + desc: "OpenID is an open standard and decentralized authentication protocol promoted by the non-profit #link(\"https://en.wikipedia.org/wiki/OpenID#OpenID_Foundation\")[OpenID Foundation]." + group: Acronym + +potato: + short: potato + desc: "#lorem(50)" + group: Acronym \ No newline at end of file diff --git a/template/main.typ b/template/main.typ index 41ab1de..d4c5259 100644 --- a/template/main.typ +++ b/template/main.typ @@ -1,6 +1,5 @@ #import "../src/lib.typ": * -#import "glossary.typ": glossary #import "abstract.typ": abstract, summary #show: dhbw-template.with(( @@ -27,7 +26,7 @@ preface: include "preface.typ", keywords: ( "IT", "other stuff" ), bibliography: bibliography("refs.bib"), - glossary: glossary, + glossary: yaml("glossary.yml"), appendices: include "appendix.typ"))) #import "@preview/wrap-it:0.1.0": wrap-content