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]
|
[links]
|
||||||
# The prefix to apply to all internally-generated URLs. Default is "/".
|
# The prefix to apply to all internally-generated URLs. Default is "/".
|
||||||
prefix = "/"
|
prefix = "/"
|
||||||
|
@ -11,3 +13,7 @@ directory = ".dragonglass.tmpl"
|
||||||
default = "default.html"
|
default = "default.html"
|
||||||
# The name of the default stylesheet.
|
# The name of the default stylesheet.
|
||||||
stylesheet = "dragonglass.css"
|
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
|
List of alternative names that can be used to link to a
|
||||||
particular page.
|
particular page.
|
||||||
|
|
||||||
|
description
|
||||||
|
(Obsidian Publish standard metadata)
|
||||||
|
The description for this page.
|
||||||
|
|
||||||
publish
|
publish
|
||||||
(Obsidian Publish standard metadata)
|
(Obsidian Publish standard metadata)
|
||||||
If this boolean value is False, the page will not be published.
|
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
|
The filename of the default stylesheet which is generated by dragonglass and added to the
|
||||||
generated pages.
|
generated pages.
|
||||||
|
|
||||||
|
description
|
||||||
|
The description of this page. May be empty.
|
||||||
|
|
||||||
dragonglass_version
|
dragonglass_version
|
||||||
The version number of dragonglass.
|
The version number of dragonglass.
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,16 @@ class Context:
|
||||||
self._default_template_name = templates_section.get("default", DEFAULT_TEMPLATE_NAME)
|
self._default_template_name = templates_section.get("default", DEFAULT_TEMPLATE_NAME)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url_prefix(self) -> str:
|
def default_stylesheet(self) -> str:
|
||||||
"""Returns the configured URL prefix for all URLs generated for internal links."""
|
"""Returns the default stylesheet name."""
|
||||||
links_section = self.config.get("links", {})
|
templates_section = self.config.get("templates", {})
|
||||||
rc = links_section.get("prefix", "/")
|
return templates_section.get("stylesheet", DEFAULT_STYLESHEET_NAME)
|
||||||
return rc if rc.endswith("/") else rc + '/'
|
|
||||||
|
@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
|
@property
|
||||||
def relative_links(self) -> bool:
|
def relative_links(self) -> bool:
|
||||||
|
@ -74,10 +79,11 @@ class Context:
|
||||||
return links_section.get("relative", False)
|
return links_section.get("relative", False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def default_stylesheet(self) -> str:
|
def url_prefix(self) -> str:
|
||||||
"""Returns the default stylesheet name."""
|
"""Returns the configured URL prefix for all URLs generated for internal links."""
|
||||||
templates_section = self.config.get("templates", {})
|
links_section = self.config.get("links", {})
|
||||||
return templates_section.get("stylesheet", DEFAULT_STYLESHEET_NAME)
|
rc = links_section.get("prefix", "/")
|
||||||
|
return rc if rc.endswith("/") else rc + '/'
|
||||||
|
|
||||||
def get_template_name_for_node(self, node: SourceNode) -> str:
|
def get_template_name_for_node(self, node: SourceNode) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -17,6 +17,10 @@ DEFAULT_TEMPLATE = """<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{{ title }}</title>
|
<title>{{ title }}</title>
|
||||||
<link rel="stylesheet" href="{{ default_stylesheet }}"/>
|
<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 }}"/>
|
<meta name="generator" content="dragonglass/{{ dragonglass_version }} python/{{ python_version }}"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -86,6 +90,11 @@ def template_vars(node: SourceNode, ctxt: Context) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
tvars = node.make_vars()
|
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["dragonglass_version"] = __version__
|
||||||
tvars["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}"
|
tvars["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}"
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,8 @@ class SourceNode:
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
"text": self.text,
|
"text": self.text,
|
||||||
"title": self.page_title
|
"title": self.page_title,
|
||||||
|
"description": self.metadata.get("description", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user