-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
371 lines (311 loc) · 13.6 KB
/
Copy pathbuild.py
File metadata and controls
371 lines (311 loc) · 13.6 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/usr/bin/env python3
"""Build the static site into dist/.
pip install -r requirements.txt
python build.py
python -m http.server -d dist 8000 # preview at http://localhost:8000
Add a blog post: copy content/posts/_template.md to
content/posts/YYYY-MM-DD-my-post.md, fill it in, run `python build.py` again
(or just push — the GitHub Actions workflow does this for you, see README).
No other file needs to change; the post appears on the Blog page automatically.
"""
import html
import re
import shutil
from pathlib import Path
import markdown
import theme
import data
ROOT = Path(__file__).parent
OUT = ROOT / "dist"
POSTS_DIR = ROOT / "content/posts"
NEWS_DIR = ROOT / "content/news"
SITE = "https://geophy321.github.io"
def reading_time(body_html):
text = re.sub(r"<[^>]+>", " ", body_html)
words = len(text.split())
minutes = max(1, round(words / 200))
return f"{minutes} min read"
def with_og(page, item, section):
"""Add Open Graph tags to <head> so LinkedIn and others show title, summary and cover."""
tags = {
"og:title": item["title"],
"og:description": item["summary"],
"og:type": "article",
"og:url": f"{SITE}/{section}/{item['slug']}/index.html",
}
if item["cover"]:
tags["og:image"] = f"{SITE}/{item['cover'].lstrip('/')}"
meta = "".join(f'<meta property="{k}" content="{html.escape(v)}">\n' for k, v in tags.items())
return page.replace("</head>", meta + "</head>", 1)
def load_posts():
posts = []
for f in sorted(POSTS_DIR.glob("*.md")):
if f.name.startswith("_"):
continue # _template.md and similar are skipped
md = markdown.Markdown(extensions=["meta", "extra"])
body_html = md.convert(f.read_text(encoding="utf-8"))
meta = md.Meta or {}
posts.append({
"slug": f.stem,
"title": meta.get("title", [f.stem])[0],
"date": meta.get("date", [""])[0],
"summary": meta.get("summary", [""])[0],
"cover": meta.get("cover", [""])[0],
"body_html": body_html,
})
posts[-1]["reading_time"] = reading_time(body_html)
posts.sort(key=lambda p: p["date"], reverse=True)
return posts
def load_news():
news = []
if NEWS_DIR.exists():
for f in sorted(NEWS_DIR.glob("*.md")):
if f.name.startswith("_"):
continue # _template.md and similar are skipped
md = markdown.Markdown(extensions=["meta", "extra"])
body_html = md.convert(f.read_text(encoding="utf-8"))
meta = md.Meta or {}
news.append({
"slug": f.stem,
"title": meta.get("title", [f.stem])[0],
"date": meta.get("date", [""])[0],
"summary": meta.get("summary", [""])[0],
"cover": meta.get("cover", [""])[0],
"body_html": body_html,
})
news[-1]["reading_time"] = reading_time(body_html)
news.sort(key=lambda n: n["date"], reverse=True)
return news
def post_card(item, cover_prefix, href, index=0, animate=False):
if item["cover"]:
thumb = f'<div class="post-card-cover" style="background-image:url(\'{cover_prefix}{item["cover"]}\')"></div>'
else:
thumb = f'<div class="post-card-cover post-card-cover-empty">{theme.ICON_PEN}</div>'
cls = "post-card"
style = ""
if animate:
# Cycle through 4 entry directions so consecutive articles feel varied:
# left, right, top, bottom.
directions = [(-40, 0), (40, 0), (0, -30), (0, 30)]
fx, fy = directions[index % 4]
delay = min(index * 0.25, 1.5)
cls += " news-fly"
style = f' style="--d:{delay:.2f}s;--fx:{fx}px;--fy:{fy}px"'
return f'''<a class="{cls}"{style} href="{href}">
{thumb}
<div class="post-card-body">
<div class="post-date">{theme.esc(item["date"])} · {theme.esc(item["reading_time"])}</div>
<div class="post-title">{theme.esc(item["title"])}</div>
<div class="post-summary">{theme.esc(item["summary"])}</div>
</div>
</a>'''
def rotator_html(items, href_prefix, tag, limit=3):
if not items:
return ""
slides = "".join(
f'''<a class="news-slide{" active" if i == 0 else ""}" href="{href_prefix}{n["slug"]}/index.html">
<span class="news-banner-tag">{tag}</span>
<span class="news-banner-title">{theme.esc(n["title"])}</span>
<span class="news-banner-date">{theme.esc(n["date"])}</span>
</a>'''
for i, n in enumerate(items[:limit])
)
return f'<div class="news-highlights-rotator">{slides}</div>'
def recent_news_banner(news, limit=3):
return rotator_html(news, "news/", "News", limit)
def recent_blog_banner(posts, limit=3):
return rotator_html(posts, "blog/", "Blog", limit)
def news_index_page(news):
if not news:
body = f'''<div class="empty-state">
<div class="grid-thumb" style="margin:0 auto 12px">{theme.ICON_PEN}</div>
<p>No news yet — updates on new publications, project milestones and other announcements
will show up here.</p>
</div>'''
else:
cards = "".join(post_card(n, "../", f'{n["slug"]}/index.html', i, animate=True) for i, n in enumerate(news))
body = f'<div class="grid-auto post-grid">{cards}</div>'
return f'''
<h3 class="page-heading">News</h3>
{body}
'''
def news_item_page(n):
cover_html = f'<img class="post-cover" src="../../{n["cover"]}" alt="" />' if n["cover"] else ""
return f'''
<article>
{cover_html}
<h3 class="page-heading">{theme.esc(n["title"])}</h3>
<p class="post-date">{theme.esc(n["date"])} · {theme.esc(n["reading_time"])}</p>
<div class="post-body">{n["body_html"]}</div>
<p><a href="../index.html">← Back to News</a></p>
</article>
'''
def recent_post_teaser(posts):
if not posts:
return ""
p = posts[0]
return post_card(p, "", f'blog/{p["slug"]}/index.html')
def home_page(posts, news):
cards = "".join([
theme.link_card("fieldwork/index.html", theme.TILE_ICONS["pin"], "Fieldwork", "DAS/DTS installs, seismic surveys, geohazard site work"),
theme.link_card("works/index.html", theme.ICON_PEN, "Editorial Roles", "Handling Editor, Seismica; Associate Editor, IJEEG"),
theme.link_card("publications/index.html", theme.ICON_DOC, "Publications", "35+ peer-reviewed papers on Scopus"),
])
return f'''
<div class="hero-row">
<div class="news-highlights">
{recent_news_banner(news)}
{recent_blog_banner(posts)}
</div>
<div class="hero-photo"><img src="images/IMG_1002.jpeg" alt="Yawar Hussain" width="130" height="130" /></div>
</div>
<section>
<h3 class="section-title">Work</h3>
<p class="para">Yawar is a geophysicist based in Stockholm with a background spanning near-surface
geophysics, seismic monitoring and geohazard characterisation, built over postdoctoral appointments in
Brazil, Belgium, Italy and the United States. He currently works as a Specialist in Infrastructure Hazard
Monitoring at HydroResearch Solutions AB, supporting fibre-optic monitoring (DTS, DSS, DAS) of dams and
embankments from field deployment through to interpretation. Over 35 peer-reviewed publications, an
H-index of 19 and 1284 citations (Scopus).</p>
<div class="center-cta"><a class="btn" href="files/cv.pdf" target="_blank" rel="noopener">CV {theme.ICON_CHEVRON}</a></div>
</section>
<section>
<h3 class="section-title">Interests</h3>
<p class="para">{data.INTERESTS}</p>
</section>
<section>
<h3 class="section-title">On the web</h3>
<ul class="link-list">
<li><a class="ghost-btn" href="mailto:yawar.pgn@gmail.com">{theme.ICON_MAIL} Contact</a></li>
</ul>
<div class="grid-auto">{cards}</div>
{recent_post_teaser(posts)}
<h3 class="section-title">Get in touch</h3>
<p>Happy to talk fibre-optic monitoring, near-surface geophysics, or postdoc/industry opportunities.</p>
<div class="center-cta"><a class="btn" href="mailto:yawar.pgn@gmail.com">{theme.ICON_MAIL} Email me</a></div>
</section>
'''
def works_page():
employment_cards = "".join(
theme.static_card("briefcase", theme.role_title(bold), desc)
for bold, desc in data.EMPLOYMENT
)
project_cards = "".join(
theme.static_card(icon, title, desc) for icon, title, desc in data.PROJECTS
)
def editorial_line(role, org, url):
org_html = theme.esc(org)
if url:
org_html = f'<a href="{theme.esc(url)}" target="_blank" rel="noopener">{org_html}</a>'
return f'<li><b>{theme.esc(role)}</b> — {org_html}</li>'
editorial_items = "".join(editorial_line(role, org, url) for role, org, url in data.EDITORIAL)
education_items = "".join(
f'<li>{theme.esc(deg)} — {theme.esc(place)}</li>'
for deg, place in data.EDUCATION
)
def teaching_line(role, desc, url):
line = f'<li><b>{theme.esc(role)}</b> — {theme.esc(desc)}'
if url:
line += f' <a href="{theme.esc(url)}" target="_blank" rel="noopener">(read more)</a>'
return line + '</li>'
teaching_items = "".join(teaching_line(role, desc, url) for role, desc, url in data.TEACHING)
conferences_items = "".join(f'<li>{theme.esc(c)}</li>' for c in data.CONFERENCES)
return f'''
<h3 class="page-heading">Works</h3>
<h4 class="sub-heading">Employment</h4>
{theme.grid(employment_cards)}
<hr class="divider" />
<h4 class="sub-heading">Projects & Grants</h4>
{theme.grid(project_cards)}
<hr class="divider" />
<h4 class="sub-heading">Editorial Contributions</h4>
{theme.plain_list(editorial_items)}
<hr class="divider" />
<h4 class="sub-heading">Education</h4>
{theme.plain_list(education_items)}
<hr class="divider" />
<h4 class="sub-heading">Teaching</h4>
{theme.plain_list(teaching_items)}
<hr class="divider" />
<h4 class="sub-heading">Selected Conferences</h4>
{theme.plain_list(conferences_items)}
'''
def fieldwork_page():
cards = "".join(theme.static_card("pin", "", item) for item in data.FIELDWORK)
return f'''
<h3 class="page-heading">Fieldwork</h3>
<p class="para">Field deployments spanning dam and mine monitoring, seismic surveys and geohazard site
investigations across Sweden, Italy, Belgium, Spain, Brazil and the United States.</p>
{theme.grid(cards)}
'''
def publications_page():
return f'''
<h3 class="page-heading">Publications</h3>
<p class="para">35+ peer-reviewed papers (Scopus H-index 19, 1284 citations), grouped by topic.</p>
{theme.pubs_accordion(data.PUBLICATIONS)}
'''
def blog_index_page(posts):
if not posts:
body = f'''<div class="empty-state">
<div class="grid-thumb" style="margin:0 auto 12px">{theme.ICON_PEN}</div>
<p>No posts yet — this space is reserved for write-ups on fibre-optic sensing, near-surface geophysics
and fieldwork notes. Check back soon, or get in touch if you'd like to be notified.</p>
<div class="center-cta"><a class="btn" href="mailto:yawar.pgn@gmail.com">{theme.ICON_MAIL} Notify me</a></div>
</div>'''
else:
cards = "".join(post_card(p, "../", f'{p["slug"]}/index.html', i) for i, p in enumerate(posts))
body = f'<div class="grid-auto post-grid">{cards}</div>'
return f'''
<h3 class="page-heading">Blog</h3>
{body}
'''
def post_page(p):
cover_html = f'<img class="post-cover" src="../../{p["cover"]}" alt="" />' if p["cover"] else ""
return f'''
<article>
{cover_html}
<h3 class="page-heading">{theme.esc(p["title"])}</h3>
<p class="post-date">{theme.esc(p["date"])} · {theme.esc(p["reading_time"])}</p>
<div class="post-body">{p["body_html"]}</div>
<p><a href="../index.html">← Back to Blog</a></p>
</article>
'''
def build():
if OUT.exists():
shutil.rmtree(OUT)
(OUT / "assets/css").mkdir(parents=True)
(OUT / "assets/js").mkdir(parents=True)
(OUT / "works").mkdir(parents=True)
(OUT / "fieldwork").mkdir(parents=True)
(OUT / "publications").mkdir(parents=True)
(OUT / "blog").mkdir(parents=True)
(OUT / "news").mkdir(parents=True)
(OUT / "assets/css/main.css").write_text(theme.CSS)
(OUT / "assets/js/main.js").write_text(theme.SCRIPT)
shutil.copytree(ROOT / "images", OUT / "images") # profile photo + any blog-post images
if (ROOT / "files").exists():
shutil.copytree(ROOT / "files", OUT / "files") # CV and other downloadable documents
(OUT / ".nojekyll").write_text("") # tell GitHub Pages this isn't a Jekyll site
posts = load_posts()
news = load_news()
(OUT / "index.html").write_text(theme.layout("Yawar Hussain", "", home_page(posts, news), base=""))
(OUT / "works/index.html").write_text(theme.layout("Works", "works/", works_page(), base="../"))
(OUT / "fieldwork/index.html").write_text(theme.layout("Fieldwork", "fieldwork/", fieldwork_page(), base="../"))
(OUT / "publications/index.html").write_text(theme.layout("Publications", "publications/", publications_page(), base="../"))
(OUT / "blog/index.html").write_text(theme.layout("Blog", "blog/", blog_index_page(posts), base="../"))
(OUT / "news/index.html").write_text(theme.layout("News", "news/", news_index_page(news), base="../"))
for n in news:
page_dir = OUT / "news" / n["slug"]
page_dir.mkdir(parents=True, exist_ok=True)
(page_dir / "index.html").write_text(with_og(
theme.layout(n["title"], "news/", news_item_page(n), base="../../", description=n["summary"] or None),
n, "news"))
for p in posts:
page_dir = OUT / "blog" / p["slug"]
page_dir.mkdir(parents=True, exist_ok=True)
(page_dir / "index.html").write_text(with_og(
theme.layout(p["title"], "blog/", post_page(p), base="../../", description=p["summary"] or None),
p, "blog"))
print(f"built {len(posts)} post(s) -> {OUT}")
if __name__ == "__main__":
build()