From f32b9f8e6f541c038a47381e93ef03c2a6c2c2e2 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 25 Jul 2020 21:51:36 -0400 Subject: bin/feed: add i18n handling * bin/feed (slug): Add regex to detect ISO 639-1 string. Return unique name, slug and the ISO 639-1 string. The third value returned is None when is there no ISO 639- string in the file name. (elink): Add argument `l` -- ISO 639-1 string. Append it to the URL if it is not None. (entry): Update slug and elink calls. --- bin/feed | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bin/feed b/bin/feed index 8c3e82d..69dff74 100644 --- a/bin/feed +++ b/bin/feed @@ -77,12 +77,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), m.group(2), m.group(4) def template(type): @@ -98,8 +98,11 @@ def title(c): return m.group(1) -def elink(sec, s): - return '/'.join([URL, sec, s]) +def elink(sec, s, l): + if l is None: + return '/'.join([URL, sec, s]) + else: + return '/'.join([URL, sec, s, l]) def flink(sec): @@ -159,15 +162,15 @@ def now(): def entry(sec, f): c = read(f.path) - s = slug(f.path) + u, s, l = slug(f.path) t = time(c) - id = t + ':' + s + id = t + ':' + u e = template('entry') e = e.replace(E_PH['id'], id, 1) e = e.replace(E_PH['title'], title(c), 1) - e = e.replace(E_PH['link'], elink(sec, s), 1) + e = e.replace(E_PH['link'], elink(sec, s, l), 1) e = e.replace(E_PH['updated'], t, 1) e = e.replace(E_PH['content'], content(c), 1) -- cgit v1.2.3