|
|
@ -1,97 +1,101 @@
|
|
|
|
from datetime import datetime
|
|
|
|
import locale
|
|
|
|
import markdown
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from os import path
|
|
|
|
|
|
|
|
import pathlib
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from os import path
|
|
|
|
|
|
|
|
|
|
|
|
import config
|
|
|
|
import config
|
|
|
|
|
|
|
|
import markdown
|
|
|
|
|
|
|
|
|
|
|
|
ENTRY_DIR = "templates/entry"
|
|
|
|
ENTRY_DIR = "templates/entry"
|
|
|
|
|
|
|
|
LANGUAGE = config.LANGUAGE
|
|
|
|
|
|
|
|
LOCAL = "de_DE.UTF-8" if LANGUAGE == "de-de" else "en_US.UTF-8"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
locale.setlocale(locale.LC_TIME, LOCAL)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
standalone_str = "Artikel" if LANGUAGE == "de-de" else "standalone"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_arch_string():
|
|
|
|
def gen_arch_string():
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Creates and returns a archive string of every file in ENTRY_DIR.
|
|
|
|
Creates and returns a archive string of every file in ENTRY_DIR.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
string: html-formatted archive-string
|
|
|
|
string: html-formatted archive-string
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
if path.exists(path_ex):
|
|
|
|
if path.exists(path_ex):
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
content_string = ""
|
|
|
|
content_string = ""
|
|
|
|
last_month = ""
|
|
|
|
last_month = ""
|
|
|
|
for file in reversed(contents):
|
|
|
|
for file in reversed(contents):
|
|
|
|
curr_date = datetime.fromtimestamp(
|
|
|
|
curr_date = datetime.fromtimestamp(os.path.getctime(file)).strftime("%Y-%m-%d")
|
|
|
|
os.path.getctime(file)).strftime("%Y-%m-%d")
|
|
|
|
curr_month = datetime.fromtimestamp(os.path.getctime(file)).strftime("%B %Y")
|
|
|
|
curr_month = datetime.fromtimestamp(
|
|
|
|
if curr_month != last_month:
|
|
|
|
os.path.getctime(file)).strftime("%b %Y")
|
|
|
|
if last_month != "":
|
|
|
|
if curr_month != last_month:
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
if last_month != "":
|
|
|
|
content_string += "<h2>" + curr_month + "</h2>\n"
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
content_string += "<ul>\n"
|
|
|
|
content_string += "<h2>" + curr_month + "</h2>\n"
|
|
|
|
last_month = curr_month
|
|
|
|
content_string += "<ul>\n"
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
last_month = curr_month
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
filename = filename.name
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
if filename[0] != ".":
|
|
|
|
filename = filename.name
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
if filename[0] != ".":
|
|
|
|
content_string += "<li>"
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
content_string += "<a href=\"" + "/index.html#" + \
|
|
|
|
content_string += "<li>"
|
|
|
|
filename + "\">" + curr_date + "</a> - "
|
|
|
|
content_string += curr_date + " - "
|
|
|
|
content_string += "<a href=\"" + "/entry/" + \
|
|
|
|
content_string += title + " ["
|
|
|
|
pathlib.PurePath(file).name + "\"><b>" + title + "</b></a>"
|
|
|
|
content_string += "<a href=\"" + "/index.html#" + \
|
|
|
|
content_string += "<br>"
|
|
|
|
filename + "\">" + "link" + "</a> - "
|
|
|
|
content_string += "</li>\n"
|
|
|
|
content_string += "<a href=\"" + "/entry/" + \
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
pathlib.PurePath(file).name + "\">" + "standalone" + "</a>"
|
|
|
|
return content_string
|
|
|
|
content_string += "] <br>"
|
|
|
|
|
|
|
|
content_string += "</li>\n"
|
|
|
|
|
|
|
|
content_string += "</ul>\n"
|
|
|
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_index_string():
|
|
|
|
def gen_index_string():
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Create and returns a string including every file in the ENTRY_DIR as an index.
|
|
|
|
Create and returns a string including every file in the ENTRY_DIR as an index.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
string: html-formatted index string
|
|
|
|
string: html-formatted index string
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
content_string = ""
|
|
|
|
content_string = ""
|
|
|
|
if path.exists(path_ex):
|
|
|
|
if path.exists(path_ex):
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
for file in reversed(contents):
|
|
|
|
for file in reversed(contents):
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
purefile = filename
|
|
|
|
purefile = filename
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
filename = filename.name
|
|
|
|
filename = filename.name
|
|
|
|
if filename[0] != ".":
|
|
|
|
if filename[0] != ".":
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
content_string += "<div class=\"entry\">\n"
|
|
|
|
content_string += "<div class=\"entry\">\n"
|
|
|
|
content_string += "<h2 id=\"" + filename + "\">" + title + "</h2>\n"
|
|
|
|
content_string += "<h2 id=\"" + filename + "\">"
|
|
|
|
content_string += "[<a href=\"" + "/entry/" + \
|
|
|
|
content_string += "<a href=\"" + "/entry/" + \
|
|
|
|
pathlib.PurePath(file).name + "\">" + \
|
|
|
|
pathlib.PurePath(file).name + "\">" + \
|
|
|
|
"standalone" + "</a>]<br>\n"
|
|
|
|
title + "</a>" +"</h2>\n"
|
|
|
|
if file.endswith(".html"):
|
|
|
|
content_string += "<small>" + \
|
|
|
|
for line in text:
|
|
|
|
datetime.fromtimestamp(os.path.getctime(
|
|
|
|
content_string += line
|
|
|
|
file)).strftime("%Y-%m-%d") + "</small><br><br>"
|
|
|
|
content_string += "<br>"
|
|
|
|
if file.endswith(".html"):
|
|
|
|
if file.endswith(".md"):
|
|
|
|
for line in text:
|
|
|
|
content_string += gen_md_content(file, 2)
|
|
|
|
content_string += line
|
|
|
|
content_string += "<small>" + \
|
|
|
|
content_string += "<br>"
|
|
|
|
datetime.fromtimestamp(os.path.getctime(
|
|
|
|
if file.endswith(".md"):
|
|
|
|
file)).strftime("%Y-%m-%d") + "</small>"
|
|
|
|
content_string += gen_md_content(file, 2)
|
|
|
|
content_string += "</div>"
|
|
|
|
content_string += "</div>"
|
|
|
|
return content_string
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_stand_string(path_ex):
|
|
|
|
def gen_stand_string(path_ex):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Creates a html-string for a file.
|
|
|
|
Creates a html-string for a file.
|
|
|
|
If the file is markdown it will convert it.
|
|
|
|
If the file is markdown it will convert it.
|
|
|
|
This functions ensures upscaling for future formats.
|
|
|
|
This functions ensures upscaling for future formats.
|
|
|
@ -102,29 +106,29 @@ def gen_stand_string(path_ex):
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
string: html-formatted string string equivalent to the file
|
|
|
|
string: html-formatted string string equivalent to the file
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
filename = os.path.join(ENTRY_DIR, path_ex)
|
|
|
|
filename = os.path.join(ENTRY_DIR, path_ex)
|
|
|
|
content_string = ""
|
|
|
|
content_string = ""
|
|
|
|
if path.exists(filename):
|
|
|
|
if path.exists(filename):
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
filename_no_end = filename.split(".", 1)[0]
|
|
|
|
curr_date = datetime.fromtimestamp(os.path.getctime(filename)).strftime("%Y-%m-%d")
|
|
|
|
filename_no_end = filename_no_end.split("/")[-1]
|
|
|
|
filename_no_end = filename.split(".", 1)[0]
|
|
|
|
content_string += "<h1>" + title + "</h1>\n"
|
|
|
|
filename_no_end = filename_no_end.split("/")[-1]
|
|
|
|
content_string += "["
|
|
|
|
content_string += "<h1>" + title + "</h1>\n"
|
|
|
|
content_string += "<a href=\"" + "/index.html#" + \
|
|
|
|
content_string += "<a href=\"" + "/index.html#" + \
|
|
|
|
filename_no_end + "\">" + "link" + "</a>"
|
|
|
|
filename_no_end + "\">" + curr_date + "</a>"
|
|
|
|
content_string += "]<br>\n"
|
|
|
|
content_string += "<br>\n"
|
|
|
|
if filename.endswith(".html"):
|
|
|
|
if filename.endswith(".html"):
|
|
|
|
for line in text:
|
|
|
|
for line in text:
|
|
|
|
content_string += line
|
|
|
|
content_string += line
|
|
|
|
content_string += "<br>"
|
|
|
|
content_string += "<br>"
|
|
|
|
if filename.endswith(".md"):
|
|
|
|
if filename.endswith(".md"):
|
|
|
|
content_string += gen_md_content(filename, 1)
|
|
|
|
content_string += gen_md_content(filename, 1)
|
|
|
|
return content_string
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_md_content(path_ex, depth):
|
|
|
|
def gen_md_content(path_ex, depth):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Convert a markdown file to a html string.
|
|
|
|
Convert a markdown file to a html string.
|
|
|
|
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Parameters:
|
|
|
@ -134,54 +138,52 @@ def gen_md_content(path_ex, depth):
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
string: html-formatted string string equivalent to the markdown file
|
|
|
|
string: html-formatted string string equivalent to the markdown file
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
content_string = ""
|
|
|
|
content_string = ""
|
|
|
|
if path.exists(path_ex):
|
|
|
|
if path.exists(path_ex):
|
|
|
|
filename = path_ex.split(".", 1)
|
|
|
|
filename = path_ex.split(".", 1)
|
|
|
|
fileend = filename[len(filename) - 1]
|
|
|
|
fileend = filename[len(filename) - 1]
|
|
|
|
header = "#"
|
|
|
|
header = "#"
|
|
|
|
for i in range(depth):
|
|
|
|
for i in range(depth):
|
|
|
|
header += "#"
|
|
|
|
header += "#"
|
|
|
|
header += " "
|
|
|
|
header += " "
|
|
|
|
markdown_lines = open(path_ex, "r").readlines()[1:]
|
|
|
|
markdown_lines = open(path_ex, "r").readlines()[1:]
|
|
|
|
markdown_text = ""
|
|
|
|
markdown_text = ""
|
|
|
|
for line in markdown_lines:
|
|
|
|
for line in markdown_lines:
|
|
|
|
markdown_text += line.replace("# ", header)
|
|
|
|
markdown_text += line.replace("# ", header)
|
|
|
|
content_string = markdown.markdown(
|
|
|
|
content_string = markdown.markdown(markdown_text, extensions=["fenced_code", "tables"])
|
|
|
|
markdown_text, extensions=["fenced_code", "tables"]
|
|
|
|
return content_string
|
|
|
|
)
|
|
|
|
|
|
|
|
return content_string
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_rss_string():
|
|
|
|
def get_rss_string():
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Create a rss-string of the blog and return it.
|
|
|
|
Create a rss-string of the blog and return it.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
string: rss-string of everything that is in the ENTRY_DIR.
|
|
|
|
string: rss-string of everything that is in the ENTRY_DIR.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
path_ex = ENTRY_DIR
|
|
|
|
if path.exists(path_ex):
|
|
|
|
if path.exists(path_ex):
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
name_list = os.listdir(path_ex)
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
full_list = [os.path.join(path_ex, i) for i in name_list]
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
contents = sorted(full_list, key=os.path.getctime)
|
|
|
|
content_string = ""
|
|
|
|
content_string = ""
|
|
|
|
for file in reversed(contents):
|
|
|
|
for file in reversed(contents):
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
filename = pathlib.PurePath(file)
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
title = open(filename).readline().rstrip("\n")
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
text = open(filename).readlines()[1:]
|
|
|
|
filename = filename.name
|
|
|
|
filename = filename.name
|
|
|
|
if filename[0] != ".":
|
|
|
|
if filename[0] != ".":
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
filename = filename.split(".", 1)[0]
|
|
|
|
content_string += "<item>\n"
|
|
|
|
content_string += "<item>\n"
|
|
|
|
content_string += "<title>" + title + "</title>\n"
|
|
|
|
content_string += "<title>" + title + "</title>\n"
|
|
|
|
content_string += "<guid>" + config.WEBSITE + \
|
|
|
|
content_string += "<guid>" + config.WEBSITE + \
|
|
|
|
"/index.html#" + filename + "</guid>\n"
|
|
|
|
"/index.html#" + filename + "</guid>\n"
|
|
|
|
content_string += "<pubDate>" + \
|
|
|
|
content_string += "<pubDate>" + \
|
|
|
|
datetime.fromtimestamp(os.path.getctime(file)).strftime(
|
|
|
|
datetime.fromtimestamp(os.path.getctime(file)).strftime(
|
|
|
|
"%Y-%m-%d") + "</pubDate>\n"
|
|
|
|
"%Y-%m-%d") + "</pubDate>\n"
|
|
|
|
content_string += "<description>"
|
|
|
|
content_string += "<description>"
|
|
|
|
for line in text:
|
|
|
|
for line in text:
|
|
|
|
content_string += line
|
|
|
|
content_string += line
|
|
|
|
content_string += "</description>\n"
|
|
|
|
content_string += "</description>\n"
|
|
|
|
content_string += "</item>\n"
|
|
|
|
content_string += "</item>\n"
|
|
|
|
return content_string
|
|
|
|
return content_string
|
|
|
|