From 45c0ab82f2c08f76f7ba506bfe90573de93411c2 Mon Sep 17 00:00:00 2001 From: maste9 Date: Sun, 22 Mar 2015 12:14:57 +0100 Subject: [PATCH] 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. --- picoblogger/main.py | 48 ++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/picoblogger/main.py b/picoblogger/main.py index a6a5624..467086c 100755 --- a/picoblogger/main.py +++ b/picoblogger/main.py @@ -269,7 +269,6 @@ def recent_articles(amount): for i in range(0,amount): if i < len(dates_of_creation): joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))]) - return joined_html def archive_articles(): @@ -309,6 +308,7 @@ def archive_articles(): except: print("Failed archiving %s."%aName) raise + def list_of_months(): dArchives = {} @@ -321,22 +321,28 @@ def list_of_months(): monthDir = os.path.join(yearDir,month) tMonth = time.strptime(month+"/"+year,"%m/%Y") sMonth = time.strftime("%B",tMonth) - dArchives[year].append(month)#sMonth) + dArchives[year].append(month) return dArchives + def list_articles(folder): - artDir = folder - joined_html = "" articles_dict = {} - 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"))) + 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"))) # Bring articles into chronological order t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%m/%d/%y %H:%M:%S")) 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.sort(key=None,reverse=True) for i in range(0, len(dates_of_creation)): - joined_html += recent_to_html(articles_dict[str(time.strftime(str(dates_of_creation[i])))]) return joined_html @@ -346,10 +352,10 @@ def list_articles(folder): def months_to_html(archived_months): html = "" return html @@ -359,10 +365,10 @@ def months_to_html(archived_months): def list_archive(archived_months): html = "" for year in archived_months: - html += "

"+str(year)+"

" + html += '

'+str(year)+"

" for month in archived_months[year]: - html += "

"+str(month)+"

" - html += list_articles(os.path.join(archiveDir,str(year),str(month))) + html += '

' + time.strftime("%B",time.strptime(month,"%m")) + "

" + html += list_articles_to_html(os.path.join(archiveDir,str(year),str(month))) html += "" return html @@ -436,7 +442,6 @@ def build_index(): print(htmlString, file=f) - def build_archive(): param={} param['sRECENT'] = months_to_html(list_of_months()) @@ -447,7 +452,6 @@ def build_archive(): print(htmlString, file=f) - def build_article(path): param={} dic = parse_article(path) @@ -460,11 +464,22 @@ def build_article(path): with open(htmlArticle,"w", encoding=l10nconf['BLOG_CHARSET']) as f: print(htmlString, file=f) + def build_current_articles(): 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")) - - + + +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): """ Joins config defined variables into templates""" @@ -474,6 +489,7 @@ def update_blog(subsection): elif subsection in ("archive","all"): build_archive() + build_archive_articles()