|
@@ -21,32 +21,26 @@ import re
|
|
|
|
|
|
_BOOKS_SRC = 'book-src'
|
|
|
_BUILD_d = "build"
|
|
|
-_TOC = []
|
|
|
|
|
|
|
|
|
+print("Building book")
|
|
|
def main():
|
|
|
- print("Building books")
|
|
|
- if not os.path.isdir(_BUILD_d):
|
|
|
- os.mkdir(_BUILD_d)
|
|
|
+
|
|
|
+ if os.path.isdir(_BUILD_d):
|
|
|
+ shutil.rmtree(_BUILD_d, ignore_errors=True)
|
|
|
+ os.mkdir(_BUILD_d)
|
|
|
|
|
|
-
|
|
|
- for book in os.listdir(_BOOKS_SRC):
|
|
|
- if os.path.isdir(os.path.join(_BOOKS_SRC, book)):
|
|
|
-
|
|
|
- parse_book(book)
|
|
|
-
|
|
|
- with open(_BUILD_d+'/toc.json', 'w') as fp:
|
|
|
- json.dump(_TOC, fp, ensure_ascii=False, indent="\t")
|
|
|
+ parse_book(_BOOKS_SRC)
|
|
|
|
|
|
|
|
|
def parse_book(book):
|
|
|
- book_name = book.replace('.git', '')
|
|
|
- print("- - -")
|
|
|
- print(book_name)
|
|
|
- print("- - -")
|
|
|
+
|
|
|
+
|
|
|
+ print("Parse book")
|
|
|
+
|
|
|
|
|
|
|
|
|
- sum_p = os.path.join(_BOOKS_SRC, book, "SUMMARY.md")
|
|
|
+ sum_p = os.path.join(_BOOKS_SRC, "SUMMARY.md")
|
|
|
if not os.path.isfile(sum_p):
|
|
|
print("No summary file, can't generate html")
|
|
|
return
|
|
@@ -65,9 +59,10 @@ def parse_book(book):
|
|
|
|
|
|
|
|
|
|
|
|
- generate_html(book, toc, book_name)
|
|
|
+ generate_html(book, toc)
|
|
|
|
|
|
def parse_summary(ul, toc):
|
|
|
+ print("Parse summary")
|
|
|
i=0
|
|
|
for li in ul.find_all('li',recursive=False):
|
|
|
|
|
@@ -85,33 +80,28 @@ def parse_summary(ul, toc):
|
|
|
return toc
|
|
|
|
|
|
|
|
|
-def generate_html(book, toc, book_name):
|
|
|
-
|
|
|
- book_build_d = os.path.join(_BUILD_d,book_name)
|
|
|
- if os.path.isdir(book_build_d):
|
|
|
- shutil.rmtree(book_build_d, ignore_errors=True)
|
|
|
- os.mkdir(book_build_d)
|
|
|
-
|
|
|
+def generate_html(book, toc):
|
|
|
+ print("Generate html")
|
|
|
|
|
|
|
|
|
template_f = open("templates/main.tpl.html", "r")
|
|
|
template_html = template_f.read()
|
|
|
template_dom = BeautifulSoup(template_html, 'html.parser')
|
|
|
|
|
|
- template_dom.html.head.title.contents[0].replaceWith(book_name)
|
|
|
+
|
|
|
|
|
|
story_dom = template_dom.find('div', {"id":"my-story"})
|
|
|
|
|
|
|
|
|
|
|
|
- book_build_d_pages = os.path.join(book_build_d,'pages')
|
|
|
- os.mkdir(book_build_d_pages)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
for p in toc:
|
|
|
|
|
|
|
|
|
|
|
|
- in_f = os.path.join(_BOOKS_SRC, book, toc[p]['file'])
|
|
|
+ in_f = os.path.join(_BOOKS_SRC, toc[p]['file'])
|
|
|
if not os.path.isfile(in_f):
|
|
|
print("Source path is not a file, can't generate html : "+in_f)
|
|
|
continue
|
|
@@ -136,17 +126,10 @@ def generate_html(book, toc, book_name):
|
|
|
story_dom.append(story_page)
|
|
|
|
|
|
|
|
|
- book_html_f = os.path.join(book_build_d,book_name+'.html')
|
|
|
+ book_html_f = os.path.join(_BUILD_d,'stories.html')
|
|
|
with open(book_html_f, 'w') as fp:
|
|
|
fp.write(template_dom.prettify())
|
|
|
|
|
|
- book_toc = {
|
|
|
- 'label':book_name,
|
|
|
- 'file':book_html_f
|
|
|
- }
|
|
|
-
|
|
|
- global _TOC
|
|
|
- _TOC.append(book_toc)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|