forked from scout-ch/cudeschin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_content.py
executable file
·53 lines (40 loc) · 1.18 KB
/
import_content.py
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
#!/usr/bin/env python3
import os
import json
import fnmatch
SOURCE_DIR = 'content'
OUTPUT = 'src/assets/articles.json'
def load():
articles = []
files = os.listdir(SOURCE_DIR)
markdown_files = [f for f in files if fnmatch.fnmatch(f, '*.md')]
markdown_files.sort()
for article in markdown_files:
with open(os.path.join(SOURCE_DIR, article)) as f:
content = f.read()
title = content.splitlines()[0]
slug = article[3:-3].lower()
img_name = article.replace('.md', '.jpg')
img = os.path.join('images', 'titles', img_name)
articles.append({
"title": title,
"slug": slug,
"img": img,
"content": content,
})
return articles
def overview(articles):
print()
print('IMPORTIERTE INHALTE')
print('###################')
print()
for a in articles:
print('- %s' % a['slug'])
print()
def export(articles):
with open(OUTPUT, 'w') as output:
json.dump(articles, output, indent=4, ensure_ascii=False)
if __name__ == '__main__':
articles = load()
overview(articles)
export(articles)