Archived articles now can also be built as permanent links. The sidebar now shows years and months as anchor links to jump to the equivalent zones of archive list.

This commit is contained in:
maste9 2015-03-22 12:14:57 +01:00 committed by Homer S
parent 344bb82fb4
commit 45c0ab82f2
1 changed files with 32 additions and 16 deletions

View File

@ -269,7 +269,6 @@ def recent_articles(amount):
for i in range(0,amount): for i in range(0,amount):
if i < len(dates_of_creation): if i < len(dates_of_creation):
joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))]) joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))])
return joined_html return joined_html
def archive_articles(): def archive_articles():
@ -309,6 +308,7 @@ def archive_articles():
except: except:
print("Failed archiving %s."%aName) print("Failed archiving %s."%aName)
raise raise
def list_of_months(): def list_of_months():
dArchives = {} dArchives = {}
@ -321,22 +321,28 @@ def list_of_months():
monthDir = os.path.join(yearDir,month) monthDir = os.path.join(yearDir,month)
tMonth = time.strptime(month+"/"+year,"%m/%Y") tMonth = time.strptime(month+"/"+year,"%m/%Y")
sMonth = time.strftime("%B",tMonth) sMonth = time.strftime("%B",tMonth)
dArchives[year].append(month)#sMonth) dArchives[year].append(month)
return dArchives return dArchives
def list_articles(folder): def list_articles(folder):
artDir = folder
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(folder) if not "~" in item]:
article = (parse_article(os.path.join(artDir, 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'], "%m/%d/%y %H:%M:%S")) t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S"))
articles_dict[str(t)] = article articles_dict[str(t)] = article
return articles_dict
def list_articles_to_html(folder):
artDir = folder
joined_html = ""
articles_dict = list_articles(folder)
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)
for i in range(0, len(dates_of_creation)): for i in range(0, len(dates_of_creation)):
joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))]) joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))])
return joined_html return joined_html
@ -346,10 +352,10 @@ def list_articles(folder):
def months_to_html(archived_months): def months_to_html(archived_months):
html = "<ul>" html = "<ul>"
for year in archived_months: for year in archived_months:
html += "<li>"+str(year)+"</li>" html += '<li><a href="#' + str(year) + '">' + str(year) + "</a></li>"
html += "<ul>" html += "<ul>"
for month in archived_months[year]: for month in archived_months[year]:
html += "<li>"+str(month)+"</li>" html += '<li><a href="#' + str(month) + '">' + time.strftime("%B",time.strptime(month,"%m")) + "</a></li>"
html += "</ul>" html += "</ul>"
html += "</ul>" html += "</ul>"
return html return html
@ -359,10 +365,10 @@ def months_to_html(archived_months):
def list_archive(archived_months): def list_archive(archived_months):
html = "" html = ""
for year in archived_months: for year in archived_months:
html += "<h2>"+str(year)+"</h2>" html += '<h2 id="'+str(year)+'">'+str(year)+"</h2>"
for month in archived_months[year]: for month in archived_months[year]:
html += "<h3>"+str(month)+"</h3>" html += '<h3 id="' + str(month) + '">' + time.strftime("%B",time.strptime(month,"%m")) + "</h3>"
html += list_articles(os.path.join(archiveDir,str(year),str(month))) html += list_articles_to_html(os.path.join(archiveDir,str(year),str(month)))
html += "" html += ""
return html return html
@ -436,7 +442,6 @@ def build_index():
print(htmlString, file=f) print(htmlString, file=f)
def build_archive(): def build_archive():
param={} param={}
param['sRECENT'] = months_to_html(list_of_months()) param['sRECENT'] = months_to_html(list_of_months())
@ -447,7 +452,6 @@ def build_archive():
print(htmlString, file=f) print(htmlString, file=f)
def build_article(path): def build_article(path):
param={} param={}
dic = parse_article(path) dic = parse_article(path)
@ -460,11 +464,22 @@ def build_article(path):
with open(htmlArticle,"w", encoding=l10nconf['BLOG_CHARSET']) as f: with open(htmlArticle,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
print(htmlString, file=f) print(htmlString, file=f)
def build_current_articles(): def build_current_articles():
for name in [os.path.splitext(item)[0] for item in os.listdir(articleDir) if not "~" in item]: for name in [os.path.splitext(item)[0] for item in os.listdir(articleDir) if not "~" in item]:
build_article(os.path.join(articleDir, name + ".txt")) build_article(os.path.join(articleDir, name + ".txt"))
def build_archive_articles():
months = list_of_months()
for year in months:
for month in months[year]:
monthFolder = os.path.join(archiveDir,str(year),str(month))
for article in list_articles(monthFolder).values():
path = os.path.join(article['PATH'],article['FILENAME'])
build_article(path)
def update_blog(subsection): def update_blog(subsection):
""" Joins config defined variables into templates""" """ Joins config defined variables into templates"""
@ -474,6 +489,7 @@ def update_blog(subsection):
elif subsection in ("archive","all"): elif subsection in ("archive","all"):
build_archive() build_archive()
build_archive_articles()