From d9d3bf9f43c5824db6aaac0b52f739ad4c34140b Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Sat, 29 Apr 2017 16:58:38 +0200 Subject: [PATCH] refactored for one-repos use and updated readme --- .gitignore | 2 +- README.md | 13 +++++++---- bin/build.py | 57 +++++++++++++++++------------------------------- bin/sync.sh | 38 ++++++++++++-------------------- book-src/.keepme | 0 index.html | 7 +----- 6 files changed, 45 insertions(+), 72 deletions(-) delete mode 100644 book-src/.keepme diff --git a/.gitignore b/.gitignore index 3fcb8fd..db9776b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ ospkit.src OSPKit node_modules -book-src/*.git +book-src build assets/css/dist/*.css diff --git a/README.md b/README.md index 83dc6fa..e81199c 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,15 @@ source are in the directory book-src bin/build.py will read the book sources and convert them to html files using pandoc (pypandoc) -### Assets - -building process intergate in html files all the necessary assets (css/js) contained in the "assets" directory - ## Automation 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 + +## use +- sync : configure the git repository url of md book in bin/sync +- run gulp from terminale +- 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 diff --git a/bin/build.py b/bin/build.py index 6035be8..7f8a561 100755 --- a/bin/build.py +++ b/bin/build.py @@ -21,32 +21,26 @@ import re _BOOKS_SRC = 'book-src' _BUILD_d = "build" -_TOC = [] # CUR_PATH = os.path.dirname(os.path.abspath(__file__)) +print("Building book") def main(): - print("Building books") - if not os.path.isdir(_BUILD_d): - os.mkdir(_BUILD_d) + # clean build directory + if os.path.isdir(_BUILD_d): + shutil.rmtree(_BUILD_d, ignore_errors=True) + os.mkdir(_BUILD_d) - # loop through books sources - 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") + parse_book(_BOOKS_SRC) def parse_book(book): - book_name = book.replace('.git', '') - print("- - -") - print(book_name) - print("- - -") + # book_name = book.replace('.git', '') + # print("- - -") + print("Parse book") + # print("- - -") # 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): print("No summary file, can't generate html") return @@ -65,9 +59,10 @@ def parse_book(book): # print(toc) # generate final html build for html2print - generate_html(book, toc, book_name) + generate_html(book, toc) def parse_summary(ul, toc): + print("Parse summary") i=0 for li in ul.find_all('li',recursive=False): # print('li') @@ -85,33 +80,28 @@ def parse_summary(ul, toc): return toc -def generate_html(book, toc, book_name): - # build directory destination - 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) - +def generate_html(book, toc): + print("Generate html") # # 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) + # 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) + # book_build_d_pages = os.path.join(_BUILD_d,'pages') + # os.mkdir(book_build_d_pages) for p in toc: # print(toc[p]['file']) # 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): print("Source path is not a file, can't generate html : "+in_f) continue @@ -136,17 +126,10 @@ def generate_html(book, toc, book_name): story_dom.append(story_page) # 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: fp.write(template_dom.prettify()) - book_toc = { - 'label':book_name, - 'file':book_html_f - } - - global _TOC - _TOC.append(book_toc) if __name__ == "__main__": diff --git a/bin/sync.sh b/bin/sync.sh index 9f6bf64..c925800 100755 --- a/bin/sync.sh +++ b/bin/sync.sh @@ -7,36 +7,26 @@ # @Last modified time: 21-04-2017 # @License: GPL-V3 +# setup +distantrepos='https://figureslibres.io/gogs/bachir/TDSM-commissaires.git' -echo "Sync books" +# script +echo "Sync book" # activate credential cache git config --global credential.helper cache git config --global credential.helper 'cache --timeout=7200' folder='book-src' -host='https://figureslibres.io/gogs/bachir' -# echo "$host" -repos[0]='TDSM-oeuvres' -repos[1]='TDSM-notices' -repos[2]='TDSM-commissaires' -repos[3]='TDSM-english' - -# echo $repos - -for repo in "${repos[@]}" -do - echo ${repo} - 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 +if [ -d $folder/.git ]; +then + # if repos exists, pull + echo "Pull $repo" + git -C $folder pull origin master +else + # if repos does not exists, clone + echo "clone $repo" + git clone $distantrepos $folder +fi diff --git a/book-src/.keepme b/book-src/.keepme deleted file mode 100644 index e69de29..0000000 diff --git a/index.html b/index.html index 372593c..d6faac7 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,7 @@
- +
@@ -28,11 +28,6 @@ - - -