2
2
import sys
3
3
import shutil
4
4
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
5
14
# open a text file ending with .md and append a paragraph to it
6
15
def reformat_wiki_pages (filepath , filename , parent , output_file , wiki_input_dir = "" ):
7
16
append_text = '''---
@@ -11,7 +20,7 @@ def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=
11
20
''' .format (filename = filename , parent = parent )
12
21
13
22
print (f"Reformatting { filename } of { parent } ..." )
14
- if parent in ["nsgportal" , "limo " ]:
23
+ if parent in ["nsgportal" , "LIMO " ]:
15
24
pages = []
16
25
titles = []
17
26
# 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=
20
29
for line in lines :
21
30
if '(' in line :
22
31
# 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 )
23
37
title = line [line .find ('[' )+ 1 :line .find (']' )]
24
- page = line [line .find ('(' )+ 1 :line .find (')' )]
25
38
pages .append (page )
26
39
titles .append (title )
27
40
pages = list (map (str .lower , pages ))
41
+ filename = clean_filename (filename )
28
42
if filename .lower () in pages :
29
43
order = pages .index (filename .lower ())
30
44
title = titles [order ]
@@ -45,7 +59,10 @@ def reformat_wiki_pages(filepath, filename, parent, output_file, wiki_input_dir=
45
59
with open (filepath ) as f :
46
60
text = f .read ()
47
61
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 :
49
66
out .write (text )
50
67
51
68
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
77
94
if plugin_type == 'wiki' :
78
95
append_text += '\n has_children: true'
79
96
wiki_plugin_input_dir = plugin_input_dir + '.wiki'
80
- print (wiki_plugin_input_dir )
81
97
82
98
# copy image directory from input to output dir
83
99
if os .path .exists (os .path .join (wiki_plugin_input_dir , 'images' )):
0 commit comments