Spaces:
Running
Running
File size: 1,608 Bytes
d90120f ec6cde5 b87d7ee 976f8d8 b87d7ee d0922dd b87d7ee c3271ea d0922dd b87d7ee acee094 1daaaff d0922dd acee094 d0922dd e7941a7 d0922dd 1daaaff c0f4a2f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
"""This script generates the papers.md file from the papers.yml file."""
from pathlib import Path
import yaml
data_file = "papers.yml"
papers_header = Path("stylesheets") / "papers_header.txt"
output_file = "papers.md"
# Load YAML file:
with open(data_file, "r") as stream:
papers = yaml.load(stream, Loader=yaml.SafeLoader)["papers"]
# Load header:
with open(papers_header, "r") as stream:
header = stream.read()
with open(output_file, "w") as f:
f.write(header)
# First, we sort the papers by date.
# This is in the format of "2022-03-15"
papers = sorted(papers, key=lambda paper: paper["date"], reverse=True)
snippets = []
for paper in papers:
title = paper["title"]
authors = (
", ".join(paper["authors"]).replace("(", "<sup>").replace(")", "</sup>")
)
affiliations = ", ".join(
f"<sup>{num}</sup>{affil}" for num, affil in paper["affiliations"].items()
)
link = paper["link"]
abstract = paper["abstract"]
image_file = paper["image"]
if image_file.startswith("http"):
absolute_image_file = image_file
else:
absolute_image_file = f"images/{image_file}"
# Begin:
paper_snippet = f"""
<figure markdown>
![]({absolute_image_file}){{ width="500"}}
<figcaption>
<!-- Large font: -->
<h2>
<a href="{link}">{title}</a>
</h2>
</figcaption>
</figure>
<center>
{authors}
<small>{affiliations}</small>
</center>
**Abstract:** {abstract}\n\n
"""
snippets.append(paper_snippet)
f.write("\n\n---\n\n".join(snippets))
|