diff options
author | NeodarZ <neodarz@neodarz.net> | 2017-05-01 22:36:52 +0200 |
---|---|---|
committer | NeodarZ <neodarz@neodarz.net> | 2017-05-01 22:36:52 +0200 |
commit | 15c05dbb86fe3d98ec6e6ebe7743fd85b860dcc6 (patch) | |
tree | 4208a0a873eef35cc59c4e536a611c699bd1ec88 /pyblog | |
parent | d8289fcffd4eaee722c8531e36e508cb5f19337d (diff) | |
download | my_new_personal_website-15c05dbb86fe3d98ec6e6ebe7743fd85b860dcc6.tar.xz my_new_personal_website-15c05dbb86fe3d98ec6e6ebe7743fd85b860dcc6.zip |
Add some test
Diffstat (limited to 'pyblog')
-rwxr-xr-x | pyblog | 74 |
1 files changed, 49 insertions, 25 deletions
@@ -37,6 +37,8 @@ import dateutil.parser import dateutil.tz import lxml.etree as ET +from pyfiglet import Figlet + ############################# BLOG CONFIGURATIONS ############################## # Safe to customize BLOG_HOME = "http://neodarz.net/" @@ -598,34 +600,56 @@ def generate_sitemap(feed): ET.tostring(sitemap).decode('utf-8')) sys.stderr.write("wrote sitemap.xml\n") -def overide_title(): +def rewrite_title(): """Override the title of some page for a better render""" sys.stderr.write("Overriding some titles\n") - filenames =['build/index.html', - 'build/blog/index.html', - 'build/notes/index.html'] - - for root, dirs, files in os.walk(BUILDDIR): - for name in files: - if re.search(r'website($)',root): - if name.endswith(".html"): - try: - filenames.append("build"+os.path.join(root.split(BUILDDIR)[1], name)) - except IndexError: - filenames.append(name) + try: + f = Figlet(font='3d') + + filenames =['build/index.html', + 'build/blog/index.html', + 'build/notes/index.html'] + + for root, dirs, files in os.walk(BUILDDIR): + for name in files: + if re.search(r'website($)',root): + if name.endswith(".html"): + try: + filenames.append("build"+os.path.join(root.split(BUILDDIR)[1], name)) + except IndexError: + filenames.append(name) + if re.search(r'notes($)',root): + if name.endswith(".html"): + try: + filenames.append("build"+os.path.join(root.split(BUILDDIR)[1], name)) + except IndexError: + filenames.append(name) + if re.search(r'blog($)',root): + if name.endswith(".html"): + try: + filenames.append("build"+os.path.join(root.split(BUILDDIR)[1], name)) + except IndexError: + filenames.append(name) - fd, tmppath = tempfile.mkstemp() - os.close(fd) - for filename in filenames: - print (filename) - with open(tmppath, 'w', encoding='utf-8') as tmpfile: - if os.path.exists(filename): - with open(filename, 'r', encoding='utf-8') as indexmd: - lines = indexmd.readlines() - with open(filename, 'w', encoding='utf-8') as indexmd: - for line in lines: - indexmd.write(re.sub(r'\<h1 class="article-title"\>(.+?)\<\/h1\>', "<h1 class='article-title'>Why is there always a cat on whatever you're editing?</h1>", line)) + fd, tmppath = tempfile.mkstemp() + os.close(fd) + for filename in filenames: + print (filename) + soup = bs4.BeautifulSoup(open(filename), "lxml") + with open(tmppath, 'w', encoding='utf-8') as tmpfile: + if os.path.exists(filename): + with open(filename, 'r', encoding='utf-8') as indexmd: + lines = indexmd.readlines() + with open(filename, 'w', encoding='utf-8') as indexmd: + for line in lines: + indexmd.write(re.sub(r'\<pre class="header"\>\<code\>(.+?)\<\/code\>\<\/pre\>', '<pre class="header"><code>'+f.renderText('Miou')+'(^._.^)οΎ‰</code></pre>', line)) + + except Exception: + sys.stderr.write("=== /!\ ERROR /!\ ===\n") + sys.stderr.write("You don't have install the 3d.flf font ! Type this command the following command:\n") + sys.stderr.write("sudo cp source/fonts/3d.flf /usr/lib/python3.6/site-packages/pyfiglet/fonts\n\n") + sys.exit(0) def absolutify_links(soup, baseurl): @@ -784,7 +808,7 @@ def generate_index_and_feed(): generate_menu() generate_blog_list(feed) generate_notes_list() - overide_title() + #rewrite_title() feed.updated_datetime = current_datetime() feed.updated = ET.Element("updated") |