added additional configuration and metadata information
This commit is contained in:
parent
ad7f109328
commit
fdcdb6a766
|
@ -9,3 +9,5 @@ relative = false
|
||||||
directory = ".dragonglass.tmpl"
|
directory = ".dragonglass.tmpl"
|
||||||
# The default template name. Default is "default.html".
|
# The default template name. Default is "default.html".
|
||||||
default = "default.html"
|
default = "default.html"
|
||||||
|
# The name of the default stylesheet.
|
||||||
|
stylesheet = "dragonglass.css"
|
||||||
|
|
|
@ -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.
|
||||||
|
|
||||||
|
publish
|
||||||
|
(Obsidian Publish standard metadata)
|
||||||
|
If this boolean value is False, the page will not be published.
|
||||||
|
|
||||||
template
|
template
|
||||||
The file name of the template to be used to render this page, overriding the default.
|
The file name of the template to be used to render this page, overriding the default.
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ DEFAULT_CONFIG_FILE = ".dragonglass"
|
||||||
DEFAULT_TEMPLATE_DIRECTORY = ".dragonglass.tmpl"
|
DEFAULT_TEMPLATE_DIRECTORY = ".dragonglass.tmpl"
|
||||||
"""The default template name."""
|
"""The default template name."""
|
||||||
DEFAULT_TEMPLATE_NAME = "default.html"
|
DEFAULT_TEMPLATE_NAME = "default.html"
|
||||||
|
""" The default stylesheet name."""
|
||||||
|
DEFAULT_STYLESHEET_NAME = "dragonglass.css"
|
||||||
|
|
||||||
|
|
||||||
class Context:
|
class Context:
|
||||||
|
@ -71,6 +73,12 @@ class Context:
|
||||||
links_section = self.config.get("links", {})
|
links_section = self.config.get("links", {})
|
||||||
return links_section.get("relative", False)
|
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 get_template_name_for_node(self, node: SourceNode) -> str:
|
def get_template_name_for_node(self, node: SourceNode) -> str:
|
||||||
"""
|
"""
|
||||||
Returns the name of a template to be used to render the current node.
|
Returns the name of a template to be used to render the current node.
|
||||||
|
|
|
@ -87,19 +87,20 @@ def main() -> int:
|
||||||
tenv = create_template_environment(context)
|
tenv = create_template_environment(context)
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
p = node.target_file(dest_dir)
|
if node.publish:
|
||||||
if node.is_dir:
|
p = node.target_file(dest_dir)
|
||||||
p.mkdir(exist_ok=True)
|
if node.is_dir:
|
||||||
elif node.is_md:
|
p.mkdir(exist_ok=True)
|
||||||
context.current_node = node
|
elif node.is_md:
|
||||||
tmpl = tenv.get_template(context.get_template_name_for_node(node))
|
context.current_node = node
|
||||||
data = tmpl.render(template_vars(node, context))
|
tmpl = tenv.get_template(context.get_template_name_for_node(node))
|
||||||
with p.open("wt") as f:
|
data = tmpl.render(template_vars(node, context))
|
||||||
f.write(data)
|
with p.open("wt") as f:
|
||||||
else:
|
f.write(data)
|
||||||
shutil.copyfile(context.source_dir / node.path, p)
|
else:
|
||||||
|
shutil.copyfile(context.source_dir / node.path, p)
|
||||||
|
|
||||||
write_default_stylesheet(tenv, dest_dir)
|
write_default_stylesheet(context, tenv, dest_dir)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logger.exception("Unexpected error in processing")
|
logger.exception("Unexpected error in processing")
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from jinja2 import Environment
|
from jinja2 import Environment
|
||||||
|
|
||||||
"""Name of the default stylesheet."""
|
from .config import Context
|
||||||
STYLESHEET_NAME = "dragonglass.css"
|
|
||||||
|
|
||||||
"""Template data for the default stylesheet."""
|
"""Template data for the default stylesheet."""
|
||||||
STYLESHEET_DATA = """/* Dragonglass default CSS file - ensure all generated HTML pages reference this */
|
STYLESHEET_DATA = """/* Dragonglass default CSS file - ensure all generated HTML pages reference this */
|
||||||
|
@ -214,15 +213,16 @@ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def write_default_stylesheet(tenv: Environment, dest_dir: Path) -> None:
|
def write_default_stylesheet(ctxt: Context, tenv: Environment, dest_dir: Path) -> None:
|
||||||
"""
|
"""
|
||||||
Writes the default stylesheet data to the destination directory.
|
Writes the default stylesheet data to the destination directory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
ctxt (Context): The context for the operation, which includes the configuration.
|
||||||
tenv (Environment): Template engine used to render the default stylesheet data.
|
tenv (Environment): Template engine used to render the default stylesheet data.
|
||||||
dest_dir (Path): The destination directory to write the stylesheet to.
|
dest_dir (Path): The destination directory to write the stylesheet to.
|
||||||
"""
|
"""
|
||||||
to_file = dest_dir / STYLESHEET_NAME
|
to_file = dest_dir / ctxt.default_stylesheet
|
||||||
tmpl = tenv.from_string(STYLESHEET_DATA)
|
tmpl = tenv.from_string(STYLESHEET_DATA)
|
||||||
data = tmpl.render({})
|
data = tmpl.render({})
|
||||||
with to_file.open("wt") as f:
|
with to_file.open("wt") as f:
|
||||||
|
|
|
@ -8,7 +8,6 @@ from typing import Any
|
||||||
from urllib.parse import quote as urlquote
|
from urllib.parse import quote as urlquote
|
||||||
|
|
||||||
from .config import Context, DEFAULT_TEMPLATE_NAME
|
from .config import Context, DEFAULT_TEMPLATE_NAME
|
||||||
from .style import STYLESHEET_NAME
|
|
||||||
from .tree import SourceNode
|
from .tree import SourceNode
|
||||||
from ._version import __version__
|
from ._version import __version__
|
||||||
|
|
||||||
|
@ -98,12 +97,12 @@ def template_vars(node: SourceNode, ctxt: Context) -> dict[str, Any]:
|
||||||
|
|
||||||
# Add reference to the default stylesheet.
|
# Add reference to the default stylesheet.
|
||||||
if ctxt.relative_links:
|
if ctxt.relative_links:
|
||||||
stylesheet_path = ctxt.source_dir / STYLESHEET_NAME
|
stylesheet_path = ctxt.source_dir / ctxt.default_stylesheet
|
||||||
rel_path = ctxt.source_dir / node.path
|
rel_path = ctxt.source_dir / node.path
|
||||||
tvars['default_stylesheet'] = urlquote(stylesheet_path.relative_to(rel_path.parent, walk_up=True).as_posix())
|
tvars['default_stylesheet'] = urlquote(stylesheet_path.relative_to(rel_path.parent, walk_up=True).as_posix())
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
tvars['default_stylesheet'] = urlquote(ctxt.url_prefix + STYLESHEET_NAME)
|
tvars['default_stylesheet'] = urlquote(ctxt.url_prefix + ctxt.default_stylesheet)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return tvars
|
return tvars
|
||||||
|
|
|
@ -77,6 +77,11 @@ class SourceNode:
|
||||||
"""Returns the standard page title for this node."""
|
"""Returns the standard page title for this node."""
|
||||||
return self.metadata.get("title", self._path.stem)
|
return self.metadata.get("title", self._path.stem)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def publish(self) -> bool:
|
||||||
|
"""Returns the "publish" flag for a page."""
|
||||||
|
return self.metadata.get("publish", True) if self._is_md else True
|
||||||
|
|
||||||
def target_file(self, dest_dir: Path) -> Path:
|
def target_file(self, dest_dir: Path) -> Path:
|
||||||
"""
|
"""
|
||||||
Computes the path of the target file as it will be written to the destination directory.
|
Computes the path of the target file as it will be written to the destination directory.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user