blob: 09a57f8171a0dc1b4ae0b0771b48187a664203c2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/usr/bin/env python3
#
# SPDX-License-Identifier: ISC
#
# Copyright © 2019 Free Software Foundation of India.
#
import datetime
import os
import re
import sys
# placeholders
PH = {
'title': '<!-- NEWS-ITEM-TITLE -->',
'date': '<!-- DATE -->',
'content': '<!-- MAIN-CONTENT -->',
}
def err(s):
print('Error: {}'.format(s))
sys.exit(1)
def files():
return os.scandir('md/news')
def read(f):
with open(f) as f:
c = f.read()
return c
def slug(p):
m = re.search(r'([a-zA-Z\-]+)\.md', p)
if not m:
err('Unable to get slug')
return m.group(1)
def title(c):
m = re.search(r'^\# (.+)$', c, re.M)
if not m:
err('Title not found')
return m.group(1)
def date(c):
m = re.search(r'pubdate: ([0-9]{8})', c)
if not m:
err('Publication date not found')
return m.group(1)
def content(c):
m = re.search(r'^\# (.+)$', c, re.M)
if not m:
err('Unable to slurp content')
return c[m.end():]
def template(type):
return read('templates/{}.html'.format(type))
def datefmt(d):
return datetime.datetime.strptime(d, '%Y%m%d').strftime('%B %d, %Y')
def process(f):
c = read(f.path)
t = title(c)
d = date(c)
c = content(c)
def run():
for f in files():
process(f)
if __name__ == "__main__":
run()
|