1818# - add header, navigation and footer to the converted file
1919def md2html (md_file , html_file , file_name ):
2020 print ("Transforming " + md_file + " into " + html_file )
21-
21+
2222 with open (md_file , 'r' ) as f :
2323 text = f .read ()
2424
2525 html = pymd .convert (text )
2626 soup = BeautifulSoup (html , 'html.parser' )
2727 for a in soup .findAll ('a' ):
28-
28+
2929 if not a ['href' ].startswith (('http://' , 'https://' , '#' )):
30- if not a ['href' ].endswith (('html' )):
31- a ['href' ] = a ['href' ]+ ".html"
32-
30+ parts = a ['href' ].split ('#' )
31+ if not parts [0 ].endswith (('html' )):
32+ a ['href' ] = parts [0 ] + ".html"
33+
34+ if (len (parts ) > 1 ):
35+ a ['href' ] = a ['href' ] + '#' + parts [1 ]
36+
3337 if (str (a ['href' ]).find (":" ) > 0 ):
3438 a ['href' ] = a ['href' ].replace (":" , "/" )
35-
39+
3640 # TODO: At this point we could use title and description to auto generate a breadcrum or an index
3741 #title = soup.find('h1').string
3842 #if (len(title.split(":")) > 1):
3943 # title = title.split(":")[1]
40-
44+
4145 #desc = ""
4246 #p = soup.find('p')
4347 #if not p is None:
@@ -48,7 +52,7 @@ def md2html(md_file, html_file, file_name):
4852
4953# search a filesystem directory for subdirs and retum these in a list
5054def getsubdirs (dir_path ):
51- return (glob .glob (dir_path + '*/' ))
55+ return (glob .glob (dir_path + '*/' ))
5256
5357# search a filesystem directory for markdown (md) files and parse these into html using the md2html function
5458def parsefiles (docsdir , outputdir ):
@@ -71,38 +75,38 @@ def parsefiles(docsdir, outputdir):
7175# filter out the ones that do not have a ssp module
7276def getmodulerepos ():
7377 module_repos = []
74-
78+
7579 with urllib .request .urlopen ("https://api.github.com/users/simplesamlphp/repos?per_page=100" ) as url :
7680 repos = json .loads (url .read ().decode ())
77-
81+
7882 for repo in repos :
7983 a_repo = {"name" : [], "description" : [], "html_url" : [], "short_name" : []}
80-
81- # we assume all module will have a name that starts with 'simplesamlphp-module-'
84+
85+ # we assume all module will have a name that starts with 'simplesamlphp-module-'
8286 if (repo ['name' ].find ('simplesamlphp-module-' ) == 0 and not repo ['archived' ]):
8387 a_repo ['name' ] = str (repo ['name' ])
8488 a_repo ['description' ] = str (repo ['description' ])
8589 a_repo ['html_url' ] = str (repo ['html_url' ])
8690 a_repo ['short_name' ] = a_repo ['name' ].split ("-" )[2 ]
8791
88- module_repos .append (a_repo )
89-
92+ module_repos .append (a_repo )
93+
9094 return module_repos
9195
9296# clone a specific git repo to a given directory. Optionally fetch specific version
9397# Target directories will be autocreated
9498def getgitrepo (repo , repo_clone_dir , repo_root , version = None ):
9599 os .makedirs (os .path .join (repo_clone_dir ))
96100 os .chdir (repo_clone_dir )
97-
101+
98102 if (version is None or version == 'devel' ):
99103 os .system ('git clone --depth=1 ' + repo )
100104 else :
101105 os .system ('git clone --depth=1 --branch simplesamlphp-' + version + ' ' + repo )
102106 os .chdir (repo_clone_dir + repo_root )
103-
107+
104108 print ("Working in git repo from" + os .getcwd ())
105-
109+
106110 os .system ('git status' )
107111
108112# make the header and headerbad div contents for indjection into each documentation page
@@ -137,14 +141,14 @@ def mkContentHeader(versions):
137141 content += '</nav>'
138142 content += '<div id="content">'
139143 content += '</header>'
140-
141- s = BeautifulSoup (content , 'html.parser' )
142-
144+
145+ s = BeautifulSoup (content , 'html.parser' )
146+
143147 return s .prettify ()
144148
145- # make a navigation structure based on the versions we have doucmentation for
149+ # make a navigation structure based on the versions we have doucmentation for
146150def mkNavigation (versions ):
147-
151+
148152 #content = '<div id="langbar" style="clar: both"><div id="navigation">Documentation is available for the following versions: '
149153 #for version in versions:
150154 # content += '<a href="/docs/'+version+'/index.html">'+version+'</a> | '
@@ -155,24 +159,24 @@ def mkNavigation(versions):
155159 if version == 'devel' :
156160 content += '<div class="menuitem first">'
157161 else :
158- content += '<div class="menuitem">'
162+ content += '<div class="menuitem">'
159163
160164 content += '<a href="' + site_base_path + version + '/index.html">' + version
161165 if version == versions [0 ]:
162166 content += ' (stable)'
163167 content += '</a></div>'
164-
168+
165169 content += ' <div class="menuitem last">'
166170 content += ' <a href="' + site_base_path + 'contributed_modules.html"> Contributed modules</a>'
167171 content += ' </div>'
168-
172+
169173 content += '</div>'
170-
174+
171175 return content
172176
173177# make sure some resources are put in the right place for the website
174178def mkResources (root_dir , web_root ):
175- # starter index.html (just a redirect to 'stable')
179+ # starter index.html (just a redirect to 'stable')
176180 os .system ('cp ' + root_dir + 'resources/index.html ' + web_root + 'index.html ' )
177181
178182# Builds an index.md file of all the contributed repository documetation (if available)
@@ -181,20 +185,20 @@ def mkcontribmodsindex(contrib_mods, module_index_file, contrib_mods_files):
181185 module_index += "===========================\n \n "
182186
183187 pages = {}
184-
188+
185189 for page in contrib_mods_files :
186190 s = page .split ("/" )
187191 mod_name = s [len (s ) - 2 ]
188192 page_name = s [len (s ) - 1 ]
189-
193+
190194 if mod_name not in pages .keys ():
191195 pages [mod_name ] = []
192196
193197 pages [mod_name ].append (page_name )
194-
198+
195199 for module in contrib_mods :
196200 module_index += " * " + module ["name" ] + "\n "
197-
201+
198202 if module ["description" ] is not None :
199203 module_index += ": " + module ["description" ] + "\n "
200204
@@ -204,30 +208,30 @@ def mkcontribmodsindex(contrib_mods, module_index_file, contrib_mods_files):
204208 for page in pages [module ["short_name" ]]:
205209 module_index += " * Documentation: [" + page + "](contrib_modules/" + module ["short_name" ] + "/" + page + ")\n "
206210 except KeyError :
207- # some modules do not have documentation, just ignore them
211+ # some modules do not have documentation, just ignore them
208212 pass
209-
213+
210214 with open (module_index_file , 'w+' ) as f :
211215 f .write (module_index )
212216
213217# reads files and (sub)dirs from a given directory
214218def getListOfFiles (dirName ):
215- # create a list of file and sub directories
216- # names in the given directory
219+ # create a list of file and sub directories
220+ # names in the given directory
217221 listOfFile = os .listdir (dirName )
218222 allFiles = list ()
219223 # Iterate over all the entries
220224 for entry in listOfFile :
221225 # Create full path
222226 fullPath = os .path .join (dirName , entry )
223- # If entry is a directory then get the list of files in this directory
227+ # If entry is a directory then get the list of files in this directory
224228 if os .path .isdir (fullPath ):
225229 allFiles = allFiles + getListOfFiles (fullPath )
226230 else :
227231 allFiles .append (fullPath )
228-
232+
229233 return allFiles
230-
234+
231235################################################
232236#
233237# MAIN
@@ -276,7 +280,7 @@ def getListOfFiles(dirName):
276280for ssp_version in ssp_versions :
277281 print ("Working on: " + ssp_version )
278282 #print("Repo Root: " + repo_root_dir)
279-
283+
280284 version_dir = tempdir + ssp_version + "/"
281285 #print("Version dir: " + version_dir)
282286 getgitrepo ('https://github.com/simplesamlphp/simplesamlphp.git' , version_dir , repo_root_dir , ssp_version )
@@ -306,22 +310,22 @@ def getListOfFiles(dirName):
306310 print ("Working on: " + module ["name" ])
307311 contrib_mod_dir = tempdir + "contrib_modules/" + module ["name" ] + "/"
308312 contrib_mod_web_dir = site_root_dir + "contrib_modules" + "/"
309-
310- # We assume contributes modules live in the ssp repo and are named 'simplesamlphp-module-*'
313+
314+ # We assume contributes modules live in the ssp repo and are named 'simplesamlphp-module-*'
311315 getgitrepo (module ["html_url" ], contrib_mod_dir , module ["name" ])
312-
316+
313317 module_dir = os .path .join (contrib_mod_dir , module ["name" ], "docs/" )
314318 print (module_dir )
315-
319+
316320 if os .path .isdir (module_dir ):
317321 module_output_dir = os .path .join (contrib_mod_web_dir , module ["short_name" ]+ "/" )
318322 parsefiles (module_dir , module_output_dir )
319-
323+
320324 else :
321325 print ("No docs found for '" + module ["name" ] + "'" )
322-
326+
323327# Now build an index of generated documents
324- contrib_mods_files = getListOfFiles (site_root_dir + "contrib_modules" + "/" )
328+ contrib_mods_files = getListOfFiles (site_root_dir + "contrib_modules" + "/" )
325329mkcontribmodsindex (contrib_mods , module_index_file , contrib_mods_files )
326330md2html (module_index_file , site_root_dir + 'contributed_modules.html' , 'contributed_modules.html' )
327331
0 commit comments