Verified Commit 3120d9e5 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

finish reference expansion extension and move to repo root

parent 376f35ea
Pipeline #81672 passed with stages
in 3 minutes and 1 second
......@@ -7,17 +7,17 @@ stages:
execute_ipynbs:
stage: build
script:
- jupyter-book build src
- jupyter-book build .
# Workaround of https://github.com/executablebooks/MyST-NB/issues/287
- cp src/_static/mystnb.css src/_build/html/_static/
- cp _static/mystnb.css _build/html/_static/
artifacts:
paths:
- src/_build/html
- _build/html
expire_in: 7d
cache:
- key: global
paths:
- src/_build/
- _build/
mirror to github:
......@@ -46,7 +46,7 @@ mirror to github:
- mkdir -p ~/.ssh && ssh-keyscan tnw-tn1.tudelft.net >> ~/.ssh/known_hosts
- echo $WEBSITE_KEY | base64 -d > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa
script:
- "rsync -ravz src/_build/html/* $USER@tnw-tn1.tudelft.net:"
- "rsync -ravz _build/html/* $USER@tnw-tn1.tudelft.net:"
after_script:
- rm -rf ~/.ssh
......
......@@ -2,6 +2,10 @@ title: 'Topology in condensed matter: tying quantum knots'
author: Topology course team
copyright: ""
extra_footer: "© 2021, TU Delft, CC-BY-SA 4.0 & MIT"
exclude_patterns:
- _build
- "**.ipynb_checkpoints"
- readme.md
execute:
execute_notebooks: cache
timeout: -1
......@@ -18,5 +22,7 @@ sphinx:
- crossorigin: anonymous
- - https://unpkg.com/@holoviz/panel@0.10.2/dist/panel.min.js
- crossorigin: anonymous
local_extensions:
expand_refs: ./expand_refs/
launch_buttons:
binderhub_url: "" # Turn off binder for now
import os
import re
from pathlib import Path
from functools import cache
from jinja2 import Template
......@@ -24,13 +25,6 @@ INLINE_TEMPLATE = Template(
)
def expand_syllabus(toc, template, out):
"""Plug the TOC data into a syllabus template."""
Path(out).write_text(
Template(Path(template).read_text()).render(chapters=YAML().load(Path(toc)))
)
def update_bibliography(bibliography, source_path):
"""Find all arxiv references and update bibliography from them."""
prerpints = sum(
......@@ -52,9 +46,14 @@ def update_bibliography(bibliography, source_path):
)
def expand_refs(bibliography, source_path):
@cache
def read_refs(bibliography):
refs = YAML().load(Path(bibliography))
refs = {ref["id"]: ref for ref in refs}
return {ref["id"]: ref for ref in refs}
def replace_refs(app, docname, source):
refs = read_refs("bibliography.yml")
def replace(match):
if match.group(1) == "### ":
......@@ -65,22 +64,14 @@ def expand_refs(bibliography, source_path):
template = INLINE_TEMPLATE
return match.group(1) + template.render(preprint=refs[match.group(2)])
for document in Path(source_path).glob("**/*.md"):
modified = re.sub(
r"(### |\* |[^#*] )" + PREPRINT_REGEX, replace, document.read_text()
)
document.write_text(modified)
source[0] = re.sub(r"(### |\* |[^#*] )" + PREPRINT_REGEX, replace, source[0])
def main():
course_materials = Path(os.environ["MARKDOWN"])
toc = "toc.yml"
template = course_materials / "syllabus.md.j2"
out = course_materials / "syllabus.md"
expand_syllabus(toc, template, out)
update_bibliography("bibliography.yml", course_materials)
expand_refs("bibliography.yml", course_materials)
def setup(app):
app.connect("source-read", replace_refs)
if __name__ == "__main__":
main()
return {
'version': '0.0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment