aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 12:59:57 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 12:59:57 +0200
commit443b5edd35d5732ee2588e04a40ff3ef77e1c958 (patch)
tree3b47ccae5a0020c4f51cbec9360e2f2b5d7c7e53
parent9d57dc83b706aa229874607204668afb3415d168 (diff)
downloadmy_new_personal_website-443b5edd35d5732ee2588e04a40ff3ef77e1c958.tar.xz
my_new_personal_website-443b5edd35d5732ee2588e04a40ff3ef77e1c958.zip
Move generate_menu to external file
Diffstat (limited to '')
-rw-r--r--generators/__init__.py0
-rw-r--r--generators/generators.py48
-rwxr-xr-xpyblog39
3 files changed, 50 insertions, 37 deletions
diff --git a/generators/__init__.py b/generators/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/generators/__init__.py
diff --git a/generators/generators.py b/generators/generators.py
new file mode 100644
index 00000000..2705ca69
--- /dev/null
+++ b/generators/generators.py
@@ -0,0 +1,48 @@
+#!/bin/python3
+
+import os
+import sys
+import tempfile
+import re
+
+from config.config import *
+
+
+def generate_menu():
+ """Generate menu."""
+
+ sys.stderr.write("generating menu\n")
+
+ fd, tmppath = tempfile.mkstemp()
+ os.close(fd)
+
+ # 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:
+ if name.endswith(".html"):
+ try:
+ html_fileList.append(os.path.join(root.split('build/')[1], name))
+ except IndexError:
+ html_fileList.append(name)
+
+ # Generate the string who contain the links of the menu
+ htmly_website_page = "<ul>"
+ for name in sorted(os.listdir(os.path.join(BUILDDIR, "website"))):
+ 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>"
+
+ # 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):
+ with open("build/"+html_file, 'r', encoding='utf-8') as indexmd:
+ lines = indexmd.readlines()
+ with open("build/"+html_file, 'w', encoding='utf-8') as indexmd:
+ for line in lines:
+ indexmd.write(re.sub(r'-- generate menu here --', htmly_website_page, line))
+
+ os.remove(tmppath)
+
+
diff --git a/pyblog b/pyblog
index e76c6a47..3ac492d1 100755
--- a/pyblog
+++ b/pyblog
@@ -48,43 +48,8 @@ from utils import utils
from config.config import *
+from generators import generators
-def generate_menu():
- """Generate menu."""
-
- sys.stderr.write("generating menu\n")
-
- fd, tmppath = tempfile.mkstemp()
- os.close(fd)
-
- # 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:
- if name.endswith(".html"):
- try:
- html_fileList.append(os.path.join(root.split('build/')[1], name))
- except IndexError:
- html_fileList.append(name)
-
- # Generate the string who contain the links of the menu
- htmly_website_page = "<ul>"
- for name in sorted(os.listdir(os.path.join(BUILDDIR, "website"))):
- 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>"
-
- # 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):
- with open("build/"+html_file, 'r', encoding='utf-8') as indexmd:
- lines = indexmd.readlines()
- with open("build/"+html_file, 'w', encoding='utf-8') as indexmd:
- for line in lines:
- indexmd.write(re.sub(r'-- generate menu here --', htmly_website_page, line))
-
- os.remove(tmppath)
def generate_table():
"""Generate table."""
@@ -689,7 +654,7 @@ def generate_index_and_feed():
rss.items.sort(key=lambda item: item.timestamp, reverse=True)
generate_index(feed)
- generate_menu()
+ generators.generate_menu()
generate_table()
generate_blog_list(feed)
generate_notes_list()