missing
[nepi.git] / website / index.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 # computes an index file in markdown/index.md from ./index.md with all the other md files referenced
5
6 import sys
7 import os
8 from glob import glob
9
10 source = "index.md"
11 output_dir = "markdown"
12
13 index_line_format = " * [{title}]({base}.html)\n"
14
15 TITLE="title:"
16
17 def get_title(filename):
18     with open(filename) as input:
19         for line in input:
20             if line.startswith(TITLE):
21                 return line[len(TITLE):].strip()
22     return filename
23
24 def main():
25     if not os.path.isfile(source):
26         print("Source not found {}".format(source))
27         sys.exit(1)
28
29     output = os.path.join(output_dir, source)
30     with open(output, 'w') as result:
31         # copy index.md
32         with open(source) as input:
33             result.write(input.read())
34         for other in sys.argv[1:]:
35             dir = os.path.dirname(other) or "."
36             base = os.path.basename(other).replace(".md", "")
37             title = get_title(other)
38             # skip index from the index...
39             if base == "index":
40                 continue
41             # menu generated
42             #result.write(index_line_format.format(**locals()))
43     print("(Over)wrote {}".format(output))
44
45 main()