added web server and sync.sh as default starting task to gulpfile
This commit is contained in:
+33
-34
@@ -92,8 +92,20 @@ def generate_html(book, toc, book_name):
|
||||
shutil.rmtree(book_build_d, ignore_errors=True)
|
||||
os.mkdir(book_build_d)
|
||||
|
||||
# main markdown book file where all pages will be merge
|
||||
book_md_f = os.path.join(book_build_d,book_name+'.md')
|
||||
#
|
||||
# create main html dom from template
|
||||
template_f = open("templates/main.tpl.html", "r")
|
||||
template_html = template_f.read()
|
||||
template_dom = BeautifulSoup(template_html, 'html.parser')
|
||||
# replace title
|
||||
template_dom.html.head.title.contents[0].replaceWith(book_name)
|
||||
# get story div
|
||||
story_dom = template_dom.find('div', {"id":"my-story"})
|
||||
|
||||
#
|
||||
# loop through pages to convert them to html and add it to main html file
|
||||
book_build_d_pages = os.path.join(book_build_d,'pages')
|
||||
os.mkdir(book_build_d_pages)
|
||||
|
||||
for p in toc:
|
||||
# print(toc[p]['file'])
|
||||
@@ -105,45 +117,32 @@ def generate_html(book, toc, book_name):
|
||||
continue
|
||||
# print('in_f : '+in_f)
|
||||
|
||||
md_f = open(in_f, 'r')
|
||||
with open(book_md_f, 'a') as fp:
|
||||
fp.write(md_f.read())
|
||||
# out_f = os.path.join(book_build_d_pages, toc[p]['file'].replace('/', '-').replace('.md', '.html'))
|
||||
# print('out_f : '+out_f)
|
||||
|
||||
pdoc_args = ['--mathjax',
|
||||
'--smart']
|
||||
|
||||
# generate html with pandoc
|
||||
output = pypandoc.convert_file(in_f,
|
||||
to='html5',
|
||||
format='md',
|
||||
extra_args=pdoc_args)
|
||||
# filters=filters,
|
||||
# outputfile=out_f)
|
||||
|
||||
# create the html file name
|
||||
html_f = book_md_f.replace('.md', '.html')
|
||||
# print('out_f : '+out_f)
|
||||
# append html story page to template_dom
|
||||
story_page = BeautifulSoup('<div class="story-page"></div>')
|
||||
story_page.div.append(BeautifulSoup(output))
|
||||
story_dom.append(story_page)
|
||||
|
||||
# pandoc options
|
||||
# filters = []
|
||||
|
||||
pdoc_args = ['-s',
|
||||
'--mathjax',
|
||||
'--smart',
|
||||
'--css=../../assets/fonts/amiri/amiri.css',
|
||||
'--css=../../assets/css/dist/main.css',
|
||||
'--include-before-body=templates/top.tpl.html',
|
||||
'--include-after-body=templates/bot.tpl.html',
|
||||
'--include-after-body=assets/lib/jquery.min.js',
|
||||
'--include-after-body=assets/js/setup.js',
|
||||
'--include-after-body=assets/js/html2print.js',
|
||||
'--include-after-body=assets/js/script.js',
|
||||
'--include-after-body=templates/end.tpl.html']
|
||||
|
||||
# pandoc command line
|
||||
# print(pypandoc.get_pandoc_version())
|
||||
output = pypandoc.convert_file(book_md_f,
|
||||
to='html5',
|
||||
format='md',
|
||||
extra_args=pdoc_args,
|
||||
# filters=filters,
|
||||
outputfile=html_f)
|
||||
# create main html file from filled template html dom
|
||||
book_html_f = os.path.join(book_build_d,book_name+'.html')
|
||||
with open(book_html_f, 'w') as fp:
|
||||
fp.write(template_dom.prettify())
|
||||
|
||||
book_toc = {
|
||||
'label':book_name,
|
||||
'file':html_f
|
||||
'file':book_html_f
|
||||
}
|
||||
|
||||
global _TOC
|
||||
|
||||
Reference in New Issue
Block a user