vault backup: 2025-12-07 17:19:42
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m48s
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m48s
This commit is contained in:
@@ -68,8 +68,6 @@ def markdown_filter(text):
|
||||
return md.convert(text)
|
||||
|
||||
env.filters["markdown"] = markdown_filter
|
||||
|
||||
template = env.get_template("base.html")
|
||||
output_dir = root_dir / "output"
|
||||
|
||||
|
||||
@@ -96,62 +94,75 @@ def build_tree(vault: Vault):
|
||||
if note:
|
||||
item["title"] = note.title
|
||||
# TODO: for search add tags, modified time, content etc
|
||||
|
||||
cur[filename] = item
|
||||
return tree
|
||||
|
||||
|
||||
def write_note(item, tree_json):
|
||||
def write_note(item):
|
||||
if "children" in item:
|
||||
for child in item["children"].values():
|
||||
write_note(child, tree_json)
|
||||
write_note(child)
|
||||
else:
|
||||
path = pathlib.Path(item["folder"]) / item["filename"]
|
||||
note = vault.get_note(path)
|
||||
if note:
|
||||
out_path = output_dir / item["folder"] / (item["title"] + ".html")
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
context = {
|
||||
"filename": item["filename"],
|
||||
"folder": item["folder"],
|
||||
"path": path,
|
||||
}
|
||||
|
||||
# Calculate relative base_path based on folder depth
|
||||
folder = item["folder"]
|
||||
if folder == ".":
|
||||
base_path = ""
|
||||
else:
|
||||
depth = len(pathlib.Path(folder).parts)
|
||||
base_path = "../" * depth
|
||||
|
||||
with out_path.open("w", encoding="utf-8") as f:
|
||||
data = template.render(note=note, vault=vault, base_path=base_path, index_json=tree_json)
|
||||
f.write(data)
|
||||
folder = output_dir / item["folder"]
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
link = False
|
||||
if note := vault.get_note(path):
|
||||
template_name = "note.jinja2"
|
||||
context["note"] = note
|
||||
context["title"] = note.title
|
||||
elif item["filename"].endswith(".pdf"):
|
||||
template_name = "pdf.jinja2"
|
||||
context["title"] = item["filename"]
|
||||
link = True
|
||||
elif item["filename"].lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
|
||||
template_name = "image.jinja2"
|
||||
context["title"] = item["filename"]
|
||||
link = True
|
||||
else:
|
||||
print(f"Note not found for {path}")
|
||||
return
|
||||
|
||||
if link:
|
||||
os.link(
|
||||
vault.path / item["folder"] / item["filename"],
|
||||
output_dir / item["folder"] / item["filename"],
|
||||
)
|
||||
|
||||
out_path = folder / (context["title"] + ".html")
|
||||
with out_path.open("w", encoding="utf-8") as f:
|
||||
template = env.get_template(template_name)
|
||||
data = template.render(**context)
|
||||
f.write(data)
|
||||
|
||||
|
||||
def build():
|
||||
"""Build the static site."""
|
||||
print("Building...")
|
||||
|
||||
# 1. Create output dir
|
||||
shutil.rmtree(output_dir, ignore_errors=True)
|
||||
output_dir.mkdir(exist_ok=True)
|
||||
|
||||
# 1b. Symlink CSS/JS to output root
|
||||
(output_dir / "style.css").symlink_to(root_dir / "style.css")
|
||||
(output_dir / "script.js").symlink_to(root_dir / "script.js")
|
||||
|
||||
# 1c. Symlink attachments directory
|
||||
attachments_src = root_dir.parent / "content" / "attachments"
|
||||
attachments_dst = output_dir / "attachments"
|
||||
attachments_dst.symlink_to(attachments_src)
|
||||
|
||||
# 2. Build tree and write index json
|
||||
tree = build_tree(vault)
|
||||
tree_json = json.dumps(tree)
|
||||
with (output_dir / "index.json").open("w") as f:
|
||||
f.write(tree_json)
|
||||
|
||||
# 3. Write out each note as html
|
||||
write_note({"children": tree}, tree_json)
|
||||
write_note({"children": tree})
|
||||
|
||||
print(f"Built to {output_dir}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user