aboutsummaryrefslogtreecommitdiff
path: root/pyblog
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-05-26 13:45:44 +0200
committerneodarz <neodarz@neodarz.net>2019-05-26 13:45:44 +0200
commitf2d9f3041e857fe08359647671edfd1d75718ff1 (patch)
treec2c0d6adeb0a5f8a1811a2ba9386ae929b7deee4 /pyblog
parent5c68a2e3ea7337fb87117331b45d8aabde84cf0d (diff)
downloadmy_new_personal_website-f2d9f3041e857fe08359647671edfd1d75718ff1.tar.xz
my_new_personal_website-f2d9f3041e857fe08359647671edfd1d75718ff1.zip
Move generate_blog_list to external file
Diffstat (limited to 'pyblog')
-rwxr-xr-xpyblog60
1 files changed, 1 insertions, 59 deletions
diff --git a/pyblog b/pyblog
index e6a15c57..c27edd1b 100755
--- a/pyblog
+++ b/pyblog
@@ -51,64 +51,6 @@ from config.config import *
from generators import generators
-def generate_blog_list(feed):
- """"Generate blog list """
-
- sys.stderr.write("generating blog list\n")
-
- html_fileList = []
- for root, dirs, files in os.walk(BUILDDIR):
- for name in files:
- if re.search(r'blog',root):
- if name.endswith(".html"):
- try:
- html_fileList.append(os.path.join(root.split('blog/')[1], name))
- except IndexError:
- html_fileList.append(name)
-
- # generate TOC
- for html_file in html_fileList:
- div_blog_list = u'<div class="blog-index" id="toc">\n</table>\n'
- year = 10000 # will be larger than the latest year for quite a while
- # recall that entries are in reverse chronological order
- table_opened = False
- for entry in feed.entries:
- date = entry.updated_datetime
- if date.year < year:
- # close the previous table if there is one
- if table_opened:
- div_blog_list += u'</table>\n'
- # write a new <h2 class="blog-index-year-title"> tag with the smaller year
- year = date.year
- div_blog_list += u'\n<h2 class="blog-index-year-title" id="{0}"><span class="left-h2">.:</span><span class="title-h2">{0}</span><span class="right-h2">:.</span></h2>\n\n'.format(year)
- div_blog_list += u'<table class="blog-index-yearly-index">\n'
- table_opened = True
-
- # write a new table row entry in Markdown, in the format:
- #
- # <tr>
- # <td class="blog-index-post-date"><time class="date" datetime="2015-05-05T00:06:04-0700">May 5</time></td>
- # <td class="blog-index-post-title">[Blah blah](/blog/2015-05-04-blah-blah.html)</td>
- # </tr>
- monthday = date.strftime("%b %d")
- div_blog_list += (u'<tr><td class="blog-index-post-date"><time class="date" datetime="%s">%s</time></td>'
- '<td class="blog-index-post-title"><a href="%s">%s</a></td></tr>\n' %
- (date.isoformat(), monthday, entry.relpath, entry.title_text))
- if table_opened:
- div_blog_list += u'</table>\n'
- div_blog_list += u'</div>'
-
- fd, tmppath = tempfile.mkstemp()
- os.close(fd)
- with open(tmppath, 'w', encoding='utf-8') as tmpfile:
- if os.path.exists("build/blog/index.html"):
- with open("build/blog/index.html", 'r', encoding='utf-8') as indexmd:
- lines = indexmd.readlines()
- with open("build/blog/index.html", 'w', encoding='utf-8') as indexmd:
- for line in lines:
- indexmd.write(re.sub(r'{% generate blog_list here %}', div_blog_list, line))
-
-
def generate_notes_list():
""""Generate notes list """
@@ -564,7 +506,7 @@ def generate_index_and_feed():
generate_index(feed)
generators.generate_menu()
generators.generate_table()
- generate_blog_list(feed)
+ generators.generate_blog_list(feed)
generate_notes_list()
rewrite_title()