summaryrefslogtreecommitdiff
path: root/platform/bin/doku2md.sh
blob: 635effb53ec8682b65133a594e1376f5f000ba56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# 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.


### 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}

  echo "DIR: $dir"
  echo "NAME: $name"
  echo "LANG: $lang"

  read

  ## 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

  cat $name.body.tmp

  read

  ## Borra temporales




# agregar cabecera para pandoc!

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


  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

read

## 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.*