diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-07-26 18:44:53 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-07-26 18:44:53 +0200 |
commit | 4751411f5d8624dc25ffa0e2015b7984864ff387 (patch) | |
tree | cd128a4fee15046890976ae637ba035b7c5920a4 | |
parent | 9d564dc09cd54307350d2740df70befa40b66d68 (diff) |
Clean Makefile and make it run in every lang by default
-rw-r--r-- | Makefile.scm | 124 |
1 files changed, 72 insertions, 52 deletions
diff --git a/Makefile.scm b/Makefile.scm index af0e9af..67ca4a0 100644 --- a/Makefile.scm +++ b/Makefile.scm @@ -4,7 +4,10 @@ exec chibi-scheme -A utils/ $0 $@ |# (import (chibi) (chibi json) - (only (chibi filesystem) directory-files create-directory*) + (only (chibi filesystem) + directory-files + create-directory* + file-directory?) (chibi process) (only (chibi pathname) path-strip-directory path-extension make-path) ;(chibi app) @@ -19,13 +22,14 @@ exec chibi-scheme -A utils/ $0 $@ (define (directory-files-not-hidden dir) (filter - (lambda (x) (and (not (string-prefix? "." x)) - (string=? "md" (path-extension x)))) + (lambda (x) (not (string-prefix? "." x))) (directory-files dir))) (define (directory-sources lang dir) (map (lambda (x) (make-path dir lang x)) - (sort (directory-files-not-hidden (make-path dir lang)) string<?))) + (sort (filter + (lambda (x) (string=? "md" (or (path-extension x) ""))) + (directory-files-not-hidden (make-path dir lang))) string<?))) (define (directory-meta lang dir) (make-path dir lang "Metadata.yaml")) @@ -62,20 +66,21 @@ exec chibi-scheme -A utils/ $0 $@ (create-directory* outpath) (process->string-or-fail (append - `("pandoc" + (list + "pandoc" "--to=html" - "-o" ,(make-path outpath "web-simple.html") + "-o" (make-path outpath "web-simple.html") "--standalone" "--no-highlight" "--data-dir=." - ,(string-append "--resource-path=" input) + (string-append "--resource-path=" input) "--base-header-level=2" ;"--shift-heading-level-by=-1" is the new way "--template=web-simple.html" "--lua-filter=toc.lua" "--lua-filter=anchored-h.lua" - "--lua-filter=appendixes.lua") - files - `("--metadata-file" ,metafile)) + "--lua-filter=appendixes.lua" + "--metadata-file" metafile) + files) "Error in web-page creation"))) @@ -86,22 +91,23 @@ exec chibi-scheme -A utils/ $0 $@ (create-directory* outpath) (process->string-or-fail (append - `("pandoc" + (list + "pandoc" "--to=html" - "-o" ,(make-path outpath "web.html") + "-o" (make-path outpath "web.html") "--standalone" "--self-contained" "--base-header-level=2" ;"--shift-heading-level-by=-1" is the new way "--data-dir=." - ,(string-append "--resource-path=./templates/web/:" - "./templates:" - input) + (string-append "--resource-path=./templates/web/:" + "./templates:" + input) "--template=web.html" "--lua-filter=toc.lua" "--lua-filter=anchored-h.lua" - "--lua-filter=appendixes.lua") - files - `("--metadata-file" ,metafile)) + "--lua-filter=appendixes.lua" + "--metadata-file" metafile) + files) "Error in simple web-page creation"))) (define (pandoc-book lang output input) @@ -111,16 +117,17 @@ exec chibi-scheme -A utils/ $0 $@ (create-directory* outpath) (process->string-or-fail (append - `("pandoc" - "-o" ,(make-path outpath "book.pdf") + (list + "pandoc" + "-o" (make-path outpath "book.pdf") "--standalone" "--pdf-engine=xelatex" "--data-dir=." - ,(string-append "--resource-path=" input) + (string-append "--resource-path=" input) "--template=book.latex" - "--lua-filter=appendixes.lua") - files - `("--metadata-file" ,metafile)) + "--lua-filter=appendixes.lua" + "--metadata-file" metafile) + files) "Error in book creation"))) (define (pandoc-book-simple lang output input) @@ -130,16 +137,17 @@ exec chibi-scheme -A utils/ $0 $@ (create-directory* outpath) (process->string-or-fail (append - `("pandoc" - "-o" ,(make-path outpath "book-simple.pdf") + (list + "pandoc" + "-o" (make-path outpath "book-simple.pdf") "--standalone" "--pdf-engine=xelatex" "--data-dir=." - ,(string-append "--resource-path=" input) + (string-append "--resource-path=" input) "--template=book-simple.latex" - "--lua-filter=appendixes.lua") - files - `("--metadata-file" ,metafile)) + "--lua-filter=appendixes.lua" + "--metadata-file" metafile) + files) "Error in simple book creation"))) (define (pandoc-epub lang output input) @@ -149,19 +157,20 @@ exec chibi-scheme -A utils/ $0 $@ (create-directory* outpath) (process->string-or-fail (append - `("pandoc" - "-o" ,(make-path outpath "book.epub") + (list + "pandoc" + "-o" (make-path outpath "book.epub") "--standalone" "--data-dir=." - ,(string-append "--resource-path=" input) + (string-append "--resource-path=" input) "--css=./templates/ebook/epub.css" "--template=book.epub" - "--lua-filter=appendixes.lua") - files - `("--metadata-file" ,metafile)) + "--lua-filter=appendixes.lua" + "--metadata-file" metafile) + files) "Error in ebook creation"))) -(define (make-cover lang out input) +(define (make-cover lang output input) (let* ((outpath (make-path output lang)) (files (directory-sources lang input)) (metafile (directory-meta lang input)) @@ -180,22 +189,33 @@ exec chibi-scheme -A utils/ $0 $@ ,svg-file)) "Error in cover creation"))) +(define (build-lang lang output input) + (pandoc-web lang output input) + (pandoc-web-simple lang output input) + (pandoc-book lang output input) + (pandoc-book-simple lang output input) + (pandoc-epub lang output input) + (make-cover lang output input)) + +(define (get-langs input) + (filter + (lambda (l) (and (file-directory? (make-path input l)) + (= 2 (string-length l)))) + (directory-files-not-hidden input))) + +(define (build input) + (let* ((bookname (path-strip-directory (string-trim-right input #\/))) + (output (make-path "out" bookname))) + (map (lambda (lang) + (build-lang lang output input)) + (get-langs input)))) + + + + ;; RUN THIS LIKE: -;; chibi-scheme Makefile.scm src/BOOK_FOLDER +;; chibi-scheme Makefile.scm src/BOOK_FOLDER ... ;; ;; It will dump the compiled book to .out/BOOK_FOLDER/LANG/FORMAT.EXT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define args (cdr (command-line))) -(define input (car args)) -(define bookname (path-strip-directory (string-trim-right input #\/))) -(define output (make-path "out" bookname)) - - -(pandoc-web "es" output input) -(pandoc-web-simple "es" output input) -(pandoc-book "es" output input) -(pandoc-book-simple "es" output input) -(pandoc-epub "es" output input) -(make-cover "es" output input) - -;(display (cdr (assoc 'title (read-meta "src/Programming_in_Python/es/Metadata.yaml")))) +(map build (cdr (command-line))) |