init ebook maker 🎉
Signed-off-by: Baptiste Lemoine <contact@cipherbliss.com>
This commit is contained in:
commit
127957f46b
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/mon_ebook.iml" filepath="$PROJECT_DIR$/.idea/mon_ebook.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/mon_ebook.iml
Normal file
8
.idea/mon_ebook.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Générateur d'ebook à partir de markdown
|
||||||
|
|
||||||
|
ce dépot présente un dossier de travail pour générer des ebook à partir de documents écrits avec la syntaxe markdown.
|
||||||
|
|
||||||
|
éditeur de texte conseillé pour le markdown:
|
||||||
|
https://www.zettlr.com/download/deb
|
||||||
|
|
||||||
|
par tykayn pour le CIL de Gometz : www.cil-gometz.org
|
||||||
|
site perso: www.cipherbliss.com
|
0
build/.gitkeep
Normal file
0
build/.gitkeep
Normal file
50
build_ebook.sh
Normal file
50
build_ebook.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
# Ce script sert à publier le WhitePaper.
|
||||||
|
# La première version crée les documents whitepaper.md et whitepaper.html.
|
||||||
|
# Le doc Markdown complet est volontairement supprimé. Je préfère que les modifications soient faites sur les différentes parties.
|
||||||
|
# ce script doit être lancé dans le dossier contenant les chapitres.
|
||||||
|
echo "=============== génération de mon ebook, c'est parti! =============== "
|
||||||
|
# dépendances : sphinx-build pandoc
|
||||||
|
hash sphinx-build 2>/dev/null || { echo >&2 "Ce générateur a besoin de la commande sphinx-build pour fonctionner. Mais cette commande n'est pas installée. Fin de l'exécution."; exit 1; }
|
||||||
|
hash pandoc 2>/dev/null || { echo >&2 "Ce générateur peut utiliser ebook-convert fourni avec Calibre, disponible dans les dépots apt. Mais cette commande n'est pas installée. Fin de l'exécution."; exit 1; }
|
||||||
|
|
||||||
|
# clean build
|
||||||
|
rm -rf build/*
|
||||||
|
|
||||||
|
## Compilation HTML des différents chapitres
|
||||||
|
cp source/base_index.rst source/index.rst
|
||||||
|
for i in chapitres/*.rst ; do
|
||||||
|
cat $i >> source/index.rst
|
||||||
|
done
|
||||||
|
|
||||||
|
sphinx-build -b html source build
|
||||||
|
|
||||||
|
if [ -e build/index.html ] ; then
|
||||||
|
echo "===== HTML OK ====="
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Compilation PDF
|
||||||
|
sphinx-build -M latexpdf source build
|
||||||
|
# deplacement dans le fichier de build
|
||||||
|
mv ./build/latex/mon_book.pdf ./build/
|
||||||
|
|
||||||
|
#firefox "$PWD/build/whitepaper_en.html"
|
||||||
|
## add ebook conversion
|
||||||
|
|
||||||
|
#ebook-convert build/whitepaper_fr.html build/whitepaper_fr.mobi
|
||||||
|
#ebook-convert build/whitepaper_en.html build/whitepaper_en.mobi
|
||||||
|
#ebook-convert build/whitepaper_fr.html build/whitepaper_fr.fb2
|
||||||
|
#ebook-convert build/whitepaper_en.html build/whitepaper_en.fb2
|
||||||
|
#ebook-convert build/whitepaper_fr.html build/whitepaper_fr.epub
|
||||||
|
#ebook-convert build/whitepaper_en.html build/whitepaper_en.epub
|
||||||
|
|
||||||
|
echo " "
|
||||||
|
echo "===== ok pour la génération d'ebooks"
|
||||||
|
ls -lArth build
|
||||||
|
|
||||||
|
|
||||||
|
# clean fichiers temporaires
|
||||||
|
|
||||||
|
|
0
img/.gitkeep
Normal file
0
img/.gitkeep
Normal file
24
install_dependances_ubuntu.sh
Normal file
24
install_dependances_ubuntu.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo " =============================================================================================== "
|
||||||
|
echo " installation de dépendances pour faire ses propres ebook par tykayn de cipherbliss.com "
|
||||||
|
echo " =============================================================================================== "
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p " voulez-vous installer les dépendances nécessaire à la compilation d'ebook ? (o pour oui, n pour non) " yn
|
||||||
|
case $yn in
|
||||||
|
[Oo]* ) echo " nous allons installer Calibre et Pandoc avec apt; c'est parti!"; sudo apt install -y calibre pandoc; break;;
|
||||||
|
[Nn]* ) echo "bon ok ._." ; break;;
|
||||||
|
* ) echo "Veuillez répondre o pour oui, n pour non .";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p " voulez-vous cent balles et un mars ? (o pour oui, n pour non) " yn
|
||||||
|
case $yn in
|
||||||
|
[Oo]* ) echo "bah moi aussi tiens."; break;;
|
||||||
|
[Nn]* ) echo "bon ok ._." ; exit;;
|
||||||
|
* ) echo "Veuillez répondre o pour oui, n pour non .";;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
7
source/00_01_premiere_couverture.md
Normal file
7
source/00_01_premiere_couverture.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Mon livre
|
||||||
|
===
|
||||||
|
|
||||||
|
Mon sous titre
|
||||||
|
---
|
||||||
|
|
||||||
|
par Tykayn
|
3
source/00_02_preface.md
Normal file
3
source/00_02_preface.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Préface
|
||||||
|
|
||||||
|
blah blah
|
3
source/01_chapitre_1.md
Normal file
3
source/01_chapitre_1.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Chapitre 1
|
||||||
|
|
||||||
|
blah blah
|
0
source/02_chapitre_2.md
Normal file
0
source/02_chapitre_2.md
Normal file
0
source/03_chapitre_3.md
Normal file
0
source/03_chapitre_3.md
Normal file
0
source/04_chapitre_3.md
Normal file
0
source/04_chapitre_3.md
Normal file
0
source/99_00_postface.md
Normal file
0
source/99_00_postface.md
Normal file
0
source/99_01_sources.md
Normal file
0
source/99_01_sources.md
Normal file
0
source/99_03_table_des_matieres.md
Normal file
0
source/99_03_table_des_matieres.md
Normal file
0
source/99_04_derniere_couverture.md
Normal file
0
source/99_04_derniere_couverture.md
Normal file
82
table_des_matieres.sh
Normal file
82
table_des_matieres.sh
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# motivation to rewrite a simple alternative to doctoc: How Much Do You Trust That Package? Understanding The Software Supply Chain https://www.youtube.com/watch?v=fnELtqE6mMM
|
||||||
|
# src https://gist.github.com/meleu/57867f4a01ede1bd730f14b2f018ae89
|
||||||
|
|
||||||
|
############
|
||||||
|
# Generates a Table of Contents getting a markdown file as input.
|
||||||
|
#
|
||||||
|
# Inspiration for this script:
|
||||||
|
# https://medium.com/@acrodriguez/one-liner-to-generate-a-markdown-toc-f5292112fd14
|
||||||
|
#
|
||||||
|
# The list of invalid chars is probably incomplete, but is good enough for my
|
||||||
|
# current needs.
|
||||||
|
# Got the list from:
|
||||||
|
# https://github.com/thlorenz/anchor-markdown-header/blob/56f77a232ab1915106ad1746b99333bf83ee32a2/anchor-markdown-header.js#L25
|
||||||
|
#
|
||||||
|
|
||||||
|
INVALID_CHARS="'[]/?!:\`.,()*\";{}+=<>~$|#@&–—"
|
||||||
|
|
||||||
|
check() {
|
||||||
|
|
||||||
|
# src https://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Error. No argument found. Put as argument a file.md"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ ! -f "$1" ]] && echo "Error. File not found" && exit
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
toc() {
|
||||||
|
|
||||||
|
local line
|
||||||
|
local level
|
||||||
|
local title
|
||||||
|
local anchor
|
||||||
|
local output
|
||||||
|
|
||||||
|
while IFS='' read -r line || [[ -n "$line" ]]; do
|
||||||
|
level="$(echo "$line" | sed -E 's/^#(#+).*/\1/; s/#/ /g; s/^ //')"
|
||||||
|
title="$(echo "$line" | sed -E 's/^#+ //')"
|
||||||
|
anchor="$(echo "$title" | tr '[:upper:] ' '[:lower:]-' | tr -d "$INVALID_CHARS")"
|
||||||
|
output=$output"$level- [$title](#$anchor)\n"
|
||||||
|
done <<< "$(grep -E '^#{2,10} ' "$1" | tr -d '\r')"
|
||||||
|
|
||||||
|
echo "$output"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
insert() {
|
||||||
|
|
||||||
|
local toc_text="$2"
|
||||||
|
local appname='doctoc.sh'
|
||||||
|
# inspired in doctoc lines
|
||||||
|
local start_toc="<!-- START $appname generated TOC please keep comment here to allow auto update -->"
|
||||||
|
local info_toc="<!-- DO NOT EDIT THIS SECTION, INSTEAD RE-RUN $appname TO UPDATE -->"
|
||||||
|
local end_toc="<!-- END $appname generated TOC please keep comment here to allow auto update -->"
|
||||||
|
|
||||||
|
toc_block="$start_toc\n$info_toc\n**Table of Contents**\n\n$toc_text\n$end_toc"
|
||||||
|
|
||||||
|
# search multiline toc block -> https://stackoverflow.com/questions/2686147/how-to-find-patterns-across-multiple-lines-using-grep/2686705
|
||||||
|
if grep -Pzl "(?s)$start_toc.*\n.*$end_toc" $1 &>/dev/null; then
|
||||||
|
echo -e "\n Updated content of $appname block for $1 succesfully\n"
|
||||||
|
# src https://askubuntu.com/questions/533221/how-do-i-replace-multiple-lines-with-single-word-in-fileinplace-replace
|
||||||
|
sed -i ":a;N;\$!ba;s/$start_toc.*$end_toc/$toc_block/g" $1
|
||||||
|
else
|
||||||
|
echo -e "\n Created $appname block for $1 succesfully\n"
|
||||||
|
sed -i 1i"$toc_block" "$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
check "$1"
|
||||||
|
toc_text=$(toc "$1")
|
||||||
|
insert "$1" "$toc_text"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"
|
Loading…
Reference in New Issue
Block a user