From 17a9ed12730fb785764b3467e31e969448d3d57e Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Thu, 15 Aug 2024 00:36:59 -0600 Subject: [PATCH] added language (a config value) and character set to default template --- doc/configuration.toml | 2 ++ doc/template-vars.txt | 17 ++++++++++------- src/dragonglass/config.py | 14 ++++++++++---- src/dragonglass/template.py | 4 +++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/doc/configuration.toml b/doc/configuration.toml index 14ad2b0..fc0a516 100644 --- a/doc/configuration.toml +++ b/doc/configuration.toml @@ -56,6 +56,8 @@ stylesheet = "dragonglass.css" [metadata] # If true, use page title as default description. description-title = false +# The language of the site, expressed as a RFC5646 language identifier. +lang = "en" # 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. diff --git a/doc/template-vars.txt b/doc/template-vars.txt index bc7e50b..347f0f3 100644 --- a/doc/template-vars.txt +++ b/doc/template-vars.txt @@ -1,20 +1,23 @@ TEMPLATE VARIABLES PROVIDED BY DRAGONGLASS WHEN RENDERING A DOCUMENT -backlinks +backlinks: A list of pages that link to the page being rendered. Formatted as a list of dicts with two elements, "name" and "link", containing the page title and the link to it, respectively. -default_stylesheet +default_stylesheet: The filename of the default stylesheet which is generated by dragonglass and added to the generated pages. -description +description: The description of this page. May be empty. -dragonglass_version +dragonglass_version: The version number of dragonglass. -python_version +lang: + The configured site language, as a RFC5646 language identifier. + +python_version: The version number of Python that's running dragonglass. site_base: @@ -26,8 +29,8 @@ site_title: tags: A list of all tags the page being rendered has, in sorted order. -text +text: The text of the page being rendered. -title +title: The title of the page being rendered. diff --git a/src/dragonglass/config.py b/src/dragonglass/config.py index f5fae20..bb3a7a1 100644 --- a/src/dragonglass/config.py +++ b/src/dragonglass/config.py @@ -121,14 +121,20 @@ class Context: @property def site_base(self) -> str | None: """Returns the configured site base URL.""" - generate_section = self.config.get("metadata", {}) - return generate_section.get("sitebase", None) + metadata_section = self.config.get("metadata", {}) + return metadata_section.get("sitebase", None) + + @property + def site_language(self) -> str: + """Returns the defayult language for the site.""" + metadata_section = self.config.get("metadata", {}) + return metadata_section.get("lang", "en") @property def site_title(self) -> str | None: """Returns the configured site title.""" - generate_section = self.config.get("metadata", {}) - return generate_section.get("sitetitle", None) + metadata_section = self.config.get("metadata", {}) + return metadata_section.get("sitetitle", None) @property def url_prefix(self) -> str: diff --git a/src/dragonglass/template.py b/src/dragonglass/template.py index 67bf471..8f2c236 100644 --- a/src/dragonglass/template.py +++ b/src/dragonglass/template.py @@ -13,7 +13,7 @@ from ._version import __version__ """The default template used to render Markdown data.""" -DEFAULT_TEMPLATE = """ +DEFAULT_TEMPLATE = """ {% if site_title is defined %} {{ title }} - {{ site_title }} @@ -21,6 +21,7 @@ DEFAULT_TEMPLATE = """ {% else %} {{ title }} {% endif %} + {% if site_base is defined %} {% endif %} @@ -112,6 +113,7 @@ def create_template_environment(ctxt: Context) -> Environment: tenv.globals["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}" # Add values derived from configuration. + tenv.globals["lang"] = ctxt.site_language t = ctxt.site_base if t: tenv.globals["site_base"] = t