Minor changes

This commit is contained in:
Nemo 2017-09-16 21:28:50 +05:30
parent d9185b5eec
commit 9a24819d34
1 changed files with 11 additions and 3 deletions

View File

@ -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 ')
@ -12,14 +14,20 @@ def setup_toc():
epub.create_epub(os.path.abspath('./build'))
def add_chapter_file(href, title):
file_path = href.replace('/sre/book/', 'html/')
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')