MAHHHHH!!! Whyever this damn tag-links are broken!?! ... I must take a closer look on the dictionary to care for this bug ... :-/
This commit is contained in:
parent
7e98cf7095
commit
da964bf068
|
@ -159,7 +159,7 @@ except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL,os.environ['LANG'])
|
locale.setlocale(locale.LC_ALL,os.environ['LANG'])
|
||||||
# print(time.strftime("%x",time.localtime()))
|
# print(time.strftime(dateFormat,time.localtime()))
|
||||||
|
|
||||||
########################
|
########################
|
||||||
# Templating functions #
|
# Templating functions #
|
||||||
|
@ -181,12 +181,16 @@ def parse_article(path):
|
||||||
return article_dict
|
return article_dict
|
||||||
|
|
||||||
def tags_to_html(tags):
|
def tags_to_html(tags):
|
||||||
|
|
||||||
tag_list = tags.split(",")
|
tag_list = tags.split(",")
|
||||||
html_tags = ""
|
html_tags = ""
|
||||||
sTAG = '<a href="${TAG}.html" class="tag">#${TAG}</a> '
|
sTAG = '<a href="${TAG}.html" class="tag">#${TAG}</a> '
|
||||||
|
|
||||||
if len(tag_list) > 0 and len(tag_list[0]) > 1:
|
if len(tag_list) > 0 and len(tag_list[0]) > 1:
|
||||||
for tag in tag_list:
|
for tag in tag_list:
|
||||||
|
tag = tag.strip()
|
||||||
|
if len(tag) < 2:
|
||||||
|
continue
|
||||||
html_tags += Template(sTAG).safe_substitute({'TAG':tag})
|
html_tags += Template(sTAG).safe_substitute({'TAG':tag})
|
||||||
|
|
||||||
return html_tags
|
return html_tags
|
||||||
|
@ -198,8 +202,8 @@ def article_to_html(article_dict):
|
||||||
|
|
||||||
# Read out article txt file
|
# Read out article txt file
|
||||||
|
|
||||||
article_dict['DATE'] = time.strftime(dateFormat, time.strptime(article_dict['DATE'],"%x"))
|
article_dict['DATE'] = time.strftime(dateFormat, time.strptime(article_dict['DATE'],dateFormat))
|
||||||
article_dict['TIME'] = time.strftime(timeFormat, time.strptime(article_dict['TIME'],"%X"))
|
article_dict['TIME'] = time.strftime(timeFormat, time.strptime(article_dict['TIME'],timeFormat))
|
||||||
article_dict['TAGS'] = tags_to_html(article_dict['TAGS'])
|
article_dict['TAGS'] = tags_to_html(article_dict['TAGS'])
|
||||||
|
|
||||||
tplSub = {
|
tplSub = {
|
||||||
|
@ -217,14 +221,29 @@ def article_to_html(article_dict):
|
||||||
sARTICLE = Template(sARTICLE).safe_substitute(tplSub)
|
sARTICLE = Template(sARTICLE).safe_substitute(tplSub)
|
||||||
return sARTICLE
|
return sARTICLE
|
||||||
|
|
||||||
def join_articles(artDir = articleDir):
|
|
||||||
|
def join_articles(list_of_articles):
|
||||||
|
joined_html = ""
|
||||||
|
articles_dict = {}
|
||||||
|
for article in list_of_articles:
|
||||||
|
# Bring articles into chronological order
|
||||||
|
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], dateFormat + " " + timeFormat))
|
||||||
|
articles_dict[str(t)] = article
|
||||||
|
dates_of_creation = [float(value) for value in articles_dict.keys()]
|
||||||
|
dates_of_creation.sort(key=None,reverse=True)
|
||||||
|
for date in dates_of_creation:
|
||||||
|
joined_html += article_to_html(articles_dict[str(time.strftime(str(date)))])
|
||||||
|
|
||||||
|
return joined_html
|
||||||
|
|
||||||
|
|
||||||
|
def join_articles_of_dir(artDir = articleDir):
|
||||||
joined_html = ""
|
joined_html = ""
|
||||||
articles_dict = {}
|
articles_dict = {}
|
||||||
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
|
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
|
||||||
article = (parse_article(os.path.join(artDir, name + ".txt")))
|
article = (parse_article(os.path.join(artDir, name + ".txt")))
|
||||||
# Bring articles into chronological order
|
# Bring articles into chronological order
|
||||||
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S"))
|
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], dateFormat + " " + timeFormat))
|
||||||
articles_dict[str(t)] = article
|
articles_dict[str(t)] = article
|
||||||
dates_of_creation = [float(value) for value in articles_dict.keys()]
|
dates_of_creation = [float(value) for value in articles_dict.keys()]
|
||||||
dates_of_creation.sort(key=None,reverse=True)
|
dates_of_creation.sort(key=None,reverse=True)
|
||||||
|
@ -238,8 +257,8 @@ def recent_to_html(article_dict):
|
||||||
|
|
||||||
# Read out article txt file
|
# Read out article txt file
|
||||||
|
|
||||||
article_dict['DATE'] = time.strftime(dateFormat, time.strptime(article_dict['DATE'],"%x"))
|
article_dict['DATE'] = time.strftime(dateFormat, time.strptime(article_dict['DATE'], dateFormat))
|
||||||
article_dict['TIME'] = time.strftime(timeFormat, time.strptime(article_dict['TIME'],"%X"))
|
article_dict['TIME'] = time.strftime(timeFormat, time.strptime(article_dict['TIME'], timeFormat))
|
||||||
article_dict['TAGS'] = tags_to_html(article_dict['TAGS'])
|
article_dict['TAGS'] = tags_to_html(article_dict['TAGS'])
|
||||||
|
|
||||||
tplSub = {
|
tplSub = {
|
||||||
|
@ -265,7 +284,7 @@ def recent_articles(amount):
|
||||||
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
|
for name in [os.path.splitext(item)[0] for item in os.listdir(artDir) if not "~" in item]:
|
||||||
article = (parse_article(os.path.join(artDir, name + ".txt")))
|
article = (parse_article(os.path.join(artDir, name + ".txt")))
|
||||||
# Bring articles into chronological order
|
# Bring articles into chronological order
|
||||||
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S"))
|
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], dateFormat + " " + timeFormat))
|
||||||
articles_dict[str(t)] = article
|
articles_dict[str(t)] = article
|
||||||
dates_of_creation = [float(value) for value in articles_dict.keys()]
|
dates_of_creation = [float(value) for value in articles_dict.keys()]
|
||||||
dates_of_creation.sort(key=None,reverse=True)
|
dates_of_creation.sort(key=None,reverse=True)
|
||||||
|
@ -283,7 +302,7 @@ def archive_articles():
|
||||||
for article in articles:
|
for article in articles:
|
||||||
aName = article["FILENAME"]
|
aName = article["FILENAME"]
|
||||||
aPath = os.path.join(article["PATH"], aName)
|
aPath = os.path.join(article["PATH"], aName)
|
||||||
aDate = time.strptime(article["DATE"],"%x")
|
aDate = time.strptime(article["DATE"], dateFormat)
|
||||||
aMonth = aDate.tm_mon
|
aMonth = aDate.tm_mon
|
||||||
aYear = aDate.tm_year
|
aYear = aDate.tm_year
|
||||||
|
|
||||||
|
@ -333,19 +352,24 @@ def list_articles(folder):
|
||||||
for name in [os.path.splitext(item)[0] for item in os.listdir(folder) if not "~" in item]:
|
for name in [os.path.splitext(item)[0] for item in os.listdir(folder) if not "~" in item]:
|
||||||
article = (parse_article(os.path.join(folder, name + ".txt")))
|
article = (parse_article(os.path.join(folder, name + ".txt")))
|
||||||
# Bring articles into chronological order
|
# Bring articles into chronological order
|
||||||
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S"))
|
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], dateFormat + " " + timeFormat))
|
||||||
articles_dict[str(t)] = article
|
articles_dict[str(t)] = article
|
||||||
|
|
||||||
return articles_dict
|
return articles_dict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_articles_by_tag():
|
def list_articles_by_tag():
|
||||||
tags_dict = {}
|
|
||||||
folder = articleDir
|
folder = articleDir
|
||||||
for name in [os.path.splitext(item)[0] for item in os.listdir(folder) if not "~" in item]:
|
tags_dict = {}
|
||||||
article = (parse_article(os.path.join(folder, name + ".txt")))
|
articles = [item for item in os.listdir(folder) if os.path.splitext(item)[1] == ".txt"]
|
||||||
|
for name in articles:
|
||||||
|
article = (parse_article(os.path.join(folder, name)))
|
||||||
for tag in article['TAGS'].split(","):
|
for tag in article['TAGS'].split(","):
|
||||||
tag = tag.strip()
|
tag = tag.strip()
|
||||||
|
if len(tag) < 2:
|
||||||
|
continue
|
||||||
if tag not in tags_dict.keys():
|
if tag not in tags_dict.keys():
|
||||||
tags_dict[tag] = list()
|
tags_dict[tag] = list()
|
||||||
tags_dict[tag].append(article)
|
tags_dict[tag].append(article)
|
||||||
|
@ -354,7 +378,11 @@ def list_articles_by_tag():
|
||||||
for year in months:
|
for year in months:
|
||||||
for month in months[year]:
|
for month in months[year]:
|
||||||
monthFolder = os.path.join(archiveDir,str(year),str(month))
|
monthFolder = os.path.join(archiveDir,str(year),str(month))
|
||||||
for article in list_articles(monthFolder).values():
|
|
||||||
|
articles = [item for item in os.listdir(monthFolder) if os.path.splitext(item)[1] == ".txt"]
|
||||||
|
for name in articles:
|
||||||
|
article = (parse_article(os.path.join(monthFolder, name)))
|
||||||
|
|
||||||
for tag in article['TAGS'].split(","):
|
for tag in article['TAGS'].split(","):
|
||||||
tag = tag.strip()
|
tag = tag.strip()
|
||||||
if len(tag) < 2:
|
if len(tag) < 2:
|
||||||
|
@ -362,7 +390,7 @@ def list_articles_by_tag():
|
||||||
if tag not in tags_dict.keys():
|
if tag not in tags_dict.keys():
|
||||||
tags_dict[tag] = list()
|
tags_dict[tag] = list()
|
||||||
tags_dict[tag].append(article)
|
tags_dict[tag].append(article)
|
||||||
|
|
||||||
return tags_dict
|
return tags_dict
|
||||||
|
|
||||||
|
|
||||||
|
@ -467,7 +495,7 @@ def templating(dic):
|
||||||
def build_index():
|
def build_index():
|
||||||
param = {}
|
param = {}
|
||||||
param['sRECENT'] = recent_articles(amountRecent)
|
param['sRECENT'] = recent_articles(amountRecent)
|
||||||
param['sMAIN'] = join_articles()
|
param['sMAIN'] = join_articles_of_dir()
|
||||||
param['sMAIN_TITLE'] = l10nconf['CURRENT']
|
param['sMAIN_TITLE'] = l10nconf['CURRENT']
|
||||||
htmlString = templating(param)
|
htmlString = templating(param)
|
||||||
with open(htmlIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
with open(htmlIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
||||||
|
@ -516,18 +544,25 @@ def build_archive_articles():
|
||||||
def build_tag(tag,articles):
|
def build_tag(tag,articles):
|
||||||
param={}
|
param={}
|
||||||
param['sRECENT'] = recent_articles(amountRecent)
|
param['sRECENT'] = recent_articles(amountRecent)
|
||||||
param['sMAIN'] = list_articles_by_tag()
|
param['sMAIN'] = join_articles(articles)
|
||||||
param['sMAIN_TITLE'] = l10nconf['TAG'] + " #" + tag
|
param['sMAIN_TITLE'] = l10nconf['TAG'] + " #" + tag
|
||||||
htmlTag = os.path.join(htmlDir,tag + ".html")
|
htmlTag = os.path.join(htmlDir,tag + ".html")
|
||||||
htmlString = templating(param)
|
htmlString = templating(param)
|
||||||
# with open(htmlTag,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
with open(htmlTag,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
||||||
# print(htmlString, file=f)
|
print(htmlString, file=f)
|
||||||
|
|
||||||
def build_tags():
|
def build_tag_cloud():
|
||||||
dic = list_articles_by_tag()
|
dic = list_articles_by_tag()
|
||||||
for tag in dic.keys():
|
for tag in dic.keys():
|
||||||
print(tag + " " + str(len(dic[tag])))
|
print(tag + " " + str(len(dic[tag])))
|
||||||
|
|
||||||
|
|
||||||
|
def build_tags():
|
||||||
|
dic = list_articles_by_tag()
|
||||||
|
for tag in dic.keys():
|
||||||
|
print(dic[tag])
|
||||||
|
build_tag(tag,dic[tag])
|
||||||
|
|
||||||
|
|
||||||
def build_feed():
|
def build_feed():
|
||||||
pass
|
pass
|
||||||
|
@ -599,7 +634,7 @@ if vars(args)['target'] == 'draft':
|
||||||
draft = os.path.join(blog_dir,"drafts",vars(args)['name'] + ".txt")
|
draft = os.path.join(blog_dir,"drafts",vars(args)['name'] + ".txt")
|
||||||
tpl = os.path.join(tplDir,"article.tpl")
|
tpl = os.path.join(tplDir,"article.tpl")
|
||||||
sTpl = open(tpl).read()
|
sTpl = open(tpl).read()
|
||||||
subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()),
|
subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime(dateFormat, time.localtime()), "TIME" : time.strftime(timeFormat,time.localtime()),
|
||||||
"AUTHOR" : user
|
"AUTHOR" : user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,7 +684,7 @@ if vars(args)['target'] == 'article':
|
||||||
article = os.path.join(blog_dir,"articles",vars(args)['name'] + ".txt")
|
article = os.path.join(blog_dir,"articles",vars(args)['name'] + ".txt")
|
||||||
tpl = os.path.join(tplDir,"article.tpl")
|
tpl = os.path.join(tplDir,"article.tpl")
|
||||||
sTpl = open(tpl).read()
|
sTpl = open(tpl).read()
|
||||||
subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime("%x",time.localtime()), "TIME" : time.strftime("%X",time.localtime()),
|
subs = {"ID":int(time.mktime(time.localtime())), "DATE" : time.strftime(dateFormat,time.localtime()), "TIME" : time.strftime(timeFormat,time.localtime()),
|
||||||
"AUTHOR" : user
|
"AUTHOR" : user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue