Skip to content

Commit ed7f628

Browse files
committed
make limo work except for jekyll syntax error in doc body
1 parent 439cf81 commit ed7f628

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

code/plugins/reformat_plugin.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
import sys
33
import shutil
44

5+
def clean_filename(filename):
6+
filename = filename.replace(' ', '_')
7+
filename = filename.replace('(', '')
8+
filename = filename.replace(')', '')
9+
filename = filename.replace(',', '')
10+
filename = filename.replace(';', '')
11+
filename = filename.replace(':', '')
12+
filename = filename.replace('/', '')
13+
return filename
514
# open a text file ending with .md and append a paragraph to it
615
def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=""):
716
append_text = '''---
@@ -11,7 +20,7 @@ def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=
1120
'''.format(filename=filename, parent=parent)
1221

1322
print(f"Reformatting {filename} of {parent}...")
14-
if parent in ["nsgportal", "limo"]:
23+
if parent in ["nsgportal", "LIMO"]:
1524
pages = []
1625
titles = []
1726
# load _Sidebar.md and extract all links from markdown file
@@ -20,11 +29,16 @@ def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=
2029
for line in lines:
2130
if '(' in line:
2231
# extract text between square brackets
32+
# find the first '(' after the square brackets
33+
page = line[line.find('(', line.find(']'))+1:line.rfind(')')]
34+
if parent == "LIMO":
35+
page = page.replace('https://github.com/LIMO-EEG-Toolbox/limo_meeg/wiki/', '')
36+
page = clean_filename(page)
2337
title = line[line.find('[')+1:line.find(']')]
24-
page = line[line.find('(')+1:line.find(')')]
2538
pages.append(page)
2639
titles.append(title)
2740
pages = list(map(str.lower, pages))
41+
filename = clean_filename(filename)
2842
if filename.lower() in pages:
2943
order = pages.index(filename.lower())
3044
title = titles[order]
@@ -45,7 +59,10 @@ def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=
4559
with open(filepath) as f:
4660
text = f.read()
4761
text = append_text + text
48-
with open(output_file, 'w') as out:
62+
outputfilename = clean_filename(os.path.basename(output_file))
63+
outputfilepath = os.path.dirname(output_file)
64+
65+
with open(f"{outputfilepath}/{outputfilename}", 'w') as out:
4966
out.write(text)
5067

5168
def reformat_plugin_dir(plugin_input_dir, plugin_name, formatted_name, order, link, plugin_type='wiki'):
@@ -77,7 +94,6 @@ def reformat_plugin_dir(plugin_input_dir, plugin_name, formatted_name, order, li
7794
if plugin_type == 'wiki':
7895
append_text += '\nhas_children: true'
7996
wiki_plugin_input_dir = plugin_input_dir + '.wiki'
80-
print(wiki_plugin_input_dir)
8197

8298
# copy image directory from input to output dir
8399
if os.path.exists(os.path.join(wiki_plugin_input_dir, 'images')):

0 commit comments

Comments
 (0)