diff options
Diffstat (limited to 'platform/bin/doku2md.sh')
-rwxr-xr-x | platform/bin/doku2md.sh | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/platform/bin/doku2md.sh b/platform/bin/doku2md.sh new file mode 100755 index 0000000..a3f0a13 --- /dev/null +++ b/platform/bin/doku2md.sh @@ -0,0 +1,116 @@ +#!/bin/bash + +### Script para dejar listo los .txt de Doku para hacerlos markdown +url='https://illich.test/' +IFS=$'\n' + +# Arregla footnotes + + dir=`dirname $1` + name=`echo $1 | sed 's/\.txt//g'` + + lang=${name: -2} + + ## Corta el archivo en dos, empezando por la linea de la primera footnote + + n=`grep -n -m 1 ':]' $1 |sed 's/\([0-9]*\).*/\1/'` + + csplit -s $1 $n -f $1.tmp. + + ## Agrega saltos de linea y elimina corchete final + + grep ':]' $1.tmp.01 | perl -p -e 's/\n/\n\n/' > $1.footer.tmp + + sed -i 's/]$//g' $1.footer.tmp + + ## Unifica todo y corrige corchete de apertura + + cat $1.tmp.00 > $1.tmp + + cat $1.footer.tmp >> $1.tmp + + sed 's/:]/]:/g' $1.tmp > $name.body.tmp + + ## Borra temporales + + + + +# agregar cabecera para pandoc! + +if test -f "$dir/index.txt"; then + echo "hay index" + yaml_title=`head -n1 "$dir/index.txt" | sed 's/# //g'` + yaml_date=`grep 'LANG_publicationdate' "$dir/index.txt" | cut -d ':' -f2 | sed 's/ //'` + yaml_author=`grep 'LANG_author' "$dir/index.txt" | 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\" +abstract: \"$url$webpage?rev=$revision\" +date: \"$yaml_date\" +lang: \"$lang\" +titlepage: true +titlepage-color: \"FFFFFF\" +titlepage-text-color: \"000000\" +titlepage-rule-color: \"CCCCCC\" +titlepage-rule-height: 4 +--- + " > $name.head.tmp +fi + + +## Hay que cambiar los titulos + +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 + +cat $name.head.tmp > $name.md +cat $name.body.tmp >> $name.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 $dir/*.tmp + +rm $dir/*.tmp.* |