summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2023-05-25 19:00:06 -0300
committerYaco <franco@reevo.org>2023-05-25 19:00:06 -0300
commit33265b890aa004257c6d3bb56450ba5659b655bf (patch)
tree0c328c84cd2804f3dcb5d32847ffc866da22ce6a
parentb9816bc1c44b57d3e737f241253f74491385a768 (diff)
add script for contents compilation
-rwxr-xr-xplatform/bin/contents_compile.sh201
1 files changed, 201 insertions, 0 deletions
diff --git a/platform/bin/contents_compile.sh b/platform/bin/contents_compile.sh
new file mode 100755
index 0000000..fc64907
--- /dev/null
+++ b/platform/bin/contents_compile.sh
@@ -0,0 +1,201 @@
+ #!/usr/bin/env bash
+# Contents compilee
+# ./contents_compile.sh <collection> <type>
+# ./contents_compile.sh illich $TYPE
+
+COLLECTION=$1
+TYPE=$2
+
+cd ../../content/$COLLECTION/contents/$TYPE
+
+AUTHOR=`cat ../../conf/local.php | grep author | cut -d "'" -f4`
+SITE=`cat ../../conf/local.php | grep title | cut -d "'" -f4`
+CODENAME=`cat ../../conf/local.php | grep codename | cut -d "'" -f4`
+BASEURL=`cat ../../../../platform/www/conf/farm.ini | grep basedomain | cut -d '"' -f 2`
+
+
+echo "#### STARTING TO COMPILE! Collection: $1 Type: $2. Press a key to proceed..."
+read
+
+rm index*
+echo "" > index.txt
+
+LANGS=("en" "es")
+for lng in ${LANGS[@]}; do
+ echo "" > index.$lng.txt
+ rm -rf ../../data/pages/$lng/$TYPE/*
+ cd ../../data/pages/$lng/$TYPE/
+ ln -s ../../../../contents/$TYPE/index.$lng.txt index.txt
+ cd -
+done
+
+
+
+echo "" > index.es.txt
+
+
+
+for i in `ls -d */`; do
+ echo "*** $i"
+ FOLDER=$i
+ YEAR=`echo $i | cut -d '-' -f1`
+ cd $i
+ LANGORIG=`cat index | grep langorig | cut -d "@" -f 4 | cut -d "_" -f 3`
+ echo $LANGORIG
+ TITLEORIG=`cat index | grep titleorig | cut -d "_" -f3`
+ echo $TITLEORIG
+
+ if [[ -f $LANGORIG.txt ]]
+ then
+ echo "la version en el idioma original esta procesada"
+ for j in `ls *.txt`; do
+ LANG=`echo $j | cut -d '.' -f1`
+ echo "**** $LANG"
+
+ # Creates the $TYPE directory
+ if [[ ! -d ../../../data/pages/$LANG/$TYPE/$i ]]
+ then
+ echo "Create the $TYPE directory for $i in $LANG"
+ mkdir ../../../data/pages/$LANG/$TYPE/$i
+ fi
+
+ # Creates the index file
+ echo "Regenerate the index functionle for $i in $LANG"
+ INDEX="../../../data/pages/$LANG/$TYPE/$i/index.txt"
+ TITLE_MD=`head -n1 $LANG.txt`
+ TITLE=`echo $TITLE_MD | sed s/\#\ //`
+ head -n1 $LANG.txt > $INDEX
+ echo "" >> $INDEX
+ TITLELANG=`head -n1 $LANG.txt | sed s/\#\ //`
+ cat index >> $INDEX
+ cat $LANG.notes >> $INDEX
+ sed -i "s/\*YEAR\*/$YEAR/g" $INDEX
+
+ if grep "LANG_authors" $INDEX
+ then
+ sed -i "s/LANG_authors@#:\*\*/LANG_authors\@\#:\*\* $AUTHOR;/g" $INDEX
+ AUTHORS=`grep "LANG_authors" $INDEX | cut -d '*' -f6 | sed s/\;/\ and/g | sed s/^\ //`
+ else
+ # only man author
+ AUTHORS=$AUTHOR
+ fi
+ if grep "LANG_translators" $INDEX
+ then
+ TRANSLATORS=`grep "LANG_translators" $INDEX | cut -d '*' -f6 | sed s/\;/\ and/g | sed s/^\ //`
+ else
+ # only man author
+ TRANSLATORS=""
+ fi
+ KEY=`echo $FOLDER | sed 's/\///'`
+ # http://illich.acerv.uz/en:$TYPE:1900-testing:index
+ URL="https://$CODENAME.$BASEURL/$LANG/$TYPE/$KEY:index"
+ echo "" >> $INDEX
+ echo "@ARTICLE{$SITE-$KEY-$LANG,
+ author = {$AUTHORS},
+ title = {$TITLE},
+ year = {$YEAR},
+ language = {$LANG},
+ translator = {$TRANSLATORS},
+ url = {$URL}
+}" > $LANG.bib
+ cat $LANG.bib >> ../index.$LANG.bib
+ echo "" >> ../index.$LANG.bib
+ echo "\`\`\`" >> $INDEX
+ cat $LANG.bib >> $INDEX
+ echo "\`\`\`" >> $INDEX
+ echo "~~NOTOC~~" >> $INDEX
+
+
+ LINES=`wc -l $LANG.txt`
+ if [[ $LINES > 2 ]]; then
+ # If the files contains more than one line, we consider the original $TYPE is complete and not pending
+ echo "{{tag>available}}" >> $INDEX
+ else
+ echo "{{tag>pending}}" >> $INDEX
+ fi
+
+ # Creates the link to the text in the specific language
+ cd ../../../data/pages/$LANG/$TYPE/$i
+ if [[ ! -f text.txt ]]
+ then
+ ln -s ../../../../../contents/$TYPE/$i$LANG.txt text.txt
+ fi
+
+ if [[ ! -f notes.txt ]]
+ then
+ ln -s ../../../../../contents/$TYPE/$i$LANG.notes notes.txt
+ fi
+ cd -
+
+ if [[ $TITLELANG == $TITLEORIG ]]
+ then
+ echo "* [[$LANG:$TYPE:$FOLDER:index|$YEAR - $TITLELANG]]" >> ../index.$LANG.txt
+
+ else
+ echo "* [[$LANG:$TYPE:$FOLDER:index|$YEAR - $TITLELANG]] (*$TITLEORIG*)" >> ../index.$LANG.txt
+ fi
+
+
+ done
+ #echo "* $YEAR - $TITLEORIG" >> ../index.txt
+ echo "* [[$LANGORIG:$TYPE:$FOLDER:index|$YEAR - $TITLEORIG]]" >> ../index.txt
+
+ # Creates the $TYPE directory
+ else
+ echo "La version en el idioma original NO esta procesada, entonces marcamos como pendiente y creamos un index"
+
+ if [[ ! -d ../../../data/pages/$LANGORIG/$TYPE/$i ]]
+ then
+ echo "Create the $TYPE directory for $i in $LANGORIG"
+ mkdir ../../../data/pages/$LANGORIG/$TYPE/$i
+ fi
+
+
+ # Creates the index file
+ echo "Creates the index file for $i in $LANGORIG"
+ INDEX="../../../data/pages/$LANGORIG/$TYPE/$i/index.txt"
+ echo $INDEX
+
+ # TITLEORIG=`cat index | grep titleorig | cut -d "_" -f3`
+ echo "# $TITLEORIG" > $INDEX
+ echo "" >> $INDEX
+ cat index >> $INDEX
+ cat $LANGORIG.notes >> $INDEX
+ echo "" >> $INDEX
+ echo "~~NOTOC~~" >> $INDEX
+ sed -i "s/\*YEAR\*/$YEAR/g" $INDEX
+ sed -i "s/LANG_authors@#:\*\*/LANG_authors\@\#:\*\* $AUTHOR;/g" $INDEX
+
+ echo "{{tag>missing}}" >> $INDEX
+ echo "* **[[$LANGORIG:$TYPE:$FOLDER:index|$YEAR - $TITLEORIG]]**" >> ../index.txt
+
+ fi
+
+ cd ..
+ echo ""
+done
+
+echo "Running decades... "
+
+IFS=$'\n'
+
+for file in `ls index*.txt`; do
+ mv $file $file.old
+ echo "***** $file"
+ for name in `cat $file.old`; do
+ YEAR=`echo $name | cut -d ':' -f 3 | cut -d '-' -f 1`
+ DECADE=${YEAR:0:3}
+ #echo "YEAR: $YEAR"
+ #echo "DECADE: $DECADE"
+
+ if [[ $DECADE_PRE != $DECADE ]]; then
+ echo "" >> $file
+ echo '### '$DECADE'0' >> $file
+ echo "" >> $file
+ fi
+ echo $name >> $file
+ DECADE_PRE=$DECADE
+ echo "" >> $file
+
+ done
+done