Now work on tag-pages is in progress. Obviously at this moment there will be some redundant processes on blog update which should later be reduced. But till then my primary object is to make everything work - though inefficiently.
This commit is contained in:
parent
4c712c2e20
commit
7e98cf7095
|
@ -22,7 +22,7 @@ parser_blog = subparsers.add_parser('blog', help='add or update blog or its sect
|
||||||
## 'blog' subroutines
|
## 'blog' subroutines
|
||||||
subparsers_blog = parser_blog.add_subparsers(help="blog subcommands", dest='action')
|
subparsers_blog = parser_blog.add_subparsers(help="blog subcommands", dest='action')
|
||||||
blog_parser_update = subparsers_blog.add_parser('update', help='updates blog to current state')
|
blog_parser_update = subparsers_blog.add_parser('update', help='updates blog to current state')
|
||||||
blog_parser_update.add_argument('subsection', choices=['all','recent','archive','feed'], help='sections of blog you may want to update')
|
blog_parser_update.add_argument('subsection', choices=['all','recent','archive','tags','feed'], help='sections of blog you may want to update')
|
||||||
blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir')
|
blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir')
|
||||||
|
|
||||||
# 'draft' command
|
# 'draft' command
|
||||||
|
@ -183,7 +183,7 @@ def parse_article(path):
|
||||||
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="tags/${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:
|
||||||
|
@ -224,7 +224,7 @@ def join_articles(artDir = articleDir):
|
||||||
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'], "%m/%d/%y %H:%M:%S"))
|
t = time.mktime(time.strptime(article['DATE'] + " " + article['TIME'], "%x %H:%M:%S"))
|
||||||
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)
|
||||||
|
@ -339,6 +339,34 @@ def list_articles(folder):
|
||||||
return articles_dict
|
return articles_dict
|
||||||
|
|
||||||
|
|
||||||
|
def list_articles_by_tag():
|
||||||
|
tags_dict = {}
|
||||||
|
folder = articleDir
|
||||||
|
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")))
|
||||||
|
for tag in article['TAGS'].split(","):
|
||||||
|
tag = tag.strip()
|
||||||
|
if tag not in tags_dict.keys():
|
||||||
|
tags_dict[tag] = list()
|
||||||
|
tags_dict[tag].append(article)
|
||||||
|
|
||||||
|
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():
|
||||||
|
for tag in article['TAGS'].split(","):
|
||||||
|
tag = tag.strip()
|
||||||
|
if len(tag) < 2:
|
||||||
|
continue
|
||||||
|
if tag not in tags_dict.keys():
|
||||||
|
tags_dict[tag] = list()
|
||||||
|
tags_dict[tag].append(article)
|
||||||
|
|
||||||
|
return tags_dict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def list_articles_to_html(folder):
|
def list_articles_to_html(folder):
|
||||||
artDir = folder
|
artDir = folder
|
||||||
joined_html = ""
|
joined_html = ""
|
||||||
|
@ -375,6 +403,7 @@ def list_archive(archived_months):
|
||||||
html += ""
|
html += ""
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def templating(dic):
|
def templating(dic):
|
||||||
|
|
||||||
sMAIN = ""
|
sMAIN = ""
|
||||||
|
@ -483,6 +512,27 @@ def build_archive_articles():
|
||||||
build_article(path)
|
build_article(path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def build_tag(tag,articles):
|
||||||
|
param={}
|
||||||
|
param['sRECENT'] = recent_articles(amountRecent)
|
||||||
|
param['sMAIN'] = list_articles_by_tag()
|
||||||
|
param['sMAIN_TITLE'] = l10nconf['TAG'] + " #" + tag
|
||||||
|
htmlTag = os.path.join(htmlDir,tag + ".html")
|
||||||
|
htmlString = templating(param)
|
||||||
|
# with open(htmlTag,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
||||||
|
# print(htmlString, file=f)
|
||||||
|
|
||||||
|
def build_tags():
|
||||||
|
dic = list_articles_by_tag()
|
||||||
|
for tag in dic.keys():
|
||||||
|
print(tag + " " + str(len(dic[tag])))
|
||||||
|
|
||||||
|
|
||||||
|
def build_feed():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_blog(subsection):
|
def update_blog(subsection):
|
||||||
""" Joins config defined variables into templates"""
|
""" Joins config defined variables into templates"""
|
||||||
|
|
||||||
|
@ -490,10 +540,16 @@ def update_blog(subsection):
|
||||||
build_index()
|
build_index()
|
||||||
build_current_articles()
|
build_current_articles()
|
||||||
|
|
||||||
elif subsection in ("archive","all"):
|
if subsection in ("archive","all"):
|
||||||
build_archive()
|
build_archive()
|
||||||
build_archive_articles()
|
build_archive_articles()
|
||||||
|
|
||||||
|
if subsection in ("tags"):
|
||||||
|
build_tags()
|
||||||
|
|
||||||
|
if subsection in ("feed"):
|
||||||
|
build_feed()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue