diff options
author | NeodarZ <neodarz@neodarz.net> | 2017-05-04 18:26:24 +0200 |
---|---|---|
committer | NeodarZ <neodarz@neodarz.net> | 2017-05-04 18:26:24 +0200 |
commit | a25f6bb704265207f57f8a7677d69ac56a73f3d6 (patch) | |
tree | 5548ed4420514efebb2cde0d9028864d805aa9f2 /pyblog | |
parent | 543f5a726bba88536fc32a1aa9a742d002d2ec0d (diff) | |
download | my_new_personal_website-a25f6bb704265207f57f8a7677d69ac56a73f3d6.tar.xz my_new_personal_website-a25f6bb704265207f57f8a7677d69ac56a73f3d6.zip |
Add idea
Diffstat (limited to '')
-rwxr-xr-x | pyblog | 100 |
1 files changed, 53 insertions, 47 deletions
@@ -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'\<pre class="header"\>\<code\>(.+?)\<\/code\>\<\/pre\>', '<pre class="header"><code>'+f.renderText('Miou')+'(^._.^)ノ</code></pre>', line)) + #indexmd.write(re.suv(r'\<code class="sourceCode diff"\>', '\<code class="sourceCode diff" id="AsourceCode"\>', 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)) - indexmd.write(re.suv(r'\<code class="sourceCode diff"\>', '\<code class="sourceCode diff" id="AsourceCode"\>', 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") |