13 changed files with 66 additions and 90 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
ospkit.src ospkit.src
OSPKit OSPKit
node_modules node_modules
book-src/*.git book-src
build build
assets/css/dist/*.css assets/css/dist/*.css
+23 -8
View File
@@ -1,18 +1,33 @@
# HTML2PRINT : tous des sangs mélé # HTML2PRINT with gitbook content management
*/!\ WORK IN PROGRESS*
## Book src ## Book src
bin/sync.sh will pull books from git repositories listed in the the script bin/sync.sh will first clone then pull books from git repositories listed in the the script into the directory book-src
source are in the directory book-src
## Building ## Building
bin/build.py will read the book sources and convert them to html files using pandoc (pypandoc) bin/build.py will read the book sources and convert them to html files using pandoc (pypandoc) and BeautifulSoup
### Assets
building process intergate in html files all the necessary assets (css/js) contained in the "assets" directory
## Automation ## Automation
gulp is watching assets files to convert scss to css and then rebuild html pages gulp is watching assets files to convert scss to css and then rebuild html pages
gulp is also runing once on launch a webserver accessible a localhost:8000 and the bin/sync script
## dependencies
- nodejs
- python3
- css-region compatible web browser (webkit)
## use
- clone this repos
- run ```npm install```
- sync : configure the git repository url of md book in *bin/sync*
- run ```gulp``` from terminal
- configure book's main properties in assets/css/setup.scss and assets/js/setup.js
- access to your book at ```localhost:8000``` from a css-region-compatible webbrowser
- start to design your book with assets/css/styles.css
- it's also possible to add any dynamic javascript formatting with assets/js/script.js
## thanks to [osp](http://osp.kitchen/) for their [html2print boilerplate](https://gitlab.constantvzw.org/osp/tools.html2print)
+3
View File
@@ -68,6 +68,9 @@ $(function() {
doc.removeClass("spread"); doc.removeClass("spread");
} }
}); });
if(spread){
$('[name="spread"]').prop('checked', true).change();
}
//$('[name="hi-res"]').change(function() { //$('[name="hi-res"]').change(function() {
//if($(this).is(":checked")) { //if($(this).is(":checked")) {
+1 -1
View File
@@ -1,3 +1,3 @@
nb_page = 100; nb_page = 100;
cropmarks = false; spread = true;
+20 -37
View File
@@ -21,32 +21,26 @@ import re
_BOOKS_SRC = 'book-src' _BOOKS_SRC = 'book-src'
_BUILD_d = "build" _BUILD_d = "build"
_TOC = []
# CUR_PATH = os.path.dirname(os.path.abspath(__file__)) # CUR_PATH = os.path.dirname(os.path.abspath(__file__))
print("Building book")
def main(): def main():
print("Building books") # clean build directory
if not os.path.isdir(_BUILD_d): if os.path.isdir(_BUILD_d):
os.mkdir(_BUILD_d) shutil.rmtree(_BUILD_d, ignore_errors=True)
os.mkdir(_BUILD_d)
# loop through books sources parse_book(_BOOKS_SRC)
for book in os.listdir(_BOOKS_SRC):
if os.path.isdir(os.path.join(_BOOKS_SRC, book)):
# print(book)
parse_book(book)
with open(_BUILD_d+'/toc.json', 'w') as fp:
json.dump(_TOC, fp, ensure_ascii=False, indent="\t")
def parse_book(book): def parse_book(book):
book_name = book.replace('.git', '') # book_name = book.replace('.git', '')
print("- - -") # print("- - -")
print(book_name) print("Parse 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, "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
@@ -65,9 +59,10 @@ def parse_book(book):
# print(toc) # print(toc)
# generate final html build for html2print # generate final html build for html2print
generate_html(book, toc, book_name) generate_html(book, toc)
def parse_summary(ul, toc): def parse_summary(ul, toc):
print("Parse summary")
i=0 i=0
for li in ul.find_all('li',recursive=False): for li in ul.find_all('li',recursive=False):
# print('li') # print('li')
@@ -85,33 +80,28 @@ def parse_summary(ul, toc):
return toc return toc
def generate_html(book, toc, book_name): def generate_html(book, toc):
# build directory destination print("Generate html")
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)
# #
# create main html dom from template # create main html dom from template
template_f = open("templates/main.tpl.html", "r") template_f = open("templates/main.tpl.html", "r")
template_html = template_f.read() template_html = template_f.read()
template_dom = BeautifulSoup(template_html, 'html.parser') template_dom = BeautifulSoup(template_html, 'html.parser')
# replace title # replace title
template_dom.html.head.title.contents[0].replaceWith(book_name) # template_dom.html.head.title.contents[0].replaceWith(book_name)
# get story div # get story div
story_dom = template_dom.find('div', {"id":"my-story"}) story_dom = template_dom.find('div', {"id":"my-story"})
# #
# loop through pages to convert them to html and add it to main html file # 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') # book_build_d_pages = os.path.join(_BUILD_d,'pages')
os.mkdir(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'])
# files # files
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): 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
@@ -136,17 +126,10 @@ def generate_html(book, toc, book_name):
story_dom.append(story_page) story_dom.append(story_page)
# create main html file from filled template html dom # create main html file from filled template html dom
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: with open(book_html_f, 'w') as fp:
fp.write(template_dom.prettify()) fp.write(template_dom.prettify())
book_toc = {
'label':book_name,
'file':book_html_f
}
global _TOC
_TOC.append(book_toc)
if __name__ == "__main__": if __name__ == "__main__":
+14 -24
View File
@@ -7,36 +7,26 @@
# @Last modified time: 21-04-2017 # @Last modified time: 21-04-2017
# @License: GPL-V3 # @License: GPL-V3
# setup
distantrepos='https://figureslibres.io/gogs/bachir/TDSM-commissaires.git'
echo "Sync books" # script
echo "Sync book"
# activate credential cache # activate credential cache
git config --global credential.helper cache git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=7200' git config --global credential.helper 'cache --timeout=7200'
folder='book-src' folder='book-src'
host='https://figureslibres.io/gogs/bachir'
# echo "$host"
repos[0]='TDSM-oeuvres' if [ -d $folder/.git ];
repos[1]='TDSM-notices' then
repos[2]='TDSM-commissaires' # if repos exists, pull
repos[3]='TDSM-english' echo "Pull $repo"
git -C $folder pull origin master
# echo $repos else
# if repos does not exists, clone
for repo in "${repos[@]}" echo "clone $repo"
do git clone $distantrepos $folder
echo ${repo} fi
if [ -d $folder/$repo.git ];
then
# if repos exists, pull
echo "Pull $repo"
git -C $folder/$repo.git pull origin master
else
# if repos does not exists, clone
echo "clone $repo"
git clone $host/$repo.git $folder/$repo.git
fi
done
View File
-3
View File
@@ -1,7 +1,6 @@
'use strict'; 'use strict';
var gulp = require('gulp'); var gulp = require('gulp');
var wrap = require('gulp-wrap');
var sass = require('gulp-sass'); 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')
@@ -21,14 +20,12 @@ gulp.task('webserver', function() {
gulp.task('scss', function () { gulp.task('scss', function () {
gulp.src('./assets/css/main.scss') gulp.src('./assets/css/main.scss')
.pipe(sass().on('error', sass.logError)) .pipe(sass().on('error', sass.logError))
.pipe(wrap('<style type="text/css">\n<%= contents %>\n</style>'))
.pipe(gulp.dest('./assets/css/dist')); .pipe(gulp.dest('./assets/css/dist'));
}); });
gulp.task('gui', function () { gulp.task('gui', function () {
gulp.src('./assets/css/gui.scss') gulp.src('./assets/css/gui.scss')
.pipe(sass().on('error', sass.logError)) .pipe(sass().on('error', sass.logError))
// .pipe(wrap('<style type="text/css">\n<%= contents %>\n</style>'))
.pipe(gulp.dest('./assets/css/dist')); .pipe(gulp.dest('./assets/css/dist'));
}); });
+2 -6
View File
@@ -9,7 +9,7 @@
</head> </head>
<body> <body>
<div id="viewport"> <div id="viewport">
<iframe src=""></iframe> <iframe src="build/stories.html"></iframe>
</div> </div>
<div id="toolbar"> <div id="toolbar">
@@ -28,11 +28,6 @@
<label for="zoom">zoom</label> <label for="zoom">zoom</label>
<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>
<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">
@@ -43,6 +38,7 @@
<!-- JAVASCRIPT --> <!-- JAVASCRIPT -->
<script type="text/javascript" src="/assets/lib/jquery.min.js"></script> <script type="text/javascript" src="/assets/lib/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/setup.js"></script>
<script type="text/javascript" src="/assets/js/gui.js"></script> <script type="text/javascript" src="/assets/js/gui.js"></script>
</body> </body>
</html> </html>
-1
View File
@@ -17,7 +17,6 @@
"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-webserver": "^0.9.1",
"gulp-wrap": "^0.11.0"
}, },
"dependencies": {} "dependencies": {}
} }
-8
View File
@@ -1,8 +0,0 @@
#! /usr/bin/env bash
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
DIR="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $DIR
python -m http.server
+2 -1
View File
@@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html class="normal">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Html 2 print</title> <title>Html 2 print</title>
@@ -7,6 +7,7 @@
<link rel="stylesheet" href="/assets/fonts/amiri/amiri.css"> <link rel="stylesheet" href="/assets/fonts/amiri/amiri.css">
<link rel="stylesheet" href="/assets/css/dist/main.css"> <link rel="stylesheet" href="/assets/css/dist/main.css">
</head> </head>
<body> <body>
<!-- PAGES --> <!-- PAGES -->