diff --git a/doc/configuration.toml b/doc/configuration.toml index f46d4ee..a6ec4b3 100644 --- a/doc/configuration.toml +++ b/doc/configuration.toml @@ -45,6 +45,10 @@ tldr = "clipboard-list" todo = "circle-check" warning = "triangle-alert" +[generate] +# Ignore these entries when generating the site. +ignore = [".git"] + [templates] # The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl". directory = ".dragonglass.tmpl" diff --git a/src/dragonglass/config.py b/src/dragonglass/config.py index 285f6b5..2985409 100644 --- a/src/dragonglass/config.py +++ b/src/dragonglass/config.py @@ -93,6 +93,7 @@ class Context: self.src_index: SourceIndex | None = None self.current_node: SourceNode | None = None self._default_template_name: str | None = None + self._ignore_patterns: list[str] = [] self._extensions: list[Extension] = [] def load_config(self, args: Namespace) -> None: @@ -111,8 +112,12 @@ class Context: # Load several base variables. templates_section = self.config.get("templates", {}) - self.template_dir = self.source_dir / templates_section.get("directory", DEFAULT_TEMPLATE_DIRECTORY) + template_dirname = templates_section.get("directory", DEFAULT_TEMPLATE_DIRECTORY) + self.template_dir = self.source_dir / template_dirname + self._ignore_patterns.append(template_dirname) self._default_template_name = templates_section.get("default", DEFAULT_TEMPLATE_NAME) + generate_section = self.config.get("generate", {}) + self._ignore_patterns.extend(generate_section.get("ignore", [])) # Load the extensions. extensions_section = self.config.get("extensions", {}) @@ -177,6 +182,18 @@ class Context: rc = links_section.get("prefix", "/") return rc if rc.endswith("/") else rc + '/' + def file_ignored(self, filename: Path) -> bool: + """ + Returns ``True`` if a given filename should be ignored, ``False`` if not. + + Args: + filename (Path): The filename to be tested. + """ + for pat in self._ignore_patterns: + if filename.match(pat): + return True + return False + def get_template_name_for_node(self, node: SourceNode) -> str: """ Returns the name of a template to be used to render the current node. diff --git a/src/dragonglass/dragonglass.py b/src/dragonglass/dragonglass.py index 26e6758..4cbb936 100644 --- a/src/dragonglass/dragonglass.py +++ b/src/dragonglass/dragonglass.py @@ -76,7 +76,7 @@ def main() -> int: context.load_config(args) - nodes = generate_list(context.source_dir) + nodes = generate_list(context, context.source_dir) for node in nodes: logger.info(f"Loading metadata for {node}") context.current_node = node diff --git a/src/dragonglass/tree.py b/src/dragonglass/tree.py index 9ebab1b..4f4ded2 100644 --- a/src/dragonglass/tree.py +++ b/src/dragonglass/tree.py @@ -176,7 +176,7 @@ class SourceNode: } -def generate_list(source_root: Path) -> list[SourceNode]: +def generate_list(ctxt: Any, source_root: Path) -> list[SourceNode]: """ Generates the list of source nodes from the source path (Obsidian vault). @@ -197,6 +197,8 @@ def generate_list(source_root: Path) -> list[SourceNode]: if rchild.match(pat): add_me = False break + if add_me and ctxt.file_ignored(rchild): + add_me = False if add_me: nodes.append(SourceNode(source_root, rchild, child.is_dir())) if child.is_dir():