From 15c05dbb86fe3d98ec6e6ebe7743fd85b860dcc6 Mon Sep 17 00:00:00 2001
From: NeodarZ <neodarz@neodarz.net>
Date: Mon, 1 May 2017 22:36:52 +0200
Subject: Add some test

---
 pyblog | 74 ++++++++++++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 25 deletions(-)

(limited to 'pyblog')

diff --git a/pyblog b/pyblog
index efd7711b..8d7fc377 100755
--- a/pyblog
+++ b/pyblog
@@ -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")
-- 
cgit v1.2.1