diff options
author | neodarz <neodarz@neodarz.net> | 2017-05-06 22:57:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-05-06 22:57:34 +0200 |
commit | e289e8a22f2767e217fd793789892bec4f56effe (patch) | |
tree | 721e4702a59221d437f6f16cfcbb9b7ca8f7b866 /pyblog | |
parent | 0ebd987d74cd494ed49cc9590269ea57da2a4bf6 (diff) | |
download | my_new_personal_website-e289e8a22f2767e217fd793789892bec4f56effe.tar.xz my_new_personal_website-e289e8a22f2767e217fd793789892bec4f56effe.zip |
Add new right submenu
Diffstat (limited to '')
-rwxr-xr-x | pyblog | 51 |
1 files changed, 47 insertions, 4 deletions
@@ -296,7 +296,7 @@ def generate_menu(): fd, tmppath = tempfile.mkstemp() os.close(fd) - # Get the list of all html file in the build folder + # Put in a list the pages where the menu will be written html_fileList = [] for root, dirs, files in os.walk(BUILDDIR): for name in files: @@ -306,13 +306,17 @@ def generate_menu(): except IndexError: html_fileList.append(name) - # Generate the a string who contain a list of file in website folder + # Generate the string who contain the links of the menu htmly_website_page = "<ul>" for name in os.listdir(os.path.join(BUILDDIR, "website")): - htmly_website_page += "<a href='/website/"+name+"' class='lia'><li><span class='left-lia'></span><span class='center-lia'>"+name.split('.html')[0]+"</span><span class='right-lia'></span></li></a>" + if name != "Documents": + htmly_website_page += "<a href='/website/"+name+"' class='lia'><li><span class='left-lia'></span><span class='center-lia'>"+name.split('.html')[0]+"</span><span class='right-lia'></span></li></a>" htmly_website_page += "</ul>" - # Write the menu in file, in place of the <generated_menu> + + print(htmly_website_page) + + # Writing the menu in all pages contained in the variable in place of the -- generate menu here -- for html_file in html_fileList: with open(tmppath, 'w', encoding='utf-8') as tmpfile: if os.path.exists("build/"+html_file): @@ -324,6 +328,44 @@ def generate_menu(): os.remove(tmppath) +def generate_submenu(): + """Generate submenu.""" + + sys.stderr.write("generating submenu\n") + + fd, tmppath = tempfile.mkstemp() + os.close(fd) + + # Put in a list the pages where the menu will be written + documents_fileList = [] + documents_fileList.append("/website/bts-sio.html") + for root, dirs, files in os.walk(BUILDDIR+"/website/Documents"): + for name in files: + if name.endswith(".html"): + try: + documents_fileList.append(os.path.join(root.split('build')[1], name)) + except IndexError: + documents_fileList.append(name) + + # Generate the string who contain the links of the menu + htmly_website_page = "<ul>" + htmly_website_page += "<a href='/website/bts-sio.html' class='sublia'><li><span class='subleft-lia'></span><span class='subcenter-lia'>bts-sio</span><span class='subright-lia'></span></li></a>" + for name in os.listdir(os.path.join(BUILDDIR, "website/Documents")): + htmly_website_page += "<a href='/website/Documents/"+name+"' class='sublia'><li><span class='subleft-lia'></span><span class='subcenter-lia'>"+name.split('.html')[0]+"</span><span class='subright-lia'></span></li></a>" + htmly_website_page += "</ul>" + + # Writing the menu in all pages contained in the variable in place of the -- generate submenu here -- + for document_file in documents_fileList: + with open(tmppath, 'w', encoding='utf-8') as tmpfile: + if os.path.exists("build"+document_file): + with open("build"+document_file, 'r', encoding='utf-8') as indexmd: + lines = indexmd.readlines() + with open("build"+document_file, 'w', encoding='utf-8') as indexmd: + for line in lines: + indexmd.write(re.sub(r'-- generate submenu here --', htmly_website_page, line)) + + os.remove(tmppath) + def generate_blog_list(feed): """"Generate blog list """ @@ -843,6 +885,7 @@ def generate_index_and_feed(): generate_index(feed) generate_menu() + generate_submenu() generate_blog_list(feed) generate_notes_list() rewrite_title() |