Skip to content

Commit

Permalink
add feed link to article body
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Jun 24, 2024
1 parent 1e47ba3 commit 6979116
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ watch:
make build
echo "Started watcher..."
while true; do \
inotifywait -qr -e modify -e create -e delete -e move --include 'src/.*$$' --include 'scripts/.*$$' .; \
inotifywait -qr -e modify -e create -e delete -e move --include '(src|scripts)/.*$$' .; \
make build; \
done

Expand Down
32 changes: 20 additions & 12 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import functools
import json
import os
import shutil
Expand All @@ -27,18 +28,32 @@

@dataclasses.dataclass
class PostMeta:
slug: str
title: str
timestamp: datetime
public: bool

@classmethod
def parse(cls, d: dict[str, Any]) -> PostMeta:
def parse(cls, slug: str, d: dict[str, Any]) -> PostMeta:
return cls(
slug=slug,
title=d["title"],
timestamp=datetime.fromisoformat(d["timestamp"]),
public=d["public"],
)

@functools.cached_property
def lastupdated(self) -> datetime | None:
p = f"src/posts/tex/{self.slug}.tex"
r = subprocess.run(["git", "log", "-1", "--format=%cI", p], capture_output=True, text=True)
text = r.stdout.strip()
if not text:
return None
lastupdated = datetime.fromisoformat(text).astimezone(pytz.utc)
if lastupdated.date() == self.timestamp.date():
return None
return lastupdated


PostIndex = dict[str, PostMeta]

Expand All @@ -52,13 +67,6 @@ def site_updated_at() -> datetime:
return datetime.fromisoformat(text).astimezone(pytz.utc)


def article_updated_at(slug: str) -> datetime:
p = f"src/posts/tex/{slug}.tex"
r = subprocess.run(["git", "log", "-1", "--format=%cI", p], capture_output=True, text=True)
text = r.stdout.strip()
return datetime.fromisoformat(text).astimezone(pytz.utc)


# BUILD STEPS


Expand All @@ -84,13 +92,13 @@ def compile_index(posts: PostIndex):
tpl = je.from_string(fp.read())

# Write the main index.html
publicposts = {k: v for k, v in posts.items() if v.public}
publicposts = {k: v for k, v in reversed(posts.items()) if v.public}
index = tpl.render(posts=publicposts)
with Path("dist/index.html").open("w") as fp:
fp.write(index)

# Write a staging index.html
staging = tpl.render(posts=posts)
staging = tpl.render(posts=dict(reversed(posts.items())))
with Path("dist/staging.html").open("w") as fp:
fp.write(staging)

Expand Down Expand Up @@ -153,7 +161,7 @@ def compile_feed(posts: PostIndex):
SubElement(post, "link", href=f"https://sunsetglow.net/posts/{slug}.html", type="text/html")
SubElement(post, "title").text = meta.title
SubElement(post, "published").text = meta.timestamp.isoformat()
SubElement(post, "updated").text = article_updated_at(slug).isoformat()
SubElement(post, "updated").text = (meta.lastupdated or meta.timestamp).isoformat()

author = SubElement(post, "author")
SubElement(author, "name").text = "blissful"
Expand All @@ -169,7 +177,7 @@ def main():
os.chdir(PROJECT_DIR)

with Path("src/posts/index.json").open("r") as fp:
posts = {k: PostMeta.parse(v) for k, v in json.load(fp).items()}
posts = {k: PostMeta.parse(k, v) for k, v in json.load(fp).items()}

empty_dist()
shutil.copytree("src/assets", "dist/assets")
Expand Down
3 changes: 3 additions & 0 deletions src/assets/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ code {
/* Flex. */
.flex { display: flex }
.flex-col { flex-direction: column }
.justify-center { justify-content: center }
.justify-between { justify-content: space-between }
.align-center { align-items: center }

/* Gap. */
.gap-1 { gap: .25rem }
Expand Down
12 changes: 10 additions & 2 deletions src/assets/css/post.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,24 @@
padding-bottom: .75rem;
}

.pandoc p {
.pandoc p,
.pandoc pre,
.pandoc blockquote {
padding-bottom: .5rem;
}

.pandoc .footnote-ref {
font-size: var(--font-size-xs);
}

.pandoc pre,
.pandoc pre code {
padding-bottom: .5rem;
font-size: var(--font-size-xs);
}

.pandoc blockquote {
margin: .5rem 1.5rem;
margin: 0 1.5rem;
line-height: 1.25;
font-size: var(--font-size-xs);
color: var(--color-fg-secondary);
Expand Down
5 changes: 3 additions & 2 deletions src/index.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>
<body>
<div class="flex flex-col gap-2 p-4">
<div>sunset glow <a href="/atom.xml">(feed)</a></div>
<div>sunset glow</div>
<div class="flex flex-col gap-1">
<div class="bold">About:</div>
<ul>
Expand Down Expand Up @@ -40,7 +40,8 @@
<li><a href="https://github.com/azuline/rose">Rosé</a>, a music management library with CLI and virtual filesystem frontends.</li>
</ul>
</div>
<div class="pt-2">
<div class="pt-4">
<a href="/atom.xml" class="text-xs fg-secondary">(feed)</a>
<a href="https://github.com/azuline/sunsetglow" class="text-xs fg-secondary">(source)</a>
</div>
</div>
Expand Down
13 changes: 9 additions & 4 deletions src/posts/template.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="py-16" />
<div class="flex flex-col gap-4">
<div class="display text-xxl medium">{{ meta.title }}</div>
<div class="display text-sm fg-secondary italic">{{ meta.timestamp.strftime("%B %-d, %Y") }}</div>
<div class="display text-sm italic">{{ meta.timestamp.strftime("%B %-d, %Y") }}</div>
</div>
<div class="pb-8 w-full"></div>
<div class="pandoc">
Expand All @@ -21,9 +21,14 @@
<div class="py-8">
<div class="br-top br-secondary"></div>
</div>
<div class="text-xs fg-secondary">
<a href="https://github.com/azuline/sunsetglow/blob/master/src/posts/tex/{{ slug }}.tex" class="fg-secondary">Source</a>
| Found an error or typo? PRs welcome!
<div class="flex justify-between">
<div class="text-xs fg-secondary">
<a href="https://github.com/azuline/sunsetglow/blob/master/src/posts/tex/{{ slug }}.tex" class="fg-secondary">Source</a>
| Found an error or typo? PRs welcome!
</div>
<div class="text-xs fg-secondary">
<a href="https://sunsetglow.net/atom.xml" class="fg-secondary">Feed</a>
</div>
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/posts/tex/frontend-build-systems.tex
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ \subsection{Bundling}
The bundlers in common use today are Webpack, Parcel, Rollup, esbuild, and Turbopack.

\begin{enumerate}
\item \href{https://webpack.js.org/}{\tb{Webpack}} (2014) started gaining significant popularity
around 2016, later becoming the standard bundler. Unlike the then-incumbent Browserify, which
was commonly used with the Gulp task runner, Webpack pioneered ``loaders'' that transformed
source files upon import, allowing Webpack to orchestrate the entire build pipeline.
\item \href{https://webpack.js.org/}{\tb{Webpack}} (2014) gained significant popularity around
2016, later becoming the standard bundler. Unlike the then-incumbent Browserify, which was
commonly used with the Gulp task runner, Webpack pioneered ``loaders'' that transformed source
files upon import, allowing Webpack to orchestrate the entire build pipeline.

Loaders also allowed developers to transparently import static assets inside JavaScript files,
Loaders allowed developers to transparently import static assets inside JavaScript files,
combining all source files and static assets into a single dependency graph. With Gulp, each
type of static asset had to be built as a separate task. Webpack also supported
\hl{code-splitting}{code splitting} out of the box, simplifying its setup and configuration.
Expand Down

0 comments on commit 6979116

Please sign in to comment.