include support for description metadata
This commit is contained in:
parent
bc759bbaf9
commit
72a2ea1ab5
|
@ -1,3 +1,5 @@
|
|||
# In this file, the value of each configuration option is its default.
|
||||
|
||||
[links]
|
||||
# The prefix to apply to all internally-generated URLs. Default is "/".
|
||||
prefix = "/"
|
||||
|
@ -11,3 +13,7 @@ directory = ".dragonglass.tmpl"
|
|||
default = "default.html"
|
||||
# The name of the default stylesheet.
|
||||
stylesheet = "dragonglass.css"
|
||||
|
||||
[metadata]
|
||||
# If true, use page title as default description.
|
||||
description-title = false
|
||||
|
|
|
@ -5,6 +5,10 @@ aliases
|
|||
List of alternative names that can be used to link to a
|
||||
particular page.
|
||||
|
||||
description
|
||||
(Obsidian Publish standard metadata)
|
||||
The description for this page.
|
||||
|
||||
publish
|
||||
(Obsidian Publish standard metadata)
|
||||
If this boolean value is False, the page will not be published.
|
||||
|
|
|
@ -8,6 +8,9 @@ default_stylesheet
|
|||
The filename of the default stylesheet which is generated by dragonglass and added to the
|
||||
generated pages.
|
||||
|
||||
description
|
||||
The description of this page. May be empty.
|
||||
|
||||
dragonglass_version
|
||||
The version number of dragonglass.
|
||||
|
||||
|
|
|
@ -59,11 +59,16 @@ class Context:
|
|||
self._default_template_name = templates_section.get("default", DEFAULT_TEMPLATE_NAME)
|
||||
|
||||
@property
|
||||
def url_prefix(self) -> str:
|
||||
"""Returns the configured URL prefix for all URLs generated for internal links."""
|
||||
links_section = self.config.get("links", {})
|
||||
rc = links_section.get("prefix", "/")
|
||||
return rc if rc.endswith("/") else rc + '/'
|
||||
def default_stylesheet(self) -> str:
|
||||
"""Returns the default stylesheet name."""
|
||||
templates_section = self.config.get("templates", {})
|
||||
return templates_section.get("stylesheet", DEFAULT_STYLESHEET_NAME)
|
||||
|
||||
@property
|
||||
def description_title(self) -> bool:
|
||||
"""Returns ``True`` if we use the title as the default description, ``False`` if not."""
|
||||
metadata_section = self.config.get("metadata", {})
|
||||
return metadata_section.get("description-title", False)
|
||||
|
||||
@property
|
||||
def relative_links(self) -> bool:
|
||||
|
@ -74,10 +79,11 @@ class Context:
|
|||
return links_section.get("relative", False)
|
||||
|
||||
@property
|
||||
def default_stylesheet(self) -> str:
|
||||
"""Returns the default stylesheet name."""
|
||||
templates_section = self.config.get("templates", {})
|
||||
return templates_section.get("stylesheet", DEFAULT_STYLESHEET_NAME)
|
||||
def url_prefix(self) -> str:
|
||||
"""Returns the configured URL prefix for all URLs generated for internal links."""
|
||||
links_section = self.config.get("links", {})
|
||||
rc = links_section.get("prefix", "/")
|
||||
return rc if rc.endswith("/") else rc + '/'
|
||||
|
||||
def get_template_name_for_node(self, node: SourceNode) -> str:
|
||||
"""
|
||||
|
|
|
@ -17,6 +17,10 @@ DEFAULT_TEMPLATE = """<html>
|
|||
<head>
|
||||
<title>{{ title }}</title>
|
||||
<link rel="stylesheet" href="{{ default_stylesheet }}"/>
|
||||
{% if description|length > 0 %}
|
||||
<meta name="description" content="{{ description }}"/>
|
||||
<meta property="og:description" content="{{ description }}"/>
|
||||
{% endif %}
|
||||
<meta name="generator" content="dragonglass/{{ dragonglass_version }} python/{{ python_version }}"/>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -86,6 +90,11 @@ def template_vars(node: SourceNode, ctxt: Context) -> dict[str, Any]:
|
|||
"""
|
||||
tvars = node.make_vars()
|
||||
|
||||
# Patch description.
|
||||
if not tvars["description"] and ctxt.description_title:
|
||||
tvars["description"] = node.page_title
|
||||
|
||||
# Add easily-calculated "global" variables.
|
||||
tvars["dragonglass_version"] = __version__
|
||||
tvars["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}"
|
||||
|
||||
|
|
|
@ -155,7 +155,8 @@ class SourceNode:
|
|||
"""
|
||||
return {
|
||||
"text": self.text,
|
||||
"title": self.page_title
|
||||
"title": self.page_title,
|
||||
"description": self.metadata.get("description", "")
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user