forked from DIAGNijmegen/website-content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_content.py
54 lines (37 loc) · 1.71 KB
/
parse_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
54
import os
import glob
import shutil
import sys
directories = ['members', 'news', 'presentations', 'projects', 'software', 'vacancies', 'calendar', 'publications', 'research']
site = sys.argv[1]
group_name = site[8:]
print(f"Copying content for {site} (group: {group_name})")
for dir in directories:
output_dir = os.path.join(site, dir)
if not os.path.isdir(output_dir):
os.mkdir(output_dir)
for dir in directories:
files = glob.glob(os.path.join('content', 'pages', dir, '*.md'))
for file_path in files:
filename = os.path.basename(file_path)
with open(file_path) as file:
try:
for line in file:
if 'groups:' in line:
groups = line.split(':')[1].replace(' ','').rstrip().split(',')
# Check if the content belongs to the current website
if group_name in groups:
if dir == 'news':
# Write hightlights to directory out of pages dir
out_dir = os.path.join(site, 'content', dir)
else:
out_dir = os.path.join(site, 'content', 'pages', dir)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
shutil.copyfile(file_path, os.path.join(out_dir, filename))
# Stop parsing file
break
except Exception as e:
print(f"Error parsing {file_path}.")
print(e)
print(f'Copied pages to {site}.')