|
3 | 3 | import shutil
|
4 | 4 |
|
5 | 5 | # open a text file ending with .md and append a paragraph to it
|
6 |
| -def reformat_wiki_pages(filepath, filename, parent, output_file): |
7 |
| - with open(filepath) as f: |
8 |
| - text = f.read() |
9 |
| - append_text = '''--- |
| 6 | +def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=""): |
| 7 | + append_text = '''--- |
10 | 8 | layout: default
|
11 | 9 | title: {filename}
|
12 | 10 | long_title: {filename}
|
13 | 11 | parent: {parent}
|
14 | 12 | grand_parent: Plugins
|
15 |
| ---- |
16 | 13 | '''.format(filename=filename, parent=parent)
|
| 14 | + |
| 15 | + if parent == "nsgportal": |
| 16 | + pages = [] |
| 17 | + # load _Sidebar.md and extract all links from markdown file |
| 18 | + with open(os.path.join(wiki_input_dir, '_Sidebar.md')) as f: |
| 19 | + lines = f.readlines() |
| 20 | + for line in lines: |
| 21 | + if line.startswith('*'): |
| 22 | + # extract text between square brackets |
| 23 | + page = line[line.find('(')+1:line.find(')')] |
| 24 | + pages.append(page) |
| 25 | + if filename in pages: |
| 26 | + order = pages.index(filename) |
| 27 | + append_text += 'nav_order: {order}\n'.format(order=order) |
| 28 | + |
| 29 | + append_text += '---\n' |
| 30 | + |
| 31 | + with open(filepath) as f: |
| 32 | + text = f.read() |
17 | 33 | text = append_text + text
|
18 |
| - with open(output_file, 'w') as out: |
19 |
| - out.write(text) |
| 34 | + with open(output_file, 'w') as out: |
| 35 | + out.write(text) |
20 | 36 |
|
21 | 37 | def reformat_plugin_dir(plugin_input_dir, plugin_name, order, plugin_type='wiki'):
|
22 | 38 | # plugins_output_dir = '/Users/dtyoung/Documents/EEGLAB/sccn.github.io/plugins'
|
@@ -70,7 +86,7 @@ def reformat_plugin_dir(plugin_input_dir, plugin_name, order, plugin_type='wiki'
|
70 | 86 | for root, dirs, files in os.walk(wiki_plugin_input_dir):
|
71 | 87 | for file in files:
|
72 | 88 | if file.endswith('.md') and not file.startswith('index') and not file.startswith('Home'):
|
73 |
| - reformat_wiki_pages(os.path.join(wiki_plugin_input_dir, file), file.strip('.md'), plugin_name, os.path.join(plugin_output_dir, file)) |
| 89 | + reformat_wiki_pages(os.path.join(wiki_plugin_input_dir, file), file.strip('.md'), plugin_name, os.path.join(plugin_output_dir, file), wiki_plugin_input_dir) |
74 | 90 | # main
|
75 | 91 | def main():
|
76 | 92 | if len(sys.argv) != 5:
|
|
0 commit comments