mirror of
https://github.com/NotXia/unibo-ai-notes.git
synced 2025-12-15 19:12:22 +01:00
Simplified web view
This commit is contained in:
40
.github/prepare_web_viewer.py
vendored
40
.github/prepare_web_viewer.py
vendored
@ -2,15 +2,16 @@ import argparse
|
|||||||
from read_metadata import readMetadata
|
from read_metadata import readMetadata
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
# from pathlib import Path
|
||||||
import shutil
|
# import shutil
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(prog="Web viewer formatter")
|
parser = argparse.ArgumentParser(prog="Web viewer formatter")
|
||||||
parser.add_argument("--src-path", type=str, required=True, help="Path to the .tex sources (for metadata)")
|
parser.add_argument("--src-path", type=str, required=True, help="Path to the .tex sources (for metadata)")
|
||||||
parser.add_argument("--out-path", type=str, required=True, help="Path of the output directory")
|
parser.add_argument("--out-path", type=str, required=True, help="Path of the output directory")
|
||||||
parser.add_argument("--pdfs-path", type=str, required=True, help="Path of the pdfs directory")
|
parser.add_argument("--gh-raw-pdf-url", type=str, required=True, help="Base URL of Github raw pdfs")
|
||||||
|
# parser.add_argument("--pdfs-path", type=str, required=True, help="Path of the pdfs directory")
|
||||||
parser.add_argument("--template-path", type=str, default="./web-viewer", help="Path to the templates")
|
parser.add_argument("--template-path", type=str, default="./web-viewer", help="Path to the templates")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -19,10 +20,10 @@ if __name__ == "__main__":
|
|||||||
url_pdf_dir = "pdfs"
|
url_pdf_dir = "pdfs"
|
||||||
dest_pdf_dir = os.path.join(args.out_path, url_pdf_dir)
|
dest_pdf_dir = os.path.join(args.out_path, url_pdf_dir)
|
||||||
with open(os.path.join(args.template_path, "index.html"), "r") as f: index_template = f.read()
|
with open(os.path.join(args.template_path, "index.html"), "r") as f: index_template = f.read()
|
||||||
with open(os.path.join(args.template_path, "view.html"), "r") as f: viewer_template = f.read()
|
# with open(os.path.join(args.template_path, "view.html"), "r") as f: viewer_template = f.read()
|
||||||
|
|
||||||
os.makedirs(args.out_path, exist_ok=True)
|
os.makedirs(args.out_path, exist_ok=True)
|
||||||
shutil.copytree(args.pdfs_path, dest_pdf_dir, dirs_exist_ok=True)
|
# shutil.copytree(args.pdfs_path, dest_pdf_dir, dirs_exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
# Generate home page content
|
# Generate home page content
|
||||||
@ -33,12 +34,12 @@ if __name__ == "__main__":
|
|||||||
course_content = notes_metadata[year][semester][course]["content"]
|
course_content = notes_metadata[year][semester][course]["content"]
|
||||||
|
|
||||||
if (len(course_content) == 1) and (course_content[0]["name"] is None):
|
if (len(course_content) == 1) and (course_content[0]["name"] is None):
|
||||||
table_of_content += f"<h2><a href={Path(course_content[0]['url']).stem}.html>{course_name}</a></h2>\n"
|
table_of_content += f"<h2><a href='{os.path.join(args.gh_raw_pdf_url, course_content[0]['url'])}'>{course_name}</a></h2>\n"
|
||||||
else:
|
else:
|
||||||
table_of_content += f"<h2>{course_name}</h2>\n"
|
table_of_content += f"<h2>{course_name}</h2>\n"
|
||||||
table_of_content += "<ul>\n"
|
table_of_content += "<ul>\n"
|
||||||
for content in course_content:
|
for content in course_content:
|
||||||
table_of_content += f"<li><h3><a href={Path(content['url']).stem}.html>{content['name']}</a></h3></li>\n"
|
table_of_content += f"<li><h3><a href='{os.path.join(args.gh_raw_pdf_url, content['url'])}'>{content['name']}</a></h3></li>\n"
|
||||||
table_of_content += "</ul>\n"
|
table_of_content += "</ul>\n"
|
||||||
|
|
||||||
with open(os.path.join(args.out_path, "index.html"), "w") as f:
|
with open(os.path.join(args.out_path, "index.html"), "w") as f:
|
||||||
@ -52,17 +53,16 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
|
|
||||||
# Generate viewer content
|
# Generate viewer content
|
||||||
for year in notes_metadata.keys():
|
# for year in notes_metadata.keys():
|
||||||
for semester in notes_metadata[year].keys():
|
# for semester in notes_metadata[year].keys():
|
||||||
for course in notes_metadata[year][semester]:
|
# for course in notes_metadata[year][semester]:
|
||||||
course_name = notes_metadata[year][semester][course]["name"]
|
# course_name = notes_metadata[year][semester][course]["name"]
|
||||||
course_content = notes_metadata[year][semester][course]["content"]
|
# course_content = notes_metadata[year][semester][course]["content"]
|
||||||
|
|
||||||
for content in course_content:
|
|
||||||
content_local_path = os.path.join(url_pdf_dir, content["url"])
|
|
||||||
content_html_name = f"{Path(content['url']).stem}.html"
|
|
||||||
with open(os.path.join(args.out_path, content_html_name), "w") as f:
|
|
||||||
page_content = re.sub(r"{{pdf-path}}", f"{content_local_path}", viewer_template)
|
|
||||||
page_content = re.sub(r"{{course-name}}", f"{Path(content['url']).name}", page_content)
|
|
||||||
f.write(page_content)
|
|
||||||
|
|
||||||
|
# for content in course_content:
|
||||||
|
# content_local_path = os.path.join(url_pdf_dir, content["url"])
|
||||||
|
# content_html_name = f"{Path(content['url']).stem}.html"
|
||||||
|
# with open(os.path.join(args.out_path, content_html_name), "w") as f:
|
||||||
|
# page_content = re.sub(r"{{pdf-path}}", f"{content_local_path}", viewer_template)
|
||||||
|
# page_content = re.sub(r"{{course-name}}", f"{Path(content['url']).name}", page_content)
|
||||||
|
# f.write(page_content)
|
||||||
16
.github/web-viewer/index.html
vendored
16
.github/web-viewer/index.html
vendored
@ -8,8 +8,20 @@
|
|||||||
<style>
|
<style>
|
||||||
* {
|
* {
|
||||||
font-family: monospace, monospace;
|
font-family: monospace, monospace;
|
||||||
color: white;
|
}
|
||||||
background-color: #292929;
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
* {
|
||||||
|
color: black;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
* {
|
||||||
|
color: white;
|
||||||
|
background-color: #292929;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
2
.github/workflows/compile.yml
vendored
2
.github/workflows/compile.yml
vendored
@ -67,8 +67,8 @@ jobs:
|
|||||||
python3 ${GITHUB_WORKSPACE}/.github/prepare_web_viewer.py \
|
python3 ${GITHUB_WORKSPACE}/.github/prepare_web_viewer.py \
|
||||||
--src-path=${GITHUB_WORKSPACE}/src \
|
--src-path=${GITHUB_WORKSPACE}/src \
|
||||||
--out-path=/tmp/webviewer \
|
--out-path=/tmp/webviewer \
|
||||||
--pdfs-path=${GITHUB_WORKSPACE}/.compiled \
|
|
||||||
--template-path=${GITHUB_WORKSPACE}/.github/web-viewer \
|
--template-path=${GITHUB_WORKSPACE}/.github/web-viewer \
|
||||||
|
--gh-raw-pdf-url="https://raw.githubusercontent.com/NotXia/unibo-ai-notes/pdfs"
|
||||||
|
|
||||||
- name: Move to pages branch
|
- name: Move to pages branch
|
||||||
uses: s0/git-publish-subdir-action@develop
|
uses: s0/git-publish-subdir-action@develop
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,4 +11,6 @@
|
|||||||
*.run.xml
|
*.run.xml
|
||||||
[!_]*.pdf
|
[!_]*.pdf
|
||||||
|
|
||||||
.compiled
|
.compiled
|
||||||
|
|
||||||
|
__pycache__
|
||||||
Reference in New Issue
Block a user