all repos — site @ 4e106f3e0a879cac0dd967563e253933dd5e9e13

source for my site, found at icyphox.sh

bin/update_index.py: Latest 4 posts on index

Signed-off-by: Anirudh Oppiliappan <x@icyphox.sh>
Anirudh Oppiliappan x@icyphox.sh
Tue, 29 Oct 2019 21:09:06 +0530
commit

4e106f3e0a879cac0dd967563e253933dd5e9e13

parent

52620b9a0596c383121cdf539501b7d76ea75200

3 files changed, 32 insertions(+), 21 deletions(-)

jump to
M bin/update_index.pybin/update_index.py

@@ -10,19 +10,23 @@ os.chdir("bin")

blog = "../pages/blog/" -# bunch of file hacks to get to the most recent file -def getrecent(path): +# order files by recency +def getrecents(path): files = [path + f for f in os.listdir(blog) if f not in ["_index.md", "feed.xml"]] - files.sort(key=os.path.getmtime, reverse=True) - return files[0] + files.sort( + key=lambda f: markdown_path(f, extras=["metadata"]).metadata["date"], + reverse=True, + ) + return files -def update_index(s): +def update_index(posts): path = "../pages/_index.md" with open(path, "r") as f: md = f.readlines() ruler = md.index("| --- | --: |\n") - md[ruler + 1] = s + "\n" + for post, i in zip(posts, range(4)): + md[ruler + i + 1] = post + "\n" with open(path, "w") as f: f.writelines(md)

@@ -37,11 +41,19 @@ l = l.replace(l, l + s)

print(l, end=""), -# fetch title and date -meta = markdown_path(getrecent(blog), extras=["metadata"]).metadata -fname = os.path.basename(os.path.splitext(getrecent(blog))[0]) -url = "/blog/" + fname -line = f"| [{meta['title']}]({url}) | `{meta['date']}` |" +top_four = [] +metas = [] +lines = [] +fnames = [] + +for i in range(4): + top_four.append(getrecents(blog)[i]) + metas.append(markdown_path(getrecents(blog)[i], extras=["metadata"]).metadata) + fnames.append(os.path.basename(os.path.splitext(getrecents(blog)[i])[0])) + +for meta, fname in zip(metas, fnames): + url = "/blog/" + fname + lines.append(f"| [{meta['title']}]({url}) | `{meta['date']}` |") -update_index(line) -update_blog(line) +update_index(lines) +update_blog(lines[0])
M pages/_index.mdpages/_index.md

@@ -20,18 +20,17 @@ Want to contact me? The best way is via email, at [x@icyphox.sh](mailto:x@icyphox.sh)

or [Twitter](https://twitter.com/icyphox) DMs. Or if you prefer IRC, I'm `icy` / `icyphox` on Rizon and Freenode. -# latest post +# latest posts ([see all](/blog)) | | | | --- | --: | | [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` | -([see all](/blog)) - -# currently reading +# currently reading ([see all](/reading)) [Kakegurui](https://myanimelist.net/manga/73603/Kakegurui) -started **15th October, 2019** - -([see all](/reading)) +*still reading* | started **15th October, 2019**
M pages/reading.mdpages/reading.md

@@ -8,7 +8,7 @@ # чтение журнала

## I read very infrequently, this might never get updated. [Kakegurui](https://myanimelist.net/manga/73603/Kakegurui) -started **15th October, 2019** +*still reading* | started **15th October, 2019** [Another](https://myanimelist.net/manga/24098/Another) started **12th October, 2019** | opinion: *pretty eh; not scary :/*