diff --git a/bin/build.py b/bin/build.py index ad0fc79..6035be8 100755 --- a/bin/build.py +++ b/bin/build.py @@ -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('
') + 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 diff --git a/gulpfile.js b/gulpfile.js index 3485b41..d76e48c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -6,6 +6,17 @@ var sass = require('gulp-sass'); var rename = require('gulp-rename'); var shell = require('gulp-shell') var watch = require('gulp-watch'); +var webserver = require('gulp-webserver'); + +gulp.task('webserver', function() { + gulp.src('.') + .pipe(webserver({ + livereload: false, + directoryListing: false, + open: false, + fallback: 'index.html' + })); +}); gulp.task('scss', function () { gulp.src('./assets/css/main.scss') @@ -21,12 +32,17 @@ gulp.task('gui', function () { .pipe(gulp.dest('./assets/css/dist')); }); +gulp.task('sync', shell.task([ + './bin/sync.sh' +])); + gulp.task('build', shell.task([ './bin/build.py' ])); + // default gulp task -gulp.task('default', ['scss', 'gui'], function() { +gulp.task('default', ['webserver', 'sync', 'scss', 'gui', 'build'], function() { gulp.watch('./assets/css/**/*.scss', ['scss']); gulp.watch('./assets/css/gui.scss', ['gui']); gulp.watch(['bin/build.py', './assets/css/**/*.scss', './assets/js/**/*.js', './templates/*.tpl.html'], ['build']); diff --git a/package.json b/package.json index 72d086c..2240832 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "gulp-sass": "^2.0.1", "gulp-shell": "^0.5.2", "gulp-watch": "^4.2.4", + "gulp-webserver": "^0.9.1", "gulp-wrap": "^0.11.0" }, "dependencies": {} diff --git a/templates/bot.tpl.html b/templates/bot.tpl.html deleted file mode 100644 index 03c1b7b..0000000 --- a/templates/bot.tpl.html +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/templates/main.tpl.html b/templates/main.tpl.html new file mode 100644 index 0000000..d45371f --- /dev/null +++ b/templates/main.tpl.html @@ -0,0 +1,35 @@ + + + + + Html 2 print + + + + + + + +
+
+
+
+
+ +
+
+
+
+
+ +
+ +
+ + + + + + + + diff --git a/templates/top.tpl.html b/templates/top.tpl.html deleted file mode 100644 index 6dc9f0c..0000000 --- a/templates/top.tpl.html +++ /dev/null @@ -1,12 +0,0 @@ - -
-
-
-
-
- -
-
-
-
-