diff --git a/doc/configuration.toml b/doc/configuration.toml index f62001f..18b6bd0 100644 --- a/doc/configuration.toml +++ b/doc/configuration.toml @@ -41,6 +41,12 @@ tldr = "clipboard-list" todo = "circle-check" warning = "triangle-alert" +[generate] +# The site base URL. If supplied, this will be added to a element in the page metadata. +sitebase = "" +# The site title. If supplied, this will be included in page metadata and used to formulate the default title. +sitetitle = "" + [templates] # The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl". directory = ".dragonglass.tmpl" diff --git a/doc/template-vars.txt b/doc/template-vars.txt index 1c815a1..bc7e50b 100644 --- a/doc/template-vars.txt +++ b/doc/template-vars.txt @@ -17,6 +17,12 @@ dragonglass_version python_version The version number of Python that's running dragonglass. +site_base: + If defined, contains the site base URL. + +site_title: + If defined, contains the site title. + tags: A list of all tags the page being rendered has, in sorted order. diff --git a/src/dragonglass/config.py b/src/dragonglass/config.py index fe6235e..65dc693 100644 --- a/src/dragonglass/config.py +++ b/src/dragonglass/config.py @@ -106,6 +106,18 @@ class Context: links_section = self.config.get("links", {}) return links_section.get("relative", False) + @property + def site_base(self) -> str | None: + """Returns the configured site base URL.""" + generate_section = self.config.get("generate", {}) + return generate_section.get("sitebase", None) + + @property + def site_title(self) -> str | None: + """Returns the configured site title.""" + generate_section = self.config.get("generate", {}) + return generate_section.get("sitetitle", None) + @property def url_prefix(self) -> str: """Returns the configured URL prefix for all URLs generated for internal links.""" diff --git a/src/dragonglass/template.py b/src/dragonglass/template.py index c67d866..4d756e0 100644 --- a/src/dragonglass/template.py +++ b/src/dragonglass/template.py @@ -15,7 +15,15 @@ from ._version import __version__ """The default template used to render Markdown data.""" DEFAULT_TEMPLATE = """ - {{ title }} + {% if site_title is defined %} + {{ title }} - {{ site_title }} + + {% else %} + {{ title }} + {% endif %} + {% if site_base is defined %} + + {% endif %} {% if description|length > 0 %} @@ -99,6 +107,14 @@ def template_vars(node: SourceNode, ctxt: Context) -> dict[str, Any]: tvars["dragonglass_version"] = __version__ tvars["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}" + # Add values derived from configuration. + t = ctxt.site_base + if t: + tvars["site_base"] = t + t = ctxt.site_title + if t: + tvars["site_title"] = t + # Compute backlinks for this node. Don't include nodes that aren't published. backlinks = sorted([n for n in node.backlinks if n.publish], key=lambda n: n.page_title) tvars['backlinks'] = [{'title': n.page_title,