Skip to content

Commit 3809b7c

Browse files
committed
feat: replace asciicast scripts with clickable SVG previews in Nix, Podman, and Ricing posts
1 parent ebff024 commit 3809b7c

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

eleventy.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ const curriculumPath = path.join(process.cwd(), "src", "_data", "curriculum.json
1717
const curriculum = JSON.parse(fs.readFileSync(curriculumPath, "utf-8"));
1818
const flatSlugs = curriculum.flatMap(m => m.slugs);
1919

20+
function injectAsciinemaEmbeds(content) {
21+
const asciicastLinkPattern = /<a\s+([^>]*?)href="https:\/\/asciinema\.org\/a\/([A-Za-z0-9_-]+)"([^>]*)>\s*<img\s+([^>]*?)alt="asciicast"([^>]*?)>\s*<\/a>/gi;
22+
23+
return content.replace(asciicastLinkPattern, (match, _preHrefAttrs, castId) => {
24+
const scriptPattern = new RegExp(
25+
`<script\\s+src="https:\\/\\/asciinema\\.org\\/a\\/${castId}\\.js"\\s+id="asciicast-${castId}"[\\s\\S]*?<\\/script>`,
26+
"i"
27+
);
28+
29+
if (scriptPattern.test(content)) {
30+
return "";
31+
}
32+
33+
return `<script src="https://asciinema.org/a/${castId}.js" id="asciicast-${castId}" async="true"></script>`;
34+
});
35+
}
36+
2037
export default function(eleventyConfig) {
2138
eleventyConfig.addPassthroughCopy("src/style.css");
2239
eleventyConfig.addPassthroughCopy("src/assets");
@@ -119,6 +136,14 @@ export default function(eleventyConfig) {
119136
return `Next we'll look at **[${nextTitle}](${nextUrl})**!`;
120137
});
121138

139+
eleventyConfig.addTransform("asciinemaEmbeds", (content, outputPath) => {
140+
if (!outputPath || !outputPath.endsWith(".html")) {
141+
return content;
142+
}
143+
144+
return injectAsciinemaEmbeds(content);
145+
});
146+
122147
return {
123148
pathPrefix: "/steam-deck/",
124149
markdownTemplateEngine: "njk",

src/posts/nix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Nix works a bit differently than other package managers. The easiest way to use
5656
## 🎥 See it in Action
5757
Want to see Nix magic in real-time? Check out this demo of running an app without installing it:
5858

59-
<script src="https://asciinema.org/a/zu1z4m8iLeSZiaRv.js" id="asciicast-zu1z4m8iLeSZiaRv" async="true"></script>
59+
[![asciicast](https://asciinema.org/a/zu1z4m8iLeSZiaRv.svg)](https://asciinema.org/a/zu1z4m8iLeSZiaRv)
6060

6161
## Optional Fix: Perl Apps and glibcLocales
6262
Most people can skip this. You usually only need this if you're running Perl software through Nix (like `cowsay`) and you see locale-related errors.

src/posts/podman.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Podman will download a tiny image, run it, and print a message. All without need
3333
## 🎥 See it in Action
3434
Check out how fast Podman starts up and runs a container!
3535

36-
<script src="https://asciinema.org/a/6QpATU4wRtFkFPW0.js" id="asciicast-6QpATU4wRtFkFPW0" async="true"></script>
36+
[![asciicast](https://asciinema.org/a/6QpATU4wRtFkFPW0.svg)](https://asciinema.org/a/6QpATU4wRtFkFPW0)
3737

3838
## Cool Things to do with Podman
3939
While most gamers won't need Podman daily, it opens up some amazing possibilities. The best example? **Hosting your own game servers directly on your Deck.**
@@ -56,7 +56,7 @@ podman run -d -it -p 25565:25565 -e EULA=TRUE -v ~/minecraft-data:/data --name m
5656

5757
To stop the server later, just type `podman stop mc-server`. To start it again, `podman start mc-server`. It’s that easy!
5858

59-
<script src="https://asciinema.org/a/qo924SpN5D5TBh68.js" id="asciicast-qo924SpN5D5TBh68" async="true"></script>
59+
[![asciicast](https://asciinema.org/a/qo924SpN5D5TBh68.svg)](https://asciinema.org/a/qo924SpN5D5TBh68)
6060

6161
### More Awesome Game Servers for Podman
6262

src/posts/ricing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fastfetch
8080

8181
**[btop](https://github.com/aristocratos/btop)** is a system monitor that looks like it belongs on the bridge of a starship. It shows CPU, memory, disk, network, and running processes — all in real time with beautiful graphs and color themes.
8282

83-
<script src="https://asciinema.org/a/SigmzvU4M4mT4nYl.js" id="asciicast-SigmzvU4M4mT4nYl" async="true"></script>
83+
[![asciicast](https://asciinema.org/a/SigmzvU4M4mT4nYl.svg)](https://asciinema.org/a/SigmzvU4M4mT4nYl)
8484

8585
Good news — **btop is already installed on SteamOS!** Just open Konsole and run:
8686
```bash

0 commit comments

Comments
 (0)