summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-07-25 20:34:46 -0400
committerrsiddharth <s@ricketyspace.net>2020-07-25 20:34:46 -0400
commit1ce235f959ba7ef352134f16c4030504ae557230 (patch)
treef14c276130794d18d503e6d6f30f1667f8ea07b8 /bin
parent08c970ce413dd7159b32b89943f29256d9cc8ae0 (diff)
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/html15
1 files changed, 9 insertions, 6 deletions
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():