🏡 index : github.com/captn3m0/google-sre-ebook.git

author Nemo <me@captnemo.in> 2017-09-16 21:28:50.0 +05:30:00
committer Nemo <me@captnemo.in> 2017-09-16 21:28:50.0 +05:30:00
commit
9a24819d341f1fdbb73613a456e2b894d87bec3e [patch]
tree
817aabc4d6efcbfdd184b95a124853e3db11d886
parent
d9185b5eecd1ce99e064369acb691b72b6382b28
download
9a24819d341f1fdbb73613a456e2b894d87bec3e.tar.gz

Minor changes



Diff

 generate.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/generate.py b/generate.py
index 96f1fb9..51cc437 100644
--- a/generate.py
+++ a/generate.py
@@ -1,8 +1,10 @@
from bs4 import BeautifulSoup
import os, pypub
import os
import pypub

epub = pypub.Epub('Site Reliability Engineering')


def setup_toc():
    soup = BeautifulSoup(open('./html/index.html'), 'html.parser')
    links = soup.select('.content a ')
@@ -11,6 +13,7 @@
        add_chapter_file(link['href'], link.get_text())

    epub.create_epub(os.path.abspath('./build'))


def add_chapter_file(href, title):
    file_path = href.replace('/sre/book/', 'html/')
@@ -18,8 +21,13 @@
    with open(file_path, 'r') as f:
        contents = f.read()
        chapter_soup = BeautifulSoup(contents, 'html.parser')
        chapter_html = chapter_soup.select_one('.content').prettify("utf-8")
        chapter = pypub.create_chapter_from_string(chapter_html, url=None, title=title)
        chapter_soup = chapter_soup.select_one('.content')
        links = chapter_soup.select_all('a')
        for link in links:
            link.href = link.href.replace('/sre/book/chapters/', '')
        chapter = pypub.create_chapter_from_string(
            chapter_html, url=None, title=title)
        epub.add_chapter(chapter)

setup_toc()
epub.create_epub('./build')