summaryrefslogtreecommitdiff
path: root/platform/bin/doku2md.sh
diff options
context:
space:
mode:
Diffstat (limited to 'platform/bin/doku2md.sh')
-rwxr-xr-xplatform/bin/doku2md.sh269
1 files changed, 162 insertions, 107 deletions
diff --git a/platform/bin/doku2md.sh b/platform/bin/doku2md.sh
index 635effb..a7839e8 100755
--- a/platform/bin/doku2md.sh
+++ b/platform/bin/doku2md.sh
@@ -2,148 +2,203 @@
# USO : ./doku2md.sh ../../content/illich/contents/books/deschooling/en.txt
# Genera un .md en la misma carpeta del archivo. Luego ese .md se puede usar dentro de la carpeta book para generar un PDF.
-
+# ./contents_compile.sh <collection> <type> <item>
+# ./contents_compile.sh illich book abc
### Script para dejar listo los .txt de Doku para hacerlos markdown
-url='https://illich.test/'
-IFS=$'\n'
-# Arregla footnotes
+cd `dirname $0`
- dir=`dirname $1`
- name=`echo $1 | sed 's/\.txt//g'`
- lang=${name: -2}
- echo "DIR: $dir"
- echo "NAME: $name"
- echo "LANG: $lang"
+COLLECTION=$1
+TYPE=$2
+ITEM=$3
- read
+AUTHOR=`cat ../../content/$COLLECTION/conf/local.php | grep author | cut -d "'" -f4`
- ## Corta el archivo en dos, empezando por la linea de la primera footnote
+FOLDER="../../content/$COLLECTION/contents/$TYPE/$ITEM"
+URL=`cat ../../platform/www/conf/farm.ini | grep basedomain | cut -d '"' -f 2`
- n=`grep -n -m 1 ':]' $1 |sed 's/\([0-9]*\).*/\1/'`
+IFS=$'\n'
- csplit -s $1 $n -f $1.tmp.
+DIR=$FOLDER
+name=$ITEM
- ## Agrega saltos de linea y elimina corchete final
- grep ':]' $1.tmp.01 | perl -p -e 's/\n/\n\n/' > $1.footer.tmp
+#
+# echo "URL: $URL"
+#
+# echo "DIR: $DIR"
+# echo "NAME: $name"
+#
+# read
- sed -i 's/]$//g' $1.footer.tmp
+cd $DIR
- ## Unifica todo y corrige corchete de apertura
+LANGS=("en" "es")
+for lng in ${LANGS[@]}; do
- cat $1.tmp.00 > $1.tmp
+ FILE="$lng.txt"
+ # Arregla footnotes
+ ## Corta el archivo en dos, empezando por la linea de la primera footnote
+ if [ -f $FILE ]; then
+ echo "---- File $FILE exists."
- cat $1.footer.tmp >> $1.tmp
+ n=`grep -n -m 1 ':]' $FILE |sed 's/\([0-9]*\).*/\1/'`
- sed 's/:]/]:/g' $1.tmp > $name.body.tmp
+ if [ -z "$n" ]; then
+ cat $FILE > $lng.body.tmp
+ else
+ csplit -s $FILE $n -f $lng.tmp.
- cat $name.body.tmp
+ ## Agrega saltos de linea y elimina corchete final
- read
+ grep ':]' $lng.tmp.01 | perl -p -e 's/\n/\n\n/' > $lng.footer.tmp
- ## Borra temporales
+ sed -i 's/]$//g' $lng.footer.tmp
+ ## Unifica todo y corrige corchete de apertura
+ cat $lng.tmp.00 > $lng.tmp
+ cat $lng.footer.tmp >> $lng.tmp
-# agregar cabecera para pandoc!
+ sed 's/:]/]:/g' $lng.tmp > $lng.body.tmp
-if test -f "$dir/index"; then
- echo "hay index"
- LANGORIG=`cat "$dir/index" | grep langorig | cut -d "@" -f 4 | cut -d "_" -f 3`
- if [[ $lang == $LANGORIG ]]; then
- echo "Se procesa en idioma original"
- yaml_title=`grep 'LANG_titleorig' "$dir/index" | cut -d '_' -f3`
- else
- echo "No se procesa en idioma original"
- yaml_title=`head -n1 $1 | sed s/\#\ //`
- fi
+ # cat $lng.body.tmp
+ fi
- yaml_date=`grep 'LANG_publicationdate' "$dir/index" | cut -d ':' -f2 | sed 's/** //'`
- yaml_author=`grep 'LANG_author' "$dir/index" | cut -d ':' -f2 | sed 's/ //'`
- if [ -z "$yaml_author" ]
- then
- yaml_author="Ivan Illich"
- else
- case $lang in
- en)
- yaml_author=`echo $yaml_author | sed 's/, / and /g'`
- ;;
- es)
- yaml_author=`echo $yaml_author | sed 's/, / y /g'`
- ;;
- esac
- fi
- # meta=`echo "$name.changes" | sed 's/pages/meta/'`
- # # el numero de revision es un unix timestamp
- # revision=`cat $meta | tail -n1 | cut -f1`
- #
- # # ../../content/data/pages/es/book/gender/es
- # # http://illich.test/es:book:gender:es?rev=1620353793
- # webpage=`echo $name | sed 's/^.*pages\///'| sed 's/\//:/g'`
-
-
- echo "---
-title: \"$yaml_title\"
-author: \"$yaml_author\"
-date: \"$yaml_date\"
-lang: \"$lang\"
-documentclass: book
-classoption:
-- oneside
-geometry: margin=1.75in
-fontsize: 12pt
-fontfamily: ebgaramond-maths
-newtxmathoptions:
-- cmintegrals
-- cmbraces
-toc: true
-colorlinks: true
-linkcolor: RoyalBlue
-urlcolor: RoyalBlue
-titlepage: true
----" > $name.head.tmp
-fi
-echo ""
-echo ""
-cat $name.head.tmp
+ ## Borra temporales
+
+
-read
-## Hay que cambiar los titulos
+ # agregar cabecera para pandoc!
-sed -i 1d $name.body.tmp
-sed -i 's/^## /# /g' $name.body.tmp
-sed -i 's/^### /## /g' $name.body.tmp
-sed -i 's/^#### /### /g' $name.body.tmp
-sed -i 's/^##### /#### /g' $name.body.tmp
-sed -i 's/^###### /##### /g' $name.body.tmp
+ if test -f "index"; then
+ echo "hay index"
+ LANGORIG=`cat "index" | grep langorig | cut -d "@" -f 4 | cut -d "_" -f 3`
-cat $name.head.tmp > $name.md
-cat $name.body.tmp >> $name.md
+ if [[ $lng == $LANGORIG ]]; then
+ echo "Se procesa en idioma original"
+ yaml_title=`grep 'LANG_titleorig' "index" | cut -d '_' -f3 | sed s/\"/\'/g`
+ else
+ echo "No se procesa en idioma original"
+ yaml_title=`head -n1 $FILE | sed s/\#\ // | sed s/\"/\'/g`
+ fi
-# Mas https://github.com/alexeygumirov/pandoc-for-pdf-how-to
-# ---
-# title: "Towards Illich's 'legibility'"
-# subtitle: "Returning to Ivan through the Mirror of the Past"
-# author: "Le Goliard[^fb42]"
-# date: "2020-11-29 / Version 1.3[^b840]"
-# # abstract: "The important thing is love"
-# keywords: "Illich, JIS"
-# bibliography: "illich_legibility-en.bib"
-# lang: "es-ES"
-# rights: "This work is published under the terms of the license 'Do What the Fuck You Want to Public License 2.0' (WTFPL 2.0). For more information see: https://en.wikipedia.org/wiki/WTFPL"
-# ---
+ yaml_date=`grep 'LANG_publicationdate' "index" | cut -d ':' -f2 | sed 's/** //'`
+ if [[ $yaml_date == "*YEAR*" ]]; then
+ # If the Year is not defined, we try to take it from the path
+ yaml_date=`echo $PWD/$FILE | cut -d "-" -f 1 | rev | cut -d '/' -f1 | rev`
+ fi
+ yaml_author=`grep 'LANG_author' "index" | cut -d ':' -f2 | sed 's/ //'`
+ if [ -z "$yaml_author" ]
+ then
+ yaml_author=$AUTHOR
+ else
+ case $lng in
+ en)
+ yaml_author=`echo $yaml_author | sed 's/, / and /g'`
+ ;;
+ es)
+ yaml_author=`echo $yaml_author | sed 's/, / y /g'`
+ ;;
+ esac
+ fi
+ # meta=`echo "$name.changes" | sed 's/pages/meta/'`
+ # # el numero de revision es un unix timestamp
+ # revision=`cat $meta | tail -n1 | cut -f1`
+ #
+ # # ../../content/data/pages/es/book/gender/es
+ # # http://illich.test/es:book:gender:es?rev=1620353793
+ # webpage=`echo $name | sed 's/^.*pages\///'| sed 's/\//:/g'`
+ case $TYPE in
+ book)
+ echo "---
+ title: \"$yaml_title\"
+ author: \"$yaml_author\"
+ date: \"$yaml_date\"
+ lang: \"$lng\"
+ documentclass: book
+ classoption:
+ - oneside
+ geometry: margin=1.75in
+ fontsize: 12pt
+ fontfamily: ebgaramond-maths
+ newtxmathoptions:
+ - cmintegrals
+ - cmbraces
+ toc: true
+ colorlinks: true
+ linkcolor: RoyalBlue
+ urlcolor: RoyalBlue
+titlepage: true
+---" > $lng.head.tmp
+ ;;
+ article)
+ echo "---
+ title: \"$yaml_title\"
+ author: \"$yaml_author\"
+ date: \"$yaml_date\"
+ lang: \"$lng\"
+ documentclass: article
+ geometry: margin=1.75in
+ fontsize: 12pt
+ fontfamily: ebgaramond-maths
+ colorlinks: true
+ linkcolor: RoyalBlue
+ urlcolor: RoyalBlue
+---" > $lng.head.tmp
+ ;;
+ #...
+ *)
+ comandos
+ ;;
+ esac
+
+
+ fi
+ echo ""
+ echo ""
+
+ # cat $lng.head.tmp
+
+ ## Hay que cambiar los titulos
+
+ sed -i 1d $lng.body.tmp
+ sed -i 's/^## /# /g' $lng.body.tmp
+ sed -i 's/^### /## /g' $lng.body.tmp
+ sed -i 's/^#### /### /g' $lng.body.tmp
+ sed -i 's/^##### /#### /g' $lng.body.tmp
+ sed -i 's/^###### /##### /g' $lng.body.tmp
+
+ cat $lng.head.tmp > $lng.md
+ cat $lng.body.tmp >> $lng.md
+
+
+ # Mas https://github.com/alexeygumirov/pandoc-for-pdf-how-to
+ # ---
+ # title: "Towards Illich's 'legibility'"
+ # subtitle: "Returning to Ivan through the Mirror of the Past"
+ # author: "Le Goliard[^fb42]"
+ # date: "2020-11-29 / Version 1.3[^b840]"
+ # # abstract: "The important thing is love"
+ # keywords: "Illich, JIS"
+ # bibliography: "illich_legibility-en.bib"
+ # lang: "es-ES"
+ # rights: "This work is published under the terms of the license 'Do What the Fuck You Want to Public License 2.0' (WTFPL 2.0). For more information see: https://en.wikipedia.org/wiki/WTFPL"
+ # ---
+ rm *tmp*
+ else
+ echo "---- File $FILE not exists."
+ fi
-rm $dir/*.tmp
-rm $dir/*.tmp.*
+done