Site changes post Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Wed, 27 May 2020 21:36:32 +0530
5 files changed,
227 insertions(+),
16 deletions(-)
M
bin/openring.py
→
bin/openring.py
@@ -39,10 +39,10 @@ post_link = fp.entries[0].link
post_title = fp.entries[0].title html_out.append(f"""<div class="openring-feed"> - <h4>{pretty_date} <a href="{post_link}">{post_title}</a></h4> + <h4><a href="{post_link}">{post_title}</a></h4> <p>{trunc_summ}</p> - <p>via <a href="{feed_link}">{feed_title}</a></p> + <p>via <a href="{feed_link}">{feed_title}</a> on {pretty_date}</p> </div> """ )
M
pages/blog/feed.xml
→
pages/blog/feed.xml
@@ -11,7 +11,109 @@ <link>https://icyphox.sh/</link>
</image> <language>en-us</language> <copyright>Creative Commons BY-NC-SA 4.0</copyright> - <item><title>The efficacy of deepfakes</title><description><![CDATA[<p>A few days back, NPR put out an article discussing why deepfakes aren’t + <item><title>Site changes</title><description><![CDATA[<p>The past couple of days, I’ve spent a fair amount of time tweaking this +site. My site’s build process involves +<a href="https://github.com/icyphox/vite">vite</a> and a bunch of +<a href="https://github.com/icyphox/site/tree/master/bin">scripts</a>. These +scripts are executed via vite’s pre- and post-build actions. The big +changes that were made were performance improvements in the +<code>update_index.py</code> script, and the addition of <code>openring.py</code>, which you +can see at the very bottom of this post!</p> + +<h2 id="speeding-up-index-page-generation">speeding up index page generation</h2> + +<p>The old script—the one that featured in <a href="/blog/hacky-scripts">Hacky +scripts</a>—was absolutely ridiculous, and not to +mention <em>super</em> slow. Here’s what it did:</p> + +<ul> +<li>got the most recent file (latest post) by sorting all posts by +<code>mtime</code>.</li> +<li>parsed the markdown frontmatter and created a markdown table entry +like: </li> +</ul> + +<div class="codehilite"><pre><span></span><code><span class="n">line</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"| [</span><span class="si">{</span><span class="n">meta</span><span class="p">[</span><span class="s1">'title'</span><span class="p">]</span><span class="si">}</span><span class="s2">](</span><span class="si">{</span><span class="n">url</span><span class="si">}</span><span class="s2">) | `</span><span class="si">{</span><span class="n">meta</span><span class="p">[</span><span class="s1">'date'</span><span class="p">]</span><span class="si">}</span><span class="s2">` |"</span> +</code></pre></div> + +<ul> +<li>updated the markdown table (in <code>_index.md</code>) by in-place editing the +markdown, with the line created earlier—for the latest post.</li> +<li>finally, I’d have to <em>rebuild</em> the entire site since this markdown +hackery would happen at the very end of the build, i.e, didn’t +actually get rendered itself. </li> +</ul> + +<p>That…probably didn’t make much sense to you, did it? Don’t bother. +I don’t know what I was thinking when I wrote that mess. So with how it +<em>was</em> done aside, here’s how it’s done now:</p> + +<ul> +<li>the metadata for all posts are nicely fetched and sorted using +<code>python-frontmatter</code>.</li> +<li>the metadata list is fed into Jinja for use in templating, and is +rendered very nicely using a simple <code>for</code> expression:</li> +</ul> + +<pre><code>{% for p in posts %} + <tr> + <td align="left"><a href="/blog/{{ p.url }}">{{ p.title }}</a></td> + <td align="right">{{ p.date }}</td> + </tr> +{% endfor %} +</code></pre> + +<p>A neat thing I learnt while working with Jinja, is you can use +<code>DebugUndefined</code> in your <code>jinja2.Environment</code> definition to ignore +uninitialized template variables. Jinja’s default behaviour is to remove +all uninitialized variables from the template output. So for instance, +if you had:</p> + +<div class="codehilite"><pre><span></span><code><span class="p"><</span><span class="nt">body</span><span class="p">></span> + {{ body }} +<span class="p"></</span><span class="nt">body</span><span class="p">></span> + +<span class="p"><</span><span class="nt">footer</span><span class="p">></span> + {{ footer }} +<span class="p"></</span><span class="nt">footer</span><span class="p">></span> +</code></pre></div> + +<p>And only <code>{{ body }}</code> was initialized in your <code>template.render(body=body)</code>, +the output you get would be:</p> + +<div class="codehilite"><pre><span></span><code><span class="p"><</span><span class="nt">body</span><span class="p">></span> + Hey there! +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"><</span><span class="nt">footer</span><span class="p">></span> + +<span class="p"></</span><span class="nt">footer</span><span class="p">></span> +</code></pre></div> + +<p>This is annoying if you’re attempting to generate your template across +multiple stages, as I was. Now, I initialize my Jinja environment like +so:</p> + +<div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">jinja2</span> <span class="kn">import</span> <span class="n">DebugUndefined</span> + +<span class="n">env</span> <span class="o">=</span> <span class="n">jinja2</span><span class="o">.</span><span class="n">Environment</span><span class="p">(</span><span class="n">loader</span><span class="o">=</span><span class="n">template_loader</span><span class="p">,</span><span class="n">undefined</span><span class="o">=</span><span class="n">DebugUndefined</span><span class="p">)</span> +</code></pre></div> + +<p>I use the same trick for <code>openring.py</code> too. Speaking of…let’s talk +about <code>openring.py</code>!</p> + +<h2 id="the-new-webring-thing-at-the-bottom">the new webring thing at the bottom</h2> + +<p>After having seen Drew’s <a href="https://git.sr.ht/~sircmpwn/openring">openring</a>, +my <a href="https://en.wikipedia.org/wiki/Not_invented_here">NIH</a> kicked in and I wrote +<a href="https://github.com/icyphox/openring.py"><code>openring.py</code></a>. It pretty much +does the exact same thing, except it’s a little more composable with +vite. Currently, it reads a random sample of 3 feeds from a list of +feeds provided in a <code>feeds.txt</code> file, and updates the webring with those +posts. Like a feed-bingo of sorts. ;)</p> + +<p>I really like how it turned out—especially the fact that I got my CSS +grid correct in the first try!</p> +]]></description><link>https://icyphox.sh/blog/site-changes</link><pubDate>Wed, 27 May 2020 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/site-changes</guid></item><item><title>The efficacy of deepfakes</title><description><![CDATA[<p>A few days back, NPR put out an article discussing why deepfakes aren’t all that powerful in spreading disinformation. <a href="https://www.npr.org/2020/05/07/851689645/why-fake-video-audio-may-not-be-as-powerful-in-spreading-disinformation-as-feare">Link to article</a>.</p>
A
pages/blog/site-changes.md
@@ -0,0 +1,108 @@
+--- +template: +url: site-changes +title: Site changes +subtitle: New stuff at the {back,front}end +date: 2020-05-27 +--- + +The past couple of days, I've spent a fair amount of time tweaking this +site. My site's build process involves +[vite](https://github.com/icyphox/vite) and a bunch of +[scripts](https://github.com/icyphox/site/tree/master/bin). These +scripts are executed via vite's pre- and post-build actions. The big +changes that were made were performance improvements in the +`update_index.py` script, and the addition of `openring.py`, which you +can see at the very bottom of this post! + +## speeding up index page generation + +The old script---the one that featured in [Hacky +scripts](/blog/hacky-scripts)---was absolutely ridiculous, and not to +mention _super_ slow. Here's what it did: + +- got the most recent file (latest post) by sorting all posts by + `mtime`. +- parsed the markdown frontmatter and created a markdown table entry + like: + +```python +line = f"| [{meta['title']}]({url}) | `{meta['date']}` |" +``` +- updated the markdown table (in `_index.md`) by in-place editing the + markdown, with the line created earlier---for the latest post. +- finally, I'd have to _rebuild_ the entire site since this markdown + hackery would happen at the very end of the build, i.e, didn't + actually get rendered itself. + +That...probably didn't make much sense to you, did it? Don't bother. +I don't know what I was thinking when I wrote that mess. So with how it +_was_ done aside, here's how it's done now: + +- the metadata for all posts are nicely fetched and sorted using + `python-frontmatter`. +- the metadata list is fed into Jinja for use in templating, and is + rendered very nicely using a simple `for` expression: + +``` +{% for p in posts %} + <tr> + <td align="left"><a href="/blog/{{ p.url }}">{{ p.title }}</a></td> + <td align="right">{{ p.date }}</td> + </tr> +{% endfor %} +``` + +A neat thing I learnt while working with Jinja, is you can use +`DebugUndefined` in your `jinja2.Environment` definition to ignore +uninitialized template variables. Jinja's default behaviour is to remove +all uninitialized variables from the template output. So for instance, +if you had: + +```html +<body> + {{ body }} +</body> + +<footer> + {{ footer }} +</footer> +``` + +And only `{{ body }}` was initialized in your `template.render(body=body)`, +the output you get would be: + +```html +<body> + Hey there! +</body> +<footer> + +</footer> +``` + +This is annoying if you're attempting to generate your template across +multiple stages, as I was. Now, I initialize my Jinja environment like +so: + +```python +from jinja2 import DebugUndefined + +env = jinja2.Environment(loader=template_loader,undefined=DebugUndefined) +``` + +I use the same trick for `openring.py` too. Speaking of...let's talk +about `openring.py`! + +## the new webring thing at the bottom + +After having seen Drew's [openring](https://git.sr.ht/~sircmpwn/openring), +my [NIH](https://en.wikipedia.org/wiki/Not_invented_here) kicked in and I wrote +[`openring.py`](https://github.com/icyphox/openring.py). It pretty much +does the exact same thing, except it's a little more composable with +vite. Currently, it reads a random sample of 3 feeds from a list of +feeds provided in a `feeds.txt` file, and updates the webring with those +posts. Like a feed-bingo of sorts. ;) + +I really like how it turned out---especially the fact that I got my CSS +grid correct in the first try!
M
templates/index.html
→
templates/index.html
@@ -27,8 +27,14 @@ <body>
<section class="container"> <div class="pull-left"> <div class="content"> + {{ body }} <table> <tbody> + + <tr> + <td align="left"><a href="/blog/site-changes">Site changes</a></td> + <td align="right">2020-05-27</td> + </tr> <tr> <td align="left"><a href="/blog/efficacy-deepfakes">The efficacy of deepfakes</a></td>
M
templates/text.html
→
templates/text.html
@@ -48,32 +48,27 @@ <hr>
<div class="openring"> <div class="openring-feed"> - <h4>May 08, 2020 <a href="https://gru.gq/2020/05/08/zoom-keybase/">Zoom + Keybase</a></h4> - <p>There is an opportunity here to signal that Zoom is not a Chinese asset. Zoom can effectively remove itself from the board by completely mitigating passive surveillance. When no state’s intelligence agency benefits from a home field advantage with Zoom, th…</p> + <h4><a href="https://www.bellingcat.com/resources/2020/05/25/investigate-tiktok-like-a-pro/">Investigate TikTok Like A Pro!</a></h4> + <p>TikTok videos have grown increasingly popular over the last few years, with short clips showing people dancing, lip syncing, doing viral challenges, and so on. This relatively new platform lets users share short video clips, and can be looped. It is simila…</p> - <p>via <a href="https://gru.gq">grugq’s domain</a></p> + <p>via <a href="https://www.bellingcat.com">bellingcat</a> on May 25, 2020</p> </div> <div class="openring-feed"> - <h4>May 09, 2020 <a href="https://peppe.rs/posts/auto-currying_rust_functions/">Auto-currying Rust Functions</a></h4> + <h4><a href="https://peppe.rs/posts/auto-currying_rust_functions/">Auto-currying Rust Functions</a></h4> <p>This post contains a gentle introduction to procedural macros in Rust and a guide to writing a procedural macro to curry Rust functions. The source code for the entire library can be found here. It is also available on crates.io. The following links might …</p> - <p>via <a href="https://peppe.rs">nerdypepper's μblog</a></p> + <p>via <a href="https://peppe.rs">nerdypepper's μblog</a> on May 09, 2020</p> </div> <div class="openring-feed"> - <h4>May 15, 2020 <a href="https://jcs.org/2020/05/15/surface_go2">OpenBSD on the Microsoft Surface Go 2 (notaweblog)</a></h4> - <p>I used OpenBSD on the -original Surface Go -back in 2018 and many things worked with the big exception of the internal -Atheros WiFi. -This meant I had to keep it tethered to a USB-C dock for Ethernet or use -a small USB-A WiFi dongle plugged into a less-than-…</p> + <h4><a href="https://gru.gq/2020/05/08/zoom-keybase/">Zoom + Keybase</a></h4> + <p>There is an opportunity here to signal that Zoom is not a Chinese asset. Zoom can effectively remove itself from the board by completely mitigating passive surveillance. When no state’s intelligence agency benefits from a home field advantage with Zoom, th…</p> - <p>via <a href="https://jcs.org/">joshua stein</a></p> + <p>via <a href="https://gru.gq">grugq’s domain</a> on May 08, 2020</p> </div>