made the configuration file format TOML instead of YAML
This commit is contained in:
parent
821ae2d8a5
commit
8e5c40a642
11
doc/configuration.toml
Normal file
11
doc/configuration.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[links]
|
||||
# The prefix to apply to all internally-generated URLs. Default is "/".
|
||||
prefix = "/"
|
||||
# If true, generate relative URLs for all internal URLs. Default is false.
|
||||
relative = false
|
||||
|
||||
[templates]
|
||||
# The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl".
|
||||
directory = ".dragonglass.tmpl"
|
||||
# The default template name. Default is "default.html".
|
||||
default = "default.html"
|
|
@ -1,6 +0,0 @@
|
|||
# The prefix to apply to all internally-generated URLs. Default is "/".
|
||||
url_prefix: /
|
||||
# The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl".
|
||||
template_directory: .dragonglass.tmpl
|
||||
# The default template name. Default is "default.html".
|
||||
default_template: default.html
|
|
@ -4,7 +4,7 @@ from argparse import Namespace
|
|||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
import tomllib
|
||||
|
||||
from .tree import SourceIndex, SourceNode
|
||||
|
||||
|
@ -27,16 +27,23 @@ class Context:
|
|||
assert self.source_dir is not None
|
||||
config_path = self.source_dir / config_filename
|
||||
if config_path.exists() and config_path.is_file():
|
||||
with open(config_path, "r") as f:
|
||||
self.config = yaml.full_load(f)
|
||||
self.template_dir = self.source_dir / self.config.get("template_directory", DEFAULT_TEMPLATE_DIRECTORY)
|
||||
self._default_template_name = self.config.get("default_template", DEFAULT_TEMPLATE_NAME)
|
||||
with open(config_path, "rb") as f:
|
||||
self.config = tomllib.load(f)
|
||||
templates_section = self.config.get("templates", {})
|
||||
self.template_dir = self.source_dir / templates_section.get("directory", DEFAULT_TEMPLATE_DIRECTORY)
|
||||
self._default_template_name = templates_section.get("default", DEFAULT_TEMPLATE_NAME)
|
||||
|
||||
@property
|
||||
def url_prefix(self) -> str:
|
||||
rc = self.config.get("url_prefix", "/")
|
||||
links_section = self.config.get("links", {})
|
||||
rc = links_section.get("prefix", "/")
|
||||
return rc if rc.endswith("/") else rc + '/'
|
||||
|
||||
@property
|
||||
def relative_links(self) -> bool:
|
||||
links_section = self.config.get("links", {})
|
||||
return links_section.get("relative", False)
|
||||
|
||||
def get_template_name_for_node(self, node: SourceNode) -> str:
|
||||
if not self.template_dir.is_dir():
|
||||
return DEFAULT_TEMPLATE_NAME
|
||||
|
|
|
@ -46,8 +46,10 @@ class SourceNode:
|
|||
p = p.with_suffix('.html')
|
||||
return dest_dir / p
|
||||
|
||||
def link_target(self, prefix: str = "/") -> str:
|
||||
def link_target(self, prefix: str = "/", rel_to: Any = None) -> str:
|
||||
xpath = self._path.with_suffix('.html') if self._is_md else self._path
|
||||
if rel_to is not None:
|
||||
return urlquote(xpath.relative_to(rel_to._path, walk_up=True).as_posix())
|
||||
return urlquote(prefix + xpath.as_posix())
|
||||
|
||||
def load_metadata(self, source_dir: Path) -> None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user