tentative micro framework for a new website, potentially some day
[nepi.git] / website / meta.py
1 #!/usr/bin/env python3
2
3 import json
4 import glob
5
6
7 # I prefer writing python code rather than JSON natively
8 # plus, this might be the place to inject subindexes for the tutorials page some day
9
10 hard_wired_meta = {
11    # '*' means this is visible to all input files unless overridden
12    # in a more specific location
13    '*' : { 'logos_height': '18px'}
14    }
15
16 title_header = 'title:'
17
18 def tuto_contents(md):
19    """
20    input is a markdown filename
21    which is expected to define title:
22    output is a tuple (name, title)
23    with name having its '.md' removed
24    and title being said title
25    """
26    basename = md.replace('.md', '')
27    title = 'No title set'
28    with open(md) as input:
29       for line in input.readlines():
30          if line.startswith(title_header):
31             title = line[len(title_header):].strip()
32    return (basename, title)
33
34 def main():
35
36    meta = hard_wired_meta
37    
38    # enrich it
39    # get the list of tutorials
40    tuto_files = glob.glob("tuto*.md")
41    # make sure the '*' key is present
42    wildcard = meta.setdefault('*', None)
43    wildcard['tutos'] = [ tuto_contents(tf) for tf in tuto_files]
44
45    # save
46    with open('markdown/meta.json', 'w') as output:
47       json.dump(meta, output)
48
49    
50 if __name__ == '__main__':
51    main()