merge all pages from each book to one html file

This commit is contained in:
Bachir Soussi Chiadmi
2017-04-22 18:53:12 +02:00
parent 6366f20dcb
commit 909bfc1d6e
5 changed files with 145 additions and 134 deletions
+23 -23
View File
@@ -13,7 +13,7 @@
* DEFINITION OF THE PAPER SHEET * DEFINITION OF THE PAPER SHEET
*/ */
@page { @page {
size: 210mm 291mm; size: 234mm 315mm;
margin: 0; } margin: 0; }
/** /**
@@ -23,19 +23,19 @@
body { body {
margin: 0; } margin: 0; }
.paper { .paper {
width: 210mm; width: 234mm;
height: 290mm; height: 314mm;
box-sizing: border-box; box-sizing: border-box;
counter-increment: page-counter; counter-increment: page-counter;
page-break-inside: avoid; page-break-inside: avoid;
page-break-after: always; page-break-after: always;
overflow: hidden; overflow: hidden;
/* Crop marks */ /* Crop marks */
padding: 0mm; padding: 12mm;
position: relative; } position: relative; }
.paper .crops { .paper .crops {
width: 210mm; width: 234mm;
height: 290mm; height: 314mm;
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; } left: 0; }
@@ -43,13 +43,13 @@
border-style: solid; border-style: solid;
border-color: black; border-color: black;
border-width: 0; border-width: 0;
width: 0mm; width: 12mm;
height: 0mm; height: 12mm;
position: absolute; position: absolute;
box-sizing: border-box; } box-sizing: border-box; }
.paper .crops div span { .paper .crops div span {
width: 0mm; width: 5mm;
height: 0mm; height: 5mm;
background-color: white; background-color: white;
position: absolute; } position: absolute; }
.paper .crops .crop-top-left { .paper .crops .crop-top-left {
@@ -93,15 +93,15 @@
.spread .paper { .spread .paper {
float: left; } float: left; }
.spread .paper:nth-child(odd) { .spread .paper:nth-child(odd) {
margin-left: 0mm; } margin-left: -12mm; }
.spread .paper:nth-child(even) { .spread .paper:nth-child(even) {
margin-right: 0mm; } margin-right: -12mm; }
.spread .paper:first-child { .spread .paper:first-child {
margin-left: 210mm; } } margin-left: 210mm; } }
@media print { @media print {
html { html {
width: 210mm; } width: 234mm; }
body { body {
/* Allows printing of background colors */ /* Allows printing of background colors */
background-color: white; background-color: white;
@@ -132,7 +132,7 @@
.header { .header {
top: 0; top: 0;
margin: 0; margin: 0;
padding-top: 8mm; padding-top: 10mm;
width: 100%; width: 100%;
height: 10mm; height: 10mm;
text-align: left; } text-align: left; }
@@ -143,9 +143,9 @@
.body { .body {
height: 270mm; height: 270mm;
width: 210mm; width: 210mm;
margin-bottom: 12mm; margin-bottom: 15mm;
padding-top: 18mm; padding-top: 20mm;
padding-bottom: 12mm; padding-bottom: 15mm;
position: absolute; } position: absolute; }
.recipient { .recipient {
@@ -175,12 +175,12 @@
.paper:nth-child(odd) .body, .paper:nth-child(odd) .body,
.paper:nth-child(odd) .footer { .paper:nth-child(odd) .footer {
padding-left: 20mm; padding-left: 20mm;
padding-right: 20mm; } padding-right: 10mm; }
.paper:nth-child(even) .header, .paper:nth-child(even) .header,
.paper:nth-child(even) .body, .paper:nth-child(even) .body,
.paper:nth-child(even) .footer { .paper:nth-child(even) .footer {
padding-left: 20mm; padding-left: 10mm;
padding-right: 20mm; } padding-right: 20mm; }
img { img {
@@ -233,13 +233,13 @@ p {
body { body {
background-color: #F0F0F0; } background-color: #F0F0F0; }
#pages { #pages {
width: 210mm; width: 234mm;
height: 290mm; height: 314mm;
margin-left: auto; margin-left: auto;
margin-right: auto; } margin-right: auto; }
.spread #pages { .spread #pages {
width: 420mm; width: 468mm;
height: 580mm; } height: 628mm; }
.paper { .paper {
/* centrer la page à l'écran */ /* centrer la page à l'écran */
background-color: white; background-color: white;
+5 -5
View File
@@ -3,10 +3,10 @@ $page-width: 210mm;
$page-height: 290mm; $page-height: 290mm;
/* the size of the crop marks*/ /* the size of the crop marks*/
$crop-size: 0mm; $crop-size: 7mm;
/* the size of bleed */ /* the size of bleed */
$bleed: 0mm; $bleed: 5mm;
// page layouts // page layouts
// 1 for single page // 1 for single page
@@ -14,9 +14,9 @@ $bleed: 0mm;
$page-layout:1; $page-layout:1;
$page-margin-inside: 20mm; $page-margin-inside: 20mm;
$page-margin-outside: 20mm; $page-margin-outside: 10mm;
$page-margin-top: 8mm; $page-margin-top: 10mm;
$page-margin-bottom: 12mm; $page-margin-bottom: 15mm;
// Header & footer variables // Header & footer variables
$header-height: 10mm; $header-height: 10mm;
+63 -53
View File
@@ -4,12 +4,15 @@ $(function() {
// console.log(data); // console.log(data);
for (book of data) { for (book of data) {
// console.log(book); // console.log(book);
var $optgroup = $('<optgroup>').attr('label', book.label); // var $optgroup = $('<optgroup>').attr('label', book.label);
for (page of book.pages) { // for (page of book.pages) {
// console.log(page); // // console.log(page);
$optgroup.append($('<option>').attr('value', book.label+'/'+page.file).text(book.label+' : '+page.label)); // $optgroup.append($('<option>').attr('value', book.label+'/'+page.file).text(book.label+' : '+page.label));
} // }
$('[name="document"]').append($optgroup); $('[name="document"]').append(
$('<option>')
.attr('value', book.file).text(book.label)
);
} }
}) })
@@ -17,30 +20,37 @@ $(function() {
// console.log(e); // console.log(e);
// var optionSelected = $("option:selected", this); // var optionSelected = $("option:selected", this);
// var valueSelected = ; // var valueSelected = ;
console.log(this.value); // console.log(this.value);
$('iframe').attr('src', 'build/'+this.value); $('iframe').attr('src', this.value);
}); });
// activate toolbar events when iframe is loaded // activate toolbar events when iframe is loaded
$('iframe').load(function() { $('iframe').load(function() {
var doc = $("iframe").contents().find("html"); initIframe();
});
$('[name="preview"]').change(function() { function initIframe(){
if($(this).is(":checked")) { var doc = $("iframe").contents().find("html");
doc.addClass("preview"); console.log('initIframe :: doc', doc);
doc.removeClass("normal");
} else { $('input[name="preview"]').change(function(e) {
doc.removeClass("preview"); console.log('Preview',e);
doc.addClass("normal"); if($(this).is(":checked")) {
} doc.addClass("preview");
doc.removeClass("normal");
} else {
doc.removeClass("preview");
doc.addClass("normal");
}
}); });
$('[name="debug"]').change(function() { $('[name="debug"]').change(function() {
if($(this).is(":checked")) {
doc.addClass("debug"); if($(this).is(":checked")) {
} else { doc.addClass("debug");
doc.removeClass("debug"); } else {
} doc.removeClass("debug");
}
}); });
$('[name="spread"]').change(function() { $('[name="spread"]').change(function() {
@@ -51,42 +61,42 @@ $(function() {
} }
}); });
//$('[name="hi-res"]').change(function() { //$('[name="hi-res"]').change(function() {
//if($(this).is(":checked")) { //if($(this).is(":checked")) {
//doc.addClass("export"); //doc.addClass("export");
//} else { //} else {
//doc.removeClass("export"); //doc.removeClass("export");
//} //}
//}); //});
$('[name="zoom"]').change(function() { $('[name="zoom"]').change(function() {
zoomLevel = $(this).val() / 100; zoomLevel = $(this).val() / 100;
doc.find("#pages").css({ doc.find("#pages").css({
"-webkit-transform": "scale(" + zoomLevel + ")", "-webkit-transform": "scale(" + zoomLevel + ")",
"-webkit-transform-origin": "0 0" "-webkit-transform-origin": "0 0"
});
});
//$(".paper").each(function(){
//page = $(this).attr("id");
//$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
//});
$('[name="page"]').change(function() {
var pageNumber = $(this).val() - 1;
var target = doc.find('.paper:eq(' + pageNumber + ')');
var offsetTop = target.offset().top;
doc.find('body').scrollTop(offsetTop);
});
$("#print").on('click', function() {
$("iframe").get(0).contentWindow.print();
}); });
}); });
//$(".paper").each(function(){
//page = $(this).attr("id");
//$("#toc-pages").append("<li><a href='#" + page + "'>" + page.replace("-", " ") + "</a></li>")
//});
$('[name="page"]').change(function() {
var pageNumber = $(this).val() - 1;
var target = doc.find('.paper:eq(' + pageNumber + ')');
var offsetTop = target.offset().top;
doc.find('body').scrollTop(offsetTop);
});
$("#print").on('click', function() {
$("iframe").get(0).contentWindow.print();
});
}
//// __________________________________ HIGH RESOLUTION __________________________________ // //// __________________________________ HIGH RESOLUTION __________________________________ //
//$("#hi-res").click(function(e){ //$("#hi-res").click(function(e){
//e.preventDefault(); //e.preventDefault();
+51 -52
View File
@@ -19,23 +19,23 @@ import pypandoc
import json import json
import re import re
BOOKS_SRC = 'book-src' _BOOKS_SRC = 'book-src'
BUILD_d = "build" _BUILD_d = "build"
CUR_PATH = os.path.dirname(os.path.abspath(__file__))
_TOC = [] _TOC = []
# CUR_PATH = os.path.dirname(os.path.abspath(__file__))
def main(): def main():
print("Building books") print("Building books")
if not os.path.isdir(BUILD_d): if not os.path.isdir(_BUILD_d):
os.mkdir(BUILD_d) os.mkdir(_BUILD_d)
# loop through books sources # loop through books sources
for book in os.listdir(BOOKS_SRC): for book in os.listdir(_BOOKS_SRC):
if os.path.isdir(os.path.join(BOOKS_SRC, book)): if os.path.isdir(os.path.join(_BOOKS_SRC, book)):
# print(book) # print(book)
parse_book(book) parse_book(book)
with open(BUILD_d+'/toc.json', 'w') as fp: with open(_BUILD_d+'/toc.json', 'w') as fp:
json.dump(_TOC, fp, ensure_ascii=False, indent="\t") json.dump(_TOC, fp, ensure_ascii=False, indent="\t")
@@ -46,7 +46,7 @@ def parse_book(book):
print("- - -") print("- - -")
# table of content (ordered list of markdown files) # table of content (ordered list of markdown files)
sum_p = os.path.join(BOOKS_SRC, book, "SUMMARY.md") sum_p = os.path.join(_BOOKS_SRC, book, "SUMMARY.md")
if not os.path.isfile(sum_p): if not os.path.isfile(sum_p):
print("No summary file, can't generate html") print("No summary file, can't generate html")
return return
@@ -84,71 +84,70 @@ def parse_summary(ul, toc):
return toc return toc
def generate_html(book, toc, book_name): def generate_html(book, toc, book_name):
# build directory destination
book_build_d = os.path.join(_BUILD_d,book_name)
# build destination
book_build_d = os.path.join(BUILD_d,book_name)
if os.path.isdir(book_build_d): if os.path.isdir(book_build_d):
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)
book_toc = { # main markdown book file where all pages will be merge
'label':book_name, book_md_f = os.path.join(book_build_d,book_name+'.md')
'pages':[]
}
for p in toc: for p in toc:
# print(toc[p]['file']) # print(toc[p]['file'])
# generate html with pandoc
# files # files
md_f = toc[p]['file'] in_f = os.path.join(_BOOKS_SRC, book, toc[p]['file'])
in_f = os.path.join(BOOKS_SRC, book, md_f)
if not os.path.isfile(in_f): if not os.path.isfile(in_f):
print("Source path is not a file, can't generate html : "+in_f) print("Source path is not a file, can't generate html : "+in_f)
continue continue
# print('in_f : '+in_f) # print('in_f : '+in_f)
html_f = md_f.replace('.md', '.html') md_f = open(in_f, 'r')
html_f = html_f.replace('README', 'index') with open(book_md_f, 'a') as fp:
html_f = html_f.replace('/', '-') fp.write(md_f.read())
out_f = os.path.join(book_build_d,html_f)
# print('out_f : '+out_f)
# pandoc options
# filters = []
pdoc_args = ['-s', # generate html with pandoc
'--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 # create the html file name
# print(pypandoc.get_pandoc_version()) html_f = book_md_f.replace('.md', '.html')
output = pypandoc.convert_file(in_f, # print('out_f : '+out_f)
to='html5',
format='md',
extra_args=pdoc_args,
# filters=filters,
outputfile=out_f)
# save reference in railway # pandoc options
book_toc['pages'].append({'label':toc[p]['label'], 'file':html_f}) # 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)
book_toc = {
'label':book_name,
'file':html_f
}
global _TOC global _TOC
_TOC.append(book_toc) _TOC.append(book_toc)
# save railway as json file
# with open(book_build_d+'/railway.json', 'w') as fp:
# json.dump(railway, fp, ensure_ascii=False, indent="\t")
if __name__ == "__main__": if __name__ == "__main__":
+3 -1
View File
@@ -29,7 +29,9 @@
<input name="zoom" value="100" type="number" min="25" max="1600" step="25"> <input name="zoom" value="100" type="number" min="25" max="1600" step="25">
<label for="document">document</label> <label for="document">document</label>
<select name="document"></select> <select name="document">
<option value="0">Choose a document</option>
</select>
<label for="page">page</label> <label for="page">page</label>
<input name="page" value="1" type="number" min="1" max="100" step="1"> <input name="page" value="1" type="number" min="1" max="100" step="1">