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)
|
shutil.rmtree(book_build_d, ignore_errors=True)
|
||||||
os.mkdir(book_build_d)
|
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:
|
for p in toc:
|
||||||
# print(toc[p]['file'])
|
# print(toc[p]['file'])
|
||||||
@@ -105,45 +117,32 @@ def generate_html(book, toc, book_name):
|
|||||||
continue
|
continue
|
||||||
# print('in_f : '+in_f)
|
# print('in_f : '+in_f)
|
||||||
|
|
||||||
md_f = open(in_f, 'r')
|
# out_f = os.path.join(book_build_d_pages, toc[p]['file'].replace('/', '-').replace('.md', '.html'))
|
||||||
with open(book_md_f, 'a') as fp:
|
# print('out_f : '+out_f)
|
||||||
fp.write(md_f.read())
|
|
||||||
|
|
||||||
|
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
|
# append html story page to template_dom
|
||||||
html_f = book_md_f.replace('.md', '.html')
|
story_page = BeautifulSoup('<div class="story-page"></div>')
|
||||||
# print('out_f : '+out_f)
|
story_page.div.append(BeautifulSoup(output))
|
||||||
|
story_dom.append(story_page)
|
||||||
|
|
||||||
# pandoc options
|
# create main html file from filled template html dom
|
||||||
# filters = []
|
book_html_f = os.path.join(book_build_d,book_name+'.html')
|
||||||
|
with open(book_html_f, 'w') as fp:
|
||||||
pdoc_args = ['-s',
|
fp.write(template_dom.prettify())
|
||||||
'--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)
|
|
||||||
|
|
||||||
book_toc = {
|
book_toc = {
|
||||||
'label':book_name,
|
'label':book_name,
|
||||||
'file':html_f
|
'file':book_html_f
|
||||||
}
|
}
|
||||||
|
|
||||||
global _TOC
|
global _TOC
|
||||||
|
|||||||
+17
-1
@@ -6,6 +6,17 @@ var sass = require('gulp-sass');
|
|||||||
var rename = require('gulp-rename');
|
var rename = require('gulp-rename');
|
||||||
var shell = require('gulp-shell')
|
var shell = require('gulp-shell')
|
||||||
var watch = require('gulp-watch');
|
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.task('scss', function () {
|
||||||
gulp.src('./assets/css/main.scss')
|
gulp.src('./assets/css/main.scss')
|
||||||
@@ -21,12 +32,17 @@ gulp.task('gui', function () {
|
|||||||
.pipe(gulp.dest('./assets/css/dist'));
|
.pipe(gulp.dest('./assets/css/dist'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
gulp.task('sync', shell.task([
|
||||||
|
'./bin/sync.sh'
|
||||||
|
]));
|
||||||
|
|
||||||
gulp.task('build', shell.task([
|
gulp.task('build', shell.task([
|
||||||
'./bin/build.py'
|
'./bin/build.py'
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
|
||||||
// default gulp task
|
// 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/**/*.scss', ['scss']);
|
||||||
gulp.watch('./assets/css/gui.scss', ['gui']);
|
gulp.watch('./assets/css/gui.scss', ['gui']);
|
||||||
gulp.watch(['bin/build.py', './assets/css/**/*.scss', './assets/js/**/*.js', './templates/*.tpl.html'], ['build']);
|
gulp.watch(['bin/build.py', './assets/css/**/*.scss', './assets/js/**/*.js', './templates/*.tpl.html'], ['build']);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"gulp-sass": "^2.0.1",
|
"gulp-sass": "^2.0.1",
|
||||||
"gulp-shell": "^0.5.2",
|
"gulp-shell": "^0.5.2",
|
||||||
"gulp-watch": "^4.2.4",
|
"gulp-watch": "^4.2.4",
|
||||||
|
"gulp-webserver": "^0.9.1",
|
||||||
"gulp-wrap": "^0.11.0"
|
"gulp-wrap": "^0.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
</div>
|
|
||||||
<!-- // my-story -->
|
|
||||||
</div>
|
|
||||||
<!-- // stories -->
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
|
|
||||||
</script>
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Html 2 print</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/fonts/amiri/amiri.css">
|
||||||
|
<link rel="stylesheet" href="/assets/css/dist/main.css">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- PAGES -->
|
||||||
|
<div id="pages">
|
||||||
|
<div id="master-page" class="paper">
|
||||||
|
<div class="page">
|
||||||
|
<section class="header"></section>
|
||||||
|
<section class="body recipient"></section>
|
||||||
|
<section class="footer"></section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="stories">
|
||||||
|
<div id="my-story">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- // my-story -->
|
||||||
|
</div>
|
||||||
|
<!-- // stories -->
|
||||||
|
|
||||||
|
<script src="/assets/lib/jquery.min.js" charset="utf-8"></script>
|
||||||
|
<script src="/assets/js/setup.js" charset="utf-8"></script>
|
||||||
|
<script src="/assets/js/html2print.js" charset="utf-8"></script>
|
||||||
|
<script src="/assets/js/script.js" charset="utf-8"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<!-- PAGES -->
|
|
||||||
<div id="pages">
|
|
||||||
<div id="master-page" class="paper">
|
|
||||||
<div class="page">
|
|
||||||
<section class="header"></section>
|
|
||||||
<section class="body recipient"></section>
|
|
||||||
<section class="footer"></section>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div id="stories">
|
|
||||||
<div id="my-story">
|
|
||||||
Reference in New Issue
Block a user