aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generators/generators.py61
-rw-r--r--source/css/theme.css29
-rw-r--r--source/css/theme.scss37
-rw-r--r--source/template.html1
4 files changed, 128 insertions, 0 deletions
diff --git a/generators/generators.py b/generators/generators.py
index c6cca082..c7a45e4b 100644
--- a/generators/generators.py
+++ b/generators/generators.py
@@ -26,6 +26,66 @@ from config.config import *
from utils import utils
+def generate_lang_switch():
+ """Generate language switcher"""
+
+ sys.stderr.write("generating langugage switcher\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)
+
+ # 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:
+ trad_files = []
+ html_file_name = re.sub(r"(.*)-[a-z]{2}(\.html)", r"\1\2",html_file)
+ for language in LANGUAGES:
+ if language != DEFAULTLANG:
+ trad_file = "{}-{}.html".format(
+ html_file_name.rsplit('.', 1)[0],
+ language)
+ if os.path.exists("build/"+trad_file):
+ trad_files.append({"file":trad_file, "lang":language})
+ else:
+ trad_file = "{}.html".format(html_file_name.rsplit('.', 1)[0])
+ if os.path.exists("build/"+trad_file):
+ trad_files.append({"file":trad_file, "lang":language})
+ if len(trad_files) > 1 and os.path.exists("build/"+html_file):
+ with open("build/"+html_file, 'r', encoding='utf-8') as f:
+ htmly_website_page = "<nav class='lang_switch'><div class='lia-border'><ul>"
+ for trad_file in trad_files:
+ if trad_file["file"] == html_file:
+ htmly_website_page += "<a href='{}' class='current lia'><li><span class='left-lia'></span><span class='center-lia'>{}</span><span class='right-lia'></span></li></a>".format(
+ trad_file["file"],
+ trad_file["lang"])
+ else:
+ htmly_website_page += "<a href='{}' class='lia'><li><span class='left-lia'></span><span class='center-lia'>{}</span><span class='right-lia'></span></li></a>".format(
+ trad_file["file"],
+ trad_file["lang"])
+ htmly_website_page += "</ul></div></nav>"
+ lines = f.readlines()
+ with open("build/"+html_file, 'w', encoding='utf-8') as f:
+ for line in lines:
+ f.write(re.sub(r'-- generate LANGSWITCH --', htmly_website_page, line))
+ else:
+ with open("build/"+html_file, 'r', encoding='utf-8') as f:
+ lines = f.readlines()
+ with open("build/"+html_file, 'w', encoding='utf-8') as f:
+ for line in lines:
+ f.write(re.sub(r'-- generate LANGSWITCH --', "", line))
+
+ os.remove(tmppath)
+
def generate_menu():
"""Generate menu."""
@@ -673,6 +733,7 @@ def generate_index_and_feed():
rss.items.sort(key=lambda item: item.timestamp, reverse=True)
generate_index(feed)
+ generate_lang_switch()
generate_menu()
generate_table()
generate_blog_list(feed)
diff --git a/source/css/theme.css b/source/css/theme.css
index 357e3c89..dd0726d3 100644
--- a/source/css/theme.css
+++ b/source/css/theme.css
@@ -91,6 +91,14 @@ ul li:before {
margin: 0;
padding: 0; }
+.lia:hover .left-lia::after {
+ content: "█▓▒░";
+ white-space: pre; }
+
+.lia:hover .right-lia::after {
+ content: "░▒▓█";
+ white-space: pre; }
+
/* subMenu design */
.subnav {
position: fixed;
@@ -188,6 +196,27 @@ ul li:before {
font-size: 12px !important;
white-space: normal; }
+/* menu lang switcher */
+.lang_switch {
+ position: fixed;
+ right: 11.5%;
+ width: 83px;
+ text-align: center; }
+
+.lang_switch .current {
+ color: black; }
+
+.lang_switch .current.lia li {
+ background-color: #fff; }
+
+.lang_switch .current .left-lia::after {
+ content: " ";
+ white-space: pre; }
+
+.lang_switch .current .right-lia::after {
+ content: " ";
+ white-space: pre; }
+
/* end menus design */
.content-separator, .footer {
width: 60%;
diff --git a/source/css/theme.scss b/source/css/theme.scss
index ef5c3dc2..5ae5af95 100644
--- a/source/css/theme.scss
+++ b/source/css/theme.scss
@@ -138,6 +138,16 @@ ul li:before {
}
}
+.lia:hover .left-lia::after {
+ content: "█▓▒░";
+ white-space: pre;
+}
+
+.lia:hover .right-lia::after {
+ content: "░▒▓█";
+ white-space: pre;
+}
+
/* subMenu design */
.subnav {
position: fixed;
@@ -282,6 +292,33 @@ ul li:before {
}
}
+/* menu lang switcher */
+
+.lang_switch {
+ position: fixed;
+ right: 11.5%;
+ width: 83px;
+ text-align: center;
+}
+
+.lang_switch .current {
+ color: black;
+}
+
+.lang_switch .current.lia li {
+ background-color: #fff;
+}
+
+.lang_switch .current .left-lia::after {
+ content: " ";
+ white-space: pre;
+}
+
+.lang_switch .current .right-lia::after {
+ content: " ";
+ white-space: pre;
+}
+
/* end menus design */
diff --git a/source/template.html b/source/template.html
index 2de53eb5..b98ce358 100644
--- a/source/template.html
+++ b/source/template.html
@@ -44,6 +44,7 @@ $endif$
░░██ █████ ░░██ ███ ██ █████ ██
░░ ░░░░░ ░░ ░░░ ░░ ░░░░░ ░░
</code></pre></div></a>
+ -- generate LANGSWITCH --
<nav class="nav">
<div class="lia-border">
-- generate menu here --