add a better ignore system when generating the site
This commit is contained in:
parent
eca318835e
commit
e51d597961
|
@ -45,6 +45,10 @@ tldr = "clipboard-list"
|
||||||
todo = "circle-check"
|
todo = "circle-check"
|
||||||
warning = "triangle-alert"
|
warning = "triangle-alert"
|
||||||
|
|
||||||
|
[generate]
|
||||||
|
# Ignore these entries when generating the site.
|
||||||
|
ignore = [".git"]
|
||||||
|
|
||||||
[templates]
|
[templates]
|
||||||
# The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl".
|
# The template directory name under the Obsidian vault. Default is ".dragonglass.tmpl".
|
||||||
directory = ".dragonglass.tmpl"
|
directory = ".dragonglass.tmpl"
|
||||||
|
|
|
@ -93,6 +93,7 @@ class Context:
|
||||||
self.src_index: SourceIndex | None = None
|
self.src_index: SourceIndex | None = None
|
||||||
self.current_node: SourceNode | None = None
|
self.current_node: SourceNode | None = None
|
||||||
self._default_template_name: str | None = None
|
self._default_template_name: str | None = None
|
||||||
|
self._ignore_patterns: list[str] = []
|
||||||
self._extensions: list[Extension] = []
|
self._extensions: list[Extension] = []
|
||||||
|
|
||||||
def load_config(self, args: Namespace) -> None:
|
def load_config(self, args: Namespace) -> None:
|
||||||
|
@ -111,8 +112,12 @@ class Context:
|
||||||
|
|
||||||
# Load several base variables.
|
# Load several base variables.
|
||||||
templates_section = self.config.get("templates", {})
|
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)
|
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.
|
# Load the extensions.
|
||||||
extensions_section = self.config.get("extensions", {})
|
extensions_section = self.config.get("extensions", {})
|
||||||
|
@ -177,6 +182,18 @@ class Context:
|
||||||
rc = links_section.get("prefix", "/")
|
rc = links_section.get("prefix", "/")
|
||||||
return rc if rc.endswith("/") else rc + '/'
|
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:
|
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.
|
||||||
|
|
|
@ -76,7 +76,7 @@ def main() -> int:
|
||||||
|
|
||||||
context.load_config(args)
|
context.load_config(args)
|
||||||
|
|
||||||
nodes = generate_list(context.source_dir)
|
nodes = generate_list(context, context.source_dir)
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
logger.info(f"Loading metadata for {node}")
|
logger.info(f"Loading metadata for {node}")
|
||||||
context.current_node = node
|
context.current_node = node
|
||||||
|
|
|
@ -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).
|
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):
|
if rchild.match(pat):
|
||||||
add_me = False
|
add_me = False
|
||||||
break
|
break
|
||||||
|
if add_me and ctxt.file_ignored(rchild):
|
||||||
|
add_me = False
|
||||||
if add_me:
|
if add_me:
|
||||||
nodes.append(SourceNode(source_root, rchild, child.is_dir()))
|
nodes.append(SourceNode(source_root, rchild, child.is_dir()))
|
||||||
if child.is_dir():
|
if child.is_dir():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user