diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | build.py | 54 | ||||
| -rw-r--r-- | site/common.typ | 55 | ||||
| -rw-r--r-- | site/content/blog/typst_migration.typ (renamed from site/content/typst_migration.typ) | 0 | ||||
| -rw-r--r-- | site/index.html | 12 | ||||
| -rw-r--r-- | site/index.typ | 30 | ||||
| -rw-r--r-- | static/style.css | 10 |
7 files changed, 112 insertions, 52 deletions
@@ -4,4 +4,5 @@ old_pages/ old_media/ # Generated site -public/
\ No newline at end of file +public/ +site/temp/
\ No newline at end of file @@ -8,10 +8,9 @@ from dataclasses import dataclass from datetime import datetime from pathlib import Path -import jinja2 from loguru import logger from typst import Compiler, TypstError -from watchfiles import watch +from watchfiles import DefaultFilter, watch @dataclass @@ -22,12 +21,14 @@ class CompiledPage: class Builder: - def __init__(self, site_dir: Path, static_dir: Path, public_dir: Path) -> None: + def __init__(self, site_dir: Path, static_dir: Path, public_dir: Path, temp_dir: Path) -> None: self.site_dir = site_dir self.content_dir = site_dir / 'content' self.static_dir = static_dir self.public_dir = public_dir - self.compiler = Compiler(root=site_dir) + self.temp_dir = temp_dir + + self._compiler = Compiler(root=site_dir) def _compile_typst_page(self, path: Path) -> CompiledPage: relative_path = path.relative_to(self.content_dir) @@ -36,7 +37,7 @@ class Builder: output_path = self.public_dir / relative_path.with_suffix('.html') output_path.parent.mkdir(parents=True, exist_ok=True) - self.compiler.compile( + self._compiler.compile( input=path, output=output_path, sys_inputs={ @@ -45,7 +46,7 @@ class Builder: ) metadata = json.loads( - self.compiler.query( + self._compiler.query( selector='<post-meta>', field='value', one=True, @@ -66,9 +67,37 @@ class Builder: return [self._compile_typst_page(path) for path in self.content_dir.rglob('*.typ')] def _compile_index_page(self, pages: list[CompiledPage]) -> None: - pages.sort(key=lambda page: page.date) - template = jinja2.Template((self.site_dir / 'index.html').read_text()) - (self.public_dir / 'index.html').write_text(template.render(pages=pages)) + # pages.sort(key=lambda page: page.date) + # template = jinja2.Template((self.site_dir / 'index.html').read_text()) + # (self.public_dir / 'index.html').write_text(template.render(pages=pages)) + + payload_path = self.temp_dir / 'payload.json' + payload_path.parent.mkdir(parents=True, exist_ok=True) + + pages.sort(key=lambda page: page.date, reverse=True) + + with payload_path.open('w') as file: + payload = { + 'pages': [ + { + 'url': page.url, + 'title': page.title, + 'year': page.date.year, + 'month': page.date.month, + 'day': page.date.day, + } + for page in pages + ], + } + json.dump(payload, file) + + self._compiler.compile( + input=self.site_dir / 'index.typ', + output=self.public_dir / 'index.html', + sys_inputs={ + 'payload': str(payload_path.relative_to(self.site_dir)), + }, + ) def build(self) -> None: logger.info(f'Removing {str(self.public_dir)!r}...') @@ -93,16 +122,19 @@ def main() -> None: site_dir = repo_dir / 'site' public_dir = repo_dir / 'public' static_dir = repo_dir / 'static' + temp_dir = site_dir / 'temp' os.environ['TYPST_FEATURES'] = 'html' - builder = Builder(site_dir=site_dir, static_dir=static_dir, public_dir=public_dir) + builder = Builder(site_dir, static_dir, public_dir, temp_dir) builder.build() if args.watch: logger.info('Watching for changes...') - for changes in watch(site_dir): + watch_filter = DefaultFilter(ignore_paths=[temp_dir]) + + for changes in watch(site_dir, watch_filter=watch_filter): print(changes) try: builder.build() diff --git a/site/common.typ b/site/common.typ index 5f41596..a1c2097 100644 --- a/site/common.typ +++ b/site/common.typ @@ -52,12 +52,29 @@ } } +#let template(title, header, main) = { + html.html({ + html.head({ + html.meta(charset: "utf-8") + html.meta(name: "viewport", content: "width=device-width, initial-scale=1") + html.title(title) + html.link(rel: "stylesheet", href: static("style.css")) + }) + html.header(header) + html.main(main) + html.footer[ + © 2019--2026 Paweł Redman \ + Text and images are licensed under #link("https://creativecommons.org/licenses/by-sa/4.0/")[CC-BY-SA 4.0] unless noted otherwise. + ] + }) +} + #let post(body, title: none, author: "Paweł Redman", date: none) = { assert(date != none, message: "missing date") set document( title: title, - author: "Paweł Redman", + author: author, ) set text(lang: "en") @@ -85,31 +102,15 @@ )) <post-meta> ] - html.html({ - html.head({ - html.meta(charset: "utf-8") - html.meta(name: "viewport", content: "width=device-width, initial-scale=1") - html.title(title) - html.link(rel: "stylesheet", href: static("style.css")) - }) - - html.header({ - html.nav(breadcrumbs()) - }) - - html.main({ - html.article({ - html.header({ - html.h1(title) - html.p(id: "author")[by #author, published on #html.time(datetime: date)[#format-date-en(date)]] - }) - - body + template( + title, + html.nav(breadcrumbs()), + html.article({ + html.header({ + html.h1(title) + html.p(id: "author")[by #author, published on #html.time(datetime: date)[#format-date-en(date)]] }) - }) - - html.footer[ - footer goes here - ] - }) + body + }), + ) }
\ No newline at end of file diff --git a/site/content/typst_migration.typ b/site/content/blog/typst_migration.typ index 50d28cd..50d28cd 100644 --- a/site/content/typst_migration.typ +++ b/site/content/blog/typst_migration.typ diff --git a/site/index.html b/site/index.html deleted file mode 100644 index 7cd6639..0000000 --- a/site/index.html +++ /dev/null @@ -1,12 +0,0 @@ -<html> - <body> - <h1>Blog</h1> - <ul> - {% for page in pages %} - <li> - <a href="{{ page.url }}">{{ page.title }}</a> - </li> - {% endfor %} - </ul> - </body> -</html> diff --git a/site/index.typ b/site/index.typ new file mode 100644 index 0000000..4b615a4 --- /dev/null +++ b/site/index.typ @@ -0,0 +1,30 @@ +#import "/common.typ": template, link-self, webroot, format-date-en +#let payload = json(sys.inputs.payload) + +#show: template.with( + "redman.xyz", + html.h1("redman.xyz"), +) + +I'm Paweł Redman, known online as enneract, a software engineer working on LTE/NR Layer 1 with a B.Sc. in Optics and Photonics Engineering. + += Latest posts + +#for page in payload.pages { + let date = datetime( + year: page.year, + month: page.month, + day: page.day, + ) + + if (datetime.today() - date).days() > 365 { + break + } + + format-date-en(date) + " " + link(webroot + page.url, page.title) +} + += Selected projects + diff --git a/static/style.css b/static/style.css index a64ba66..01b992d 100644 --- a/static/style.css +++ b/static/style.css @@ -11,8 +11,8 @@ body { /* Header */ - h1 { + margin-top: 0; margin-bottom: 0; } @@ -23,6 +23,14 @@ h1 { font-style: italic; } +/* Footer */ + +footer { + text-align: center; + font-size: 80%; + color: #666; +} + /* Content */ img { |
