all repos — site @ 2de52515831d6ff708bd3322c069ce627f52c4a1

source for my site, found at icyphox.sh

Speed up update_index.py using Jinja!

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Wed, 27 May 2020 12:31:59 +0530
commit

2de52515831d6ff708bd3322c069ce627f52c4a1

parent

f7f77ed567d733a126192ca526787cf066b7cdfd

M bin/update_index.pybin/update_index.py

@@ -1,68 +1,37 @@

#!/usr/bin/env python3 -from markdown2 import markdown_path import os -import fileinput -import sys +import frontmatter as fm +import jinja2 +from jinja2 import DebugUndefined -# change our cwd -os.chdir("bin") -blog = "../pages/blog/" +def get_metas(blog): + all_metas = [] + files = [ blog + f for f in os.listdir(blog) if f not in ["_index.md", "feed.xml"]] + for f in files: + with open(f) as fx: + meta, _ = fm.parse(fx.read()) + all_metas.append(meta) + + all_metas.sort(key=lambda x: x['date'], reverse=True) + return all_metas -print("this is going to take a while...") -print("you might as well serve the site!") -# order files by recency -def get_recents(path): - files = [path + f for f in os.listdir(blog) if f not in ["_index.md", "feed.xml"]] - files.sort( - key=lambda f: markdown_path(f, extras=["metadata"]).metadata["date"], - reverse=True, - ) - return files +def jinja_render(posts, tmpl): + template_loader = jinja2.FileSystemLoader("./") + env = jinja2.Environment(loader=template_loader, undefined=DebugUndefined) + try: + template = env.get_template(tmpl) + except jinja2.exceptions.TemplateNotFound: + print("error: template not found") - -def update_index(posts): - path = "../pages/_index.md" - with open(path, "r") as f: - md = f.readlines() - ruler = md.index("| :-- | --: |\n") - for post, i in zip(posts, range(5)): - md[ruler + i + 1] = post + "\n" - - with open(path, "w") as f: - f.writelines(md) - - -def update_blog(s): - path = "../pages/_index.md" - s = s + "\n" - with open(path) as f: - tempf = f.readlines() - - if s in tempf: - print("index has already been updated. quitting...") - sys.exit() - for l in fileinput.FileInput(path, inplace=1): - if "--:" in l: - l = l.replace(l, l + s) - print(l, end=""), + out = template.render(posts=posts) + return out -top_five = [] -metas = [] -lines = [] -fnames = [] - -for i in range(5): - top_five.append(get_recents(blog)[i]) - metas.append(markdown_path(get_recents(blog)[i], extras=["metadata"]).metadata) - fnames.append(os.path.basename(os.path.splitext(get_recents(blog)[i])[0])) - -for meta, fname in zip(metas, fnames): - url = "/blog/" + fname - new_line = f"| [{meta['title']}]({url}) | {meta['date']} |" - lines.append(new_line) - -update_blog(lines[0]) +if __name__ == "__main__": + all_metas = get_metas("pages/blog/") + rendered = jinja_render(all_metas, "templates/_index.html") + with open("templates/index.html", "w") as f: + f.write(rendered)
M config.pyconfig.py

@@ -54,5 +54,5 @@ </a>

</div> """ template = 'text.html' # default is index.html -pre_build = [['./bin/openring.py', '-j']] -post_build = ['./bin/rss.py', './bin/update_index.py'] +pre_build = [['./bin/openring.py', '-j'], './bin/update_index.py'] +post_build = ['./bin/rss.py']
M pages/_index.mdpages/_index.md

@@ -6,39 +6,3 @@ ---

# блог ([rss](/blog/feed.xml)) ## Computers, security & computer security. - -| | | -| :-- | --: | -| [The efficacy of deepfakes](/blog/efficacy-deepfakes) | 2020-05-11 | -| [Simplicity (mostly) guarantees security](/blog/simplicity-security) | 2020-05-07 | -| [The S-nail mail client](/blog/s-nail) | 2020-05-06 | -| [Stop joining mastodon.social](/blog/mastodon-social) | 2020-05-05 | -| [OpenBSD on the HP Envy 13](/blog/openbsd-hp-envy) | 2020-04-17 | -| [The Zen of KISS Linux](/blog/kiss-zen) | 2020-04-03 | -| [Introducing mael](/blog/mael) | 2020-03-29 | -| [COVID-19 disinformation](/blog/covid19-disinfo) | 2020-03-15 | -| [Nullcon 2020](/blog/nullcon-2020) | 2020-03-09 | -| [Setting up Prosody for XMPP](/blog/prosody) | 2020-02-18 | -| [Status update](/blog/2020-01-18) | 2020-01-18 | -| [Vimb: my Firefox replacement](/blog/mnml-browsing) | 2020-01-16 | -| [Five days in a TTY](/blog/five-days-tty) | 2020-01-13 | -| [2019 in review](/blog/2019-in-review) | 2020-01-02 | -| [Disinfo war: RU vs GB](/blog/ru-vs-gb) | 2019-12-12 | -| [Instagram OPSEC](/blog/ig-opsec) | 2019-12-02 | -| [Save .ORG!](/blog/save-org) | 2019-11-23 | -| [Status update](/blog/2019-11-16) | 2019-11-16 | -| [IRC for DMs](/blog/irc-for-dms) | 2019-11-03 | -| [The intelligence conundrum](/blog/intel-conundrum) | 2019-10-28 | -| [Hacky scripts](/blog/hacky-scripts) | 2019-10-24 | -| [Status update](/blog/2019-10-17) | 2019-10-16 | -| [PyCon India 2019 wrap-up](/blog/pycon-wrap-up) | 2019-10-15 | -| [Thoughts on digital minimalism](/blog/digital-minimalism) | 2019-10-05 | -| [Weekly status update](/blog/2019-09-27) |2019-09-27| -| [Weekly status update](/blog/2019-09-17) |2019-09-17| -| [Disinformation demystified](/blog/disinfo) |2019-09-10| -| [Setting up my personal mailserver](/blog/mailserver) |2019-08-15| -| [Picking the FB50 smart lock](/blog/fb50) |2019-08-06| -| [ROP on ARM32](/blog/rop-on-arm) |2019-06-06| -| [My Setup](/blog/my-setup) |2019-05-13| -| [Python for Reverse Engineering](/blog/python-for-re-1/)|2019-02-08| -
M pages/blog/feed.xmlpages/blog/feed.xml

@@ -1110,7 +1110,7 @@ quantify it. Perhaps I&#8217;ll log the number of reps × sets I do each time,

and with what weights. I can then look back to see if either the weights have increased since, or the number of reps × sets have. If you know of a better way to quantify progress, let me know! I&#8217;m pretty new to this.</p> -]]></description><link>https://icyphox.sh/blog/2020-01-18</link><pubDate>Sat, 18 Jan 2020 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2020-01-18</guid></item><item><title>Vimb: my Firefox replacement</title><description><![CDATA[<p>After having recently installed <a href="https://getkiss.org">KISS</a>, and +]]></description><link>https://icyphox.sh/blog/2020-01-18</link><pubDate>Sat, 18 Jan 2020 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2020-01-18</guid></item><item><title>Vimb&amp;#58; my Firefox replacement</title><description><![CDATA[<p>After having recently installed <a href="https://getkiss.org">KISS</a>, and building Firefox from source, I was exposed to the true monstrosity that Firefox&#8212;and web browsers in general&#8212;is. It took all of 9 hours to build the dependencies and then Firefox itself.</p>

@@ -1390,7 +1390,7 @@ <p>2019 was super productive! (in my terms). I learnt a lot of new things

last year, and I can only hope to learn as much in 2020. :)</p> <p>I&#8217;ll see you next week.</p> -]]></description><link>https://icyphox.sh/blog/2019-in-review</link><pubDate>Thu, 02 Jan 2020 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2019-in-review</guid></item><item><title>Disinfo war: RU vs GB</title><description><![CDATA[<p>This entire sequence of events begins with the attempted poisoning of +]]></description><link>https://icyphox.sh/blog/2019-in-review</link><pubDate>Thu, 02 Jan 2020 00:00:00 +0000</pubDate><guid>https://icyphox.sh/blog/2019-in-review</guid></item><item><title>Disinfo war&amp;#58; RU vs GB</title><description><![CDATA[<p>This entire sequence of events begins with the attempted poisoning of Sergei Skripal<sup class="footnote-ref" id="fnref-skripal"><a href="#fn-skripal">1</a></sup>, an ex-GRU officer who was a double-agent for the UK&#8217;s intelligence services. This hit attempt happened on the 4th of March, 2018. 8 days later, then-Prime Minister Theresa May formally
M pages/blog/mnml-browsing.mdpages/blog/mnml-browsing.md

@@ -1,6 +1,6 @@

--- template: -title: Vimb: my Firefox replacement +title: Vimb&#58; my Firefox replacement subtitle: Web browsing, suckless style date: 2020-01-16 url: mnml-browsing
M pages/blog/ru-vs-gb.mdpages/blog/ru-vs-gb.md

@@ -1,6 +1,6 @@

--- template: -title: Disinfo war: RU vs GB +title: Disinfo war&#58; RU vs GB subtitle: A look at Russian info ops against Britain date: 2019-12-12 url: ru-vs-gb
M static/style.cssstatic/style.css

@@ -35,7 +35,6 @@ color: var(--dark);

} .container { - padding-top: 1%; display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); min-width: 0;
A templates/_index.html

@@ -0,0 +1,47 @@

+<!DOCTYPE html> +<html lang=en> + <link rel="stylesheet" href="/static/style.css" type="text/css"> + <link rel="shortcut icon" type="images/x-icon" href="/static/favicon.ico"> + <link rel="alternate" type="application/rss+xml" title="RSS" href="https://icyphox.sh/blog/feed.xml"> + <meta name="description" content="{{ subtitle }}"> + <meta name="viewport" content="initial-scale=1"> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> + <meta charset="UTF-8"> + <meta content="#ffffff" name="theme-color"> + <meta name="HandheldFriendly" content="true"> + <meta name="twitter:card" content="summary_large_image"> + <meta name="twitter:site" content="@icyphox"> + <meta name="twitter:title" content="{{ title }}"> + <meta name="twitter:description" content="{{ subtitle }}"> + <meta name="twitter:image" content="/static/icyphox.png"> + <meta property="og:title" content="{{ title }}"> + <meta property="og:type" content="website"> + <meta property="og:description" content="{{ subtitle }}"> + <meta property="og:url" content="https://icyphox.sh"> + <meta property="og:image" content="/static/icyphox.png"> + + <title> + {{ title }} + </title> + <body> + <section class="container"> + <div class="pull-left"> + <div class="content"> + {{ body }} + <table> + <tbody> + {% 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 %} + </table> + </div> + </div> + <div class="pull-right"> + {{ footer }} + </div> + </section> + </body> +</html>
M templates/index.htmltemplates/index.html

@@ -2,6 +2,7 @@ <!DOCTYPE html>

<html lang=en> <link rel="stylesheet" href="/static/style.css" type="text/css"> <link rel="shortcut icon" type="images/x-icon" href="/static/favicon.ico"> + <link rel="alternate" type="application/rss+xml" title="RSS" href="https://icyphox.sh/blog/feed.xml"> <meta name="description" content="{{ subtitle }}"> <meta name="viewport" content="initial-scale=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

@@ -26,7 +27,170 @@ <body>

<section class="container"> <div class="pull-left"> <div class="content"> - {{ body }} + <table> + <tbody> + + <tr> + <td align="left"><a href="/blog/efficacy-deepfakes">The efficacy of deepfakes</a></td> + <td align="right">2020-05-11</td> + </tr> + + <tr> + <td align="left"><a href="/blog/simplicity-security">Simplicity (mostly) guarantees security</a></td> + <td align="right">2020-05-07</td> + </tr> + + <tr> + <td align="left"><a href="/blog/s-nail">The S-nail mail client</a></td> + <td align="right">2020-05-06</td> + </tr> + + <tr> + <td align="left"><a href="/blog/mastodon-social">Stop joining mastodon.social</a></td> + <td align="right">2020-05-05</td> + </tr> + + <tr> + <td align="left"><a href="/blog/openbsd-hp-envy">OpenBSD on the HP Envy 13</a></td> + <td align="right">2020-04-17</td> + </tr> + + <tr> + <td align="left"><a href="/blog/kiss-zen">The Zen of KISS Linux</a></td> + <td align="right">2020-04-03</td> + </tr> + + <tr> + <td align="left"><a href="/blog/mael">Introducing mael</a></td> + <td align="right">2020-03-29</td> + </tr> + + <tr> + <td align="left"><a href="/blog/covid19-disinfo">COVID-19 disinformation</a></td> + <td align="right">2020-03-15</td> + </tr> + + <tr> + <td align="left"><a href="/blog/nullcon-2020">Nullcon 2020</a></td> + <td align="right">2020-03-09</td> + </tr> + + <tr> + <td align="left"><a href="/blog/prosody">Setting up Prosody for XMPP</a></td> + <td align="right">2020-02-18</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2020-01-18">Status update</a></td> + <td align="right">2020-01-18</td> + </tr> + + <tr> + <td align="left"><a href="/blog/mnml-browsing">Vimb&#58; my Firefox replacement</a></td> + <td align="right">2020-01-16</td> + </tr> + + <tr> + <td align="left"><a href="/blog/five-days-tty">Five days in a TTY</a></td> + <td align="right">2020-01-13</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2019-in-review">2019 in review</a></td> + <td align="right">2020-01-02</td> + </tr> + + <tr> + <td align="left"><a href="/blog/ru-vs-gb">Disinfo war&#58; RU vs GB</a></td> + <td align="right">2019-12-12</td> + </tr> + + <tr> + <td align="left"><a href="/blog/ig-opsec">Instagram OPSEC</a></td> + <td align="right">2019-12-02</td> + </tr> + + <tr> + <td align="left"><a href="/blog/save-org">Save .ORG!</a></td> + <td align="right">2019-11-23</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2019-11-16">Status update</a></td> + <td align="right">2019-11-16</td> + </tr> + + <tr> + <td align="left"><a href="/blog/irc-for-dms">IRC for DMs</a></td> + <td align="right">2019-11-03</td> + </tr> + + <tr> + <td align="left"><a href="/blog/intel-conundrum">The intelligence conundrum</a></td> + <td align="right">2019-10-28</td> + </tr> + + <tr> + <td align="left"><a href="/blog/hacky-scripts">Hacky scripts</a></td> + <td align="right">2019-10-24</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2019-10-16">Status update</a></td> + <td align="right">2019-10-16</td> + </tr> + + <tr> + <td align="left"><a href="/blog/pycon-wrap-up">PyCon India 2019 wrap-up</a></td> + <td align="right">2019-10-15</td> + </tr> + + <tr> + <td align="left"><a href="/blog/digital-minimalism">Thoughts on digital minimalism</a></td> + <td align="right">2019-10-05</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2019-09-27">Weekly status update, 09/17–09/27</a></td> + <td align="right">2019-09-27</td> + </tr> + + <tr> + <td align="left"><a href="/blog/2019-09-17">Weekly status update, 09/08–09/17</a></td> + <td align="right">2019-09-17</td> + </tr> + + <tr> + <td align="left"><a href="/blog/disinfo">Disinformation demystified</a></td> + <td align="right">2019-09-10</td> + </tr> + + <tr> + <td align="left"><a href="/blog/mailserver">Setting up my personal mailserver</a></td> + <td align="right">2019-08-15</td> + </tr> + + <tr> + <td align="left"><a href="/blog/fb50.md">Picking the FB50 smart lock (CVE-2019-13143)</a></td> + <td align="right">2019-08-05</td> + </tr> + + <tr> + <td align="left"><a href="/blog/rop-on-arm">Return Oriented Programming on ARM (32-bit)</a></td> + <td align="right">2019-06-06</td> + </tr> + + <tr> + <td align="left"><a href="/blog/my-setup">My setup</a></td> + <td align="right">2019-05-13</td> + </tr> + + <tr> + <td align="left"><a href="/blog/python-for-re-1">Python for Reverse Engineering</a></td> + <td align="right">2019-02-08</td> + </tr> + + </table> </div> </div> <div class="pull-right">

@@ -34,4 +198,4 @@ {{ footer }}

</div> </section> </body> -</html> +</html>
M templates/text.htmltemplates/text.html

@@ -48,30 +48,32 @@ <hr>

<div class="openring"> <div class="openring-feed"> - <h4>May 25, 2020 <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> + <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> - <p>via <a href="https://www.bellingcat.com">bellingcat</a></p> + <p>via <a href="https://gru.gq">grugq’s domain</a></p> </div> <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>May 09, 2020 <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://gru.gq">grugq’s domain</a></p> + <p>via <a href="https://peppe.rs">nerdypepper's μblog</a></p> </div> <div class="openring-feed"> - <h4>May 15, 2020 <a href="https://drewdevault.com/2020/05/15/Status-update.html">Status update, May 2020</a></h4> - <p>Hello, future readers! I am writing to you from one day in the past. I finished -my plans for today early and thought I’d get a head start on writing the status -updates for tomorrow, or rather, for today. From your reference frame, that is. - -Let’s start wit…</p> + <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> - <p>via <a href="https://drewdevault.com">Drew DeVault's Blog</a></p> + <p>via <a href="https://jcs.org/">joshua stein</a></p> </div>