Skip to content

Commit 8ff4438

Browse files
normalize filenames
1 parent 729e7e2 commit 8ff4438

File tree

63 files changed

+62
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+62
-12
lines changed

docs/_draft/generalized-wire-cellular-automata/index.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

markdown/pickle_tokenizer_js.md renamed to markdown/0039_pickle_tokenizer.md

+1-1

markdown/boost_converter.md renamed to markdown/0041_not_your_daddy_s_boost_converter.md

+1-1

markdown/pickle_pattern.md renamed to markdown/0042_powerful_pickle_pattern_matching.md

+1-1

markdown/out_of_memory.md renamed to markdown/0043_error_out_of_memory.md

+1-1

markdown/pickle_is_a_regex.md renamed to markdown/0044_pickle_has_regular_expressions_apparently.md

+1-1

markdown/if_not_tree.md renamed to markdown/0048_zero_thickness_tree.md

+1-1

markdown/pickle_bytecode.md renamed to markdown/0051_the_lesser_of_two_evils.md

+1-1

markdown/generalized_wire.md renamed to markdown/draft_0003_generalized_wire_cellular_automata.md

+3-3

markdown/normalize_filenames.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import glob
2+
import datetime
3+
import html
4+
import os
5+
import pprint
6+
import string
7+
import re
8+
9+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
10+
11+
files = glob.glob("*.md")
12+
13+
dates = {}
14+
draft_dates = {}
15+
16+
17+
def slugify(s: str):
18+
return re.sub(fr"[\s{re.escape(string.punctuation)}]+", "_",
19+
html.unescape(s).lower()).strip("_")
20+
21+
assert slugify("Hello, World!") == "hello_world"
22+
23+
for file in files:
24+
date = None
25+
is_draft = False
26+
title = ""
27+
with open(file) as f:
28+
for line in f:
29+
lLine = line.lower().strip()
30+
if lLine.startswith("date:"):
31+
date = datetime.date.fromisoformat(
32+
lLine.removeprefix("date:").strip())
33+
if lLine == "status: draft":
34+
is_draft = True
35+
if lLine.startswith("title:"):
36+
title = line[6:].strip()
37+
if is_draft:
38+
draft_dates[file] = (date, slugify(title))
39+
else:
40+
dates[file] = (date, slugify(title))
41+
42+
old2new = {n: f"{i+1:04d}_{t}.md" for i, (n, (d, t)) in
43+
enumerate(sorted(dates.items(),
44+
key=lambda file: dates[file[0]][0]))}
45+
old2new_drafts = {n: f"draft_{i+1:04d}_{t}.md" for i, (n, (d, t)) in
46+
enumerate(sorted(draft_dates.items(),
47+
key=lambda file: draft_dates[file[0]][0]))}
48+
49+
for a, b in sorted((old2new | old2new_drafts).items()):
50+
os.rename(a, b)

0 commit comments

Comments
 (0)