codified and implemented some of the metadata values and template variables
This commit is contained in:
parent
375767a93c
commit
ad7f109328
12
doc/metadata-values.txt
Normal file
12
doc/metadata-values.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
METADATA VALUES USED BY DRAGONGLASS
|
||||
|
||||
aliases
|
||||
(Obsidian standard metadata)
|
||||
List of alternative names that can be used to link to a
|
||||
particular page.
|
||||
|
||||
template
|
||||
The file name of the template to be used to render this page, overriding the default.
|
||||
|
||||
title
|
||||
Title to use for the page, overriding the Markdown file name.
|
21
doc/template-vars.txt
Normal file
21
doc/template-vars.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
TEMPLATE VARIABLES PROVIDED BY DRAGONGLASS WHEN RENDERING A DOCUMENT
|
||||
|
||||
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
|
||||
The filename of the default stylesheet which is generated by dragonglass and added to the
|
||||
generated pages.
|
||||
|
||||
dragonglass_version
|
||||
The version number of dragonglass.
|
||||
|
||||
python_version
|
||||
The version number of Python that's running dragonglass.
|
||||
|
||||
text
|
||||
The text of the page being rendered.
|
||||
|
||||
title
|
||||
The title of the page being rendered.
|
1
src/dragonglass/_version.py
Normal file
1
src/dragonglass/_version.py
Normal file
|
@ -0,0 +1 @@
|
|||
__version__ = "0.1.0"
|
|
@ -83,4 +83,4 @@ class Context:
|
|||
"""
|
||||
if not self.template_dir.is_dir():
|
||||
return DEFAULT_TEMPLATE_NAME
|
||||
return self._default_template_name
|
||||
return node.metadata.get("template", self._default_template_name)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""The template engine used to render the data to the destination."""
|
||||
import sys
|
||||
|
||||
from jinja2 import Environment, BaseLoader, ChoiceLoader, FunctionLoader, FileSystemLoader
|
||||
from typing import Any
|
||||
|
@ -9,6 +10,7 @@ from urllib.parse import quote as urlquote
|
|||
from .config import Context, DEFAULT_TEMPLATE_NAME
|
||||
from .style import STYLESHEET_NAME
|
||||
from .tree import SourceNode
|
||||
from ._version import __version__
|
||||
|
||||
|
||||
"""The default template used to render Markdown data."""
|
||||
|
@ -16,6 +18,7 @@ DEFAULT_TEMPLATE = """<html>
|
|||
<head>
|
||||
<title>{{ title }}</title>
|
||||
<link rel="stylesheet" href="{{ default_stylesheet }}"/>
|
||||
<meta name="generator" content="dragonglass/{{ dragonglass_version }} python/{{ python_version }}"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ title }}</h1>
|
||||
|
@ -84,6 +87,9 @@ def template_vars(node: SourceNode, ctxt: Context) -> dict[str, Any]:
|
|||
"""
|
||||
tvars = node.make_vars()
|
||||
|
||||
tvars["dragonglass_version"] = __version__
|
||||
tvars["python_version"] = f"{sys.version_info[0]}.{sys.version_info[1]}.{sys.version_info[2]}"
|
||||
|
||||
# Compute backlinks for this node.
|
||||
backlinks = sorted(node.backlinks, key=lambda n: n.page_title)
|
||||
tvars['backlinks'] = [{'title': n.page_title,
|
||||
|
|
|
@ -75,7 +75,7 @@ class SourceNode:
|
|||
@property
|
||||
def page_title(self) -> str:
|
||||
"""Returns the standard page title for this node."""
|
||||
return self._path.stem
|
||||
return self.metadata.get("title", self._path.stem)
|
||||
|
||||
def target_file(self, dest_dir: Path) -> Path:
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user