micropost: 27 July 2025

This commit is contained in:
Ming Di Leom 2025-07-27 06:39:01 +00:00
parent 4d797debcc
commit 798c54ae4d
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
---
title: Separate markdown headings into pages
date: 2025-07-27
---
Previously the [Threat Hunting](/threat-hunting/) page contained all search queries in one page separated by headings. That approach was untidy especially when conducting a web search; where after being redirected to the threat hunting page, still had to navigate to the relevant heading to locate the relevant search query.
Each heading or search query is now in a [separate page](https://gitlab.com/curben/blog/-/commit/4922492c959627fe7beeb678c13e29efee79b540), so once those new pages are indexed by search engine, the search result will lead directly to a page that only contains the relevant search query, e.g. [FileFix detection](/threat-hunting/filefix-detection).
```py
from os import chdir, path
from re import S, findall, sub
chdir(path.dirname(__file__))
template = """---
title: {title}
layout: page
date: 2025-07-27
---
{content}"""
with open("index.md") as f:
s = f.read()
# https://stackoverflow.com/a/66619938
for title, content in findall(r"(?:^|\n)##\s([^\n]+)\n(.*?)(?=\n##?\s|$)", s, S):
# https://stackoverflow.com/a/74260791
fname = sub(r"\W+", "-", title).strip("-").lower()
with open(fname + ".md", "w") as w:
w.write(template.format(title=title, content=content))
with open("index-new.md", "a") as a:
a.write(f"- [{title}]({fname})\n")
```