1
0

vault backup: 2025-12-07 17:19:42
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m48s

This commit is contained in:
2025-12-07 17:19:42 +01:00
parent 502887ad61
commit 2e231ec64c
28 changed files with 109 additions and 39 deletions

View File

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.5 MiB

View File

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 143 KiB

View File

@@ -36,11 +36,3 @@ PMCID: PMC389671
PMID: 4342968 PMID: 4342968
→ Nobelpriset 1980 till Paul Berg → Nobelpriset 1980 till Paul Berg
𝛼-sl

View File

@@ -68,8 +68,6 @@ def markdown_filter(text):
return md.convert(text) return md.convert(text)
env.filters["markdown"] = markdown_filter env.filters["markdown"] = markdown_filter
template = env.get_template("base.html")
output_dir = root_dir / "output" output_dir = root_dir / "output"
@@ -96,62 +94,75 @@ def build_tree(vault: Vault):
if note: if note:
item["title"] = note.title item["title"] = note.title
# TODO: for search add tags, modified time, content etc # TODO: for search add tags, modified time, content etc
cur[filename] = item cur[filename] = item
return tree return tree
def write_note(item, tree_json): def write_note(item):
if "children" in item: if "children" in item:
for child in item["children"].values(): for child in item["children"].values():
write_note(child, tree_json) write_note(child)
else: else:
path = pathlib.Path(item["folder"]) / item["filename"] path = pathlib.Path(item["folder"]) / item["filename"]
note = vault.get_note(path) context = {
if note: "filename": item["filename"],
out_path = output_dir / item["folder"] / (item["title"] + ".html") "folder": item["folder"],
out_path.parent.mkdir(parents=True, exist_ok=True) "path": path,
}
# Calculate relative base_path based on folder depth folder = output_dir / item["folder"]
folder = item["folder"] folder.mkdir(parents=True, exist_ok=True)
if folder == ".": link = False
base_path = "" if note := vault.get_note(path):
else: template_name = "note.jinja2"
depth = len(pathlib.Path(folder).parts) context["note"] = note
base_path = "../" * depth context["title"] = note.title
elif item["filename"].endswith(".pdf"):
with out_path.open("w", encoding="utf-8") as f: template_name = "pdf.jinja2"
data = template.render(note=note, vault=vault, base_path=base_path, index_json=tree_json) context["title"] = item["filename"]
f.write(data) link = True
elif item["filename"].lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".webp")):
template_name = "image.jinja2"
context["title"] = item["filename"]
link = True
else: else:
print(f"Note not found for {path}") 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(): def build():
"""Build the static site.""" """Build the static site."""
print("Building...") print("Building...")
# 1. Create output dir
shutil.rmtree(output_dir, ignore_errors=True) shutil.rmtree(output_dir, ignore_errors=True)
output_dir.mkdir(exist_ok=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 / "style.css").symlink_to(root_dir / "style.css")
(output_dir / "script.js").symlink_to(root_dir / "script.js") (output_dir / "script.js").symlink_to(root_dir / "script.js")
# 1c. Symlink attachments directory
attachments_src = root_dir.parent / "content" / "attachments" attachments_src = root_dir.parent / "content" / "attachments"
attachments_dst = output_dir / "attachments" attachments_dst = output_dir / "attachments"
attachments_dst.symlink_to(attachments_src) attachments_dst.symlink_to(attachments_src)
# 2. Build tree and write index json
tree = build_tree(vault) tree = build_tree(vault)
tree_json = json.dumps(tree) tree_json = json.dumps(tree)
with (output_dir / "index.json").open("w") as f: with (output_dir / "index.json").open("w") as f:
f.write(tree_json) f.write(tree_json)
# 3. Write out each note as html # 3. Write out each note as html
write_note({"children": tree}, tree_json) write_note({"children": tree})
print(f"Built to {output_dir}") print(f"Built to {output_dir}")

View File

@@ -3,7 +3,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<base href="{{base_path}}"> <base href="{{base_path}}">
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<title>{% block title %}WIP{% endblock %}</title> <title>{% block title %}{% endblock %}</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
</head> </head>
<body> <body>

View File

@@ -0,0 +1,20 @@
{% extends "base.jinja2" %}
{% block title %}{{ filename }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
<div class="image-container">
<img src="{{ filename }}" alt="{{ title }}" class="preview-image">
</div>
<style>
.image-container {
margin-top: 15px;
}
.preview-image {
max-width: 100%;
height: auto;
border-radius: 5px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
</style>
{% endblock %}

View File

@@ -1,4 +1,4 @@
{% extends 'base.html' %} {% extends 'base.jinja2' %}
{% block title %}{{note.title}}{% endblock %} {% block title %}{{note.title}}{% endblock %}
{% block content %} {% block content %}
<h1>{{note.title}}</h1> <h1>{{note.title}}</h1>

View File

@@ -1,5 +1,52 @@
{% extends "base.html" %} {% extends "base.jinja2" %}
{% block title %}{{filename}}{% endblock %} {% block title %}{{ filename }}{% endblock %}
{% block content %} {% block content %}
TODO: pdf.js <h1>{{ title }}</h1>
<a id="download-btn" href="{{ filename }}" download class="download-button">Download PDF</a>
<canvas id="pdf-render"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.min.js"></script>
<script type="text/javascript">
const url = "{{ filename }}";
const pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.6.347/pdf.worker.min.js';
const loadingTask = pdfjsLib
.getDocument(url)
.promise
.then(function (pdf) {
console.log('PDF loaded');
pdf.getPage(1).then(function (page) {
console.log('Page loaded');
const scale = 1.5;
const viewport = page.getViewport({scale: scale});
const canvas = document.getElementById('pdf-render');
const context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
const renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext).promise.then(function () {
console.log('Page rendered');
});
});
})
.catch(function (reason) {
console.error(reason);
});
</script>
<style>
.download-button {
display: inline-block;
padding: 10px 20px;
background-color: #007bff;
color: white;
text-decoration: none;
border-radius: 5px;
margin-bottom: 15px;
}
.download-button:hover {
background-color: #0056b3;
}
</style>
{% endblock %} {% endblock %}