From 1ce235f959ba7ef352134f16c4030504ae557230 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 25 Jul 2020 20:34:46 -0400 Subject: bin/html: detect i18n files * bin/html (slug): Add regex to identify ISO 639-1 string in file name. Return a tuple containing the file 'slug' and the IS0 639-1 string. The second element of the tuple is None when ISO 639-1 string is not found in the file name. (html): Read ISO 639-1 string into `l` and return it as the third element. (process): Add handling to write localized version at `SLUG/XX` where `XX` is a ISO 639-1 string. --- bin/html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'bin/html') diff --git a/bin/html b/bin/html index 1c896b9..4ada99f 100644 --- a/bin/html +++ b/bin/html @@ -73,12 +73,12 @@ def write(p, c): def slug(p): - m = re.search(r'([a-zA-Z\-]+)\.md', p) + m = re.search(r'([a-zA-Z\-]+)(\.([a-z]{2}))?\.md', p) if not m: err('Unable to get slug') - return m.group(1) + return m.group(1, 3) def title(c): @@ -140,7 +140,7 @@ def markdown(c): def html(sec, f): c = read(f.path) - s = slug(f.path) + s, l = slug(f.path) t = title(c) a = author(c) @@ -155,13 +155,16 @@ def html(sec, f): if author: h = h.replace(PH['author'], a, 1) - return s, h + return s, h, l def process(sec): for f in files(sec): - s, h = html(sec, f) - write('/'.join(['_build', sec, s, 'index.html']), h) + s, h, l = html(sec, f) + if not l: + write('/'.join(['_build', sec, s, 'index.html']), h) + else: + write('/'.join(['_build', sec, s, l, 'index.html']), h) def run(): -- cgit v1.2.3