-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconf.py
172 lines (137 loc) · 5.18 KB
/
conf.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import glob
import os
import shutil
import sys
project = "Garyfallidis Research Group"
copyright = "2024, GRG"
author = "GRG"
# release = ''
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
try:
import tomllib # type: ignore
except ImportError:
import tomli as tomllib
sys.path.append(os.path.abspath("sphinxext"))
# -- General configuration -----------------------------------------------------
rel = {}
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.ifconfig",
"sphinx_reredirects",
"ablog",
]
# The suffix of source filenames.
source_suffix = ".rst"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "pydata_sphinx_theme"
templates_path = ["_templates"]
html_static_path = ["_static"]
html_js_files = [
"js/nav.js",
"js/carousel.js",
"js/splide.js",
"js/search.js",
"js/pagination.js",
"js/publications.js",
"js/modal.js",
]
html_style = "css/main.css"
# Load multiple TOML files
toml_files = ["context/others.toml", "context/publications.toml", "context/team.toml"]
config = {}
for toml_file in toml_files:
with open(toml_file, "rb") as f:
config.update(tomllib.load(f))
html_context = {
"journal_slides": config["journal_slides"],
"team_director": config["team_director"],
"team_staff": config["team_staff"],
"team_current": config["team_current"],
"team_alumni": config["team_alumni"],
"teaching_course": config["teaching_course"],
"publication_paper": config["publication_paper"],
"default_mode": "light",
}
html_favicon = "_static/images/logos/trident-favicon.png"
html_theme_options = {
# "secondary_sidebar_items": ["page-toc"],
# "show_toc_level": 1,
"logo": {
"text": "Garyfallidis Research Group",
"image_light": "_static/images/logos/trident-large.png",
"image_dark": "_static/images/logos/trident-large.png",
},
"navbar_persistent": [],
"navbar_start": ["components/common/navbar.html"],
"navbar_center": [],
"navbar_end": [],
"footer_center": ["components/common/footer.html"],
"footer_start": [],
"footer_end": [],
}
def generate_team_pages():
TOML_FILE = "context/team.toml"
TEMPLATE_FILE = "_templates/components/team_template/team_template.html"
OUTPUT_DIR = "_templates/team"
# Clear the output directory
if os.path.exists(OUTPUT_DIR):
for filename in os.listdir(OUTPUT_DIR):
file_path = os.path.join(OUTPUT_DIR, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(f"Failed to delete {file_path}. Reason: {e}")
else:
os.makedirs(OUTPUT_DIR)
# Read the team.toml file
with open(TOML_FILE, "rb") as f:
team_data = tomllib.load(f)
# Read the template file
with open(TEMPLATE_FILE, "r") as f:
template_content = f.read()
# List of all team collections we want to process
collections = ["team_director", "team_staff", "team_current", "team_alumni"]
# Loop through each collection
for collection in collections:
if collection in team_data:
for member in team_data[collection]:
member_name = member["name"].lower().replace(" ", "_")
output_file = f"{member_name}.html"
member_html = template_content.replace("{{ collection }}", collection)
member_html = member_html.replace(
"{{ member.name }}", member.get("name", "")
)
with open(os.path.join(OUTPUT_DIR, output_file), "w") as f:
f.write(member_html)
# Generate team pages
generate_team_pages()
# Now populate html_additional_pages
html_additional_pages = {
"index": "pages/home.html",
"about": "pages/about.html",
"team": "pages/team.html",
"research": "pages/research.html",
"teaching": "pages/teaching.html",
"publications": "pages/publications.html",
"software": "pages/software.html",
"career": "pages/career.html",
}
OUTPUT_DIR = "_templates/team"
for filename in glob.glob(os.path.join(OUTPUT_DIR, "*.html")):
member_name = os.path.splitext(os.path.basename(filename))[0]
html_additional_pages[f"team/{member_name}"] = f"team/{os.path.basename(filename)}"