From a25f6bb704265207f57f8a7677d69ac56a73f3d6 Mon Sep 17 00:00:00 2001 From: NeodarZ Date: Thu, 4 May 2017 18:26:24 +0200 Subject: Add idea --- pyblog | 100 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 53 insertions(+), 47 deletions(-) (limited to 'pyblog') diff --git a/pyblog b/pyblog index 4acaa6b9..4c14e9bf 100755 --- a/pyblog +++ b/pyblog @@ -602,53 +602,59 @@ def rewrite_title(): """Override the title of some page for a better render""" sys.stderr.write("Overriding some titles\n") - 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) + 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: + soup = bs4.BeautifulSoup(open(filename), "lxml") + for h1 in soup.find_all("h1"): + if re.match("^(?!.*article-title).*$", str(h1)): + print(h1) + h1_id = h1['id'] + h1_name = h1.string + h1_ = soup.new_tag("h1") + h1_['id'] = h1_id + h1_.string = h1_name + h1.name = "span" + h1.string = "" + h1['class'] = "left-h1" + del h1['id'] + h1.string.insert_before(h1_) + print(h1) + + #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'\
\(.+?)\<\/code\>\<\/pre\>', '
'+f.renderText('Miou')+'(^._.^)ノ
', line)) + #indexmd.write(re.suv(r'\', '\', 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'\
\(.+?)\<\/code\>\<\/pre\>', '
'+f.renderText('Miou')+'(^._.^)ノ
', line)) - indexmd.write(re.suv(r'\', '\', 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): """Make links in an article absolute. @@ -806,7 +812,7 @@ def generate_index_and_feed(): generate_menu() generate_blog_list(feed) generate_notes_list() - #rewrite_title() + rewrite_title() feed.updated_datetime = current_datetime() feed.updated = ET.Element("updated") -- cgit v1.2.1