« Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/pre-annex.sh » : différence entre les versions

Contenu supprimé Contenu ajouté
m →‎sitelist.sh : Modification du sous-titre
m →‎pre-annex.sh : Mise à jour du code
Ligne 25 :
<syntaxhighlight lang="Bash">
#!/bin/bash
#H pre-annex header documentation
#H ------------------------------
#H Workdir is ~/Add_appendix or ~/Annexer
#H Source file : Workdir/src/pre-annex.sh
#H Executable file : Workdir/bin/pre-annex
#H Syntax : pre-annex [ Full-url-of-book || --v ]
#H Example : ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
#H Example :
#HP ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
#P https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel
#H Created : 12/05/2021 by GC
#H Last Update on fr:Wikibooks :
Ligne 36 ⟶ 39 :
#H Updated : by user GC For layout
#H
#P These two collection files have the same content with different titles:
#P https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel
#P https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel
#P In collections files:
#P The site prefix is detected by the characters "[[" <a href ...
#P The character ':' for tabulation is tetected by the tag <dd><a href ... :[[ Is used in collection and contents or summary files
#P The character '#' for ordered list is detected by the tag <ol><li><a href ...</li><li><a href ...</li></ol> Is used in contents and summary files
#P The character '*' for not ordered list is detected by the tag <ul><li><a href ...</li><li><a href ...</li></ul> Is used in contents and summary files
#P ';' = <dl><dt> .. text .. </dt> ... </dl>
#P
#D pre-annex program documentation
#D -------------------------------
#D This program use findbook to analyse the link to the book
#D If the result is correct, create the project directory, pre-create the
#D file project.suffix and create a local html book in project directory.
#D If everything is correct, edit a collection file or a book contents file
#D if the suffix is 'content' or 'summary', else for 'collection' link create
#D to manually copy the content to the project/project.suffix file
#D a local collection file
#D If everything is correct, edit the local book contents file or the local
#D collection file to check and possibly update the file manually. Then copy
#D the content to the project.suffix file if necessary
#D
#w pre-annex wanings documentation
#w Install Add_appendix or Annexer with the program executable users_install_annex.sh
#W https://fr.wikibooks.org/wiki/Auto-éditer_un_wikilivre/Annexer_(Version_internationalisée)/users_install_annex.sh
Ligne 62 ⟶ 54 :
#w the previous line and the command with grep -v deletes the whole line
#w
#O pre-annex organizational chart documentation
#D This Documentation is included in source file
#O --------------------------------------------
#H Header of file included in source file
#O pre-annex programmers documentation
#O Organigram of program included in source file
#O ------------------------------------
#P Comments for programmers included in source file
#S Structure comments of program included in source file
#w Warnings comments in program included in source file
 
unset $VERSION=211005
VERSION=210812
 
#O If first parameter is "--v", print pre-annex version
Ligne 85 ⟶ 74 :
#P Include install variables
pwd > pwd.txt
if cat pwd.txt | grep ~/Annexer; then Workdir=~/Annexer; elif cat pwd.txt | grep ~/Add_appendix; \
then Workdir=~/Add_appendix; else echo "WorkingWorkind directory not found"; exit -1;fi
rm pwd.txt
source $Workdir/vars/installdir.var
if [ "$1" = "--t" ] || [ "$2" = "--t" ] ; then echo; echo "Global install variables :"; cat $Workdir/vars/installdir.var; fi
Datasdir=$Installdir/datas
#O Convert URL of first parameter
echo $1 | sed -f $Datasdir/conversions.dat > fullurl.txt
read Fullurl < fullurl.txt
#T echo "Installdir = $Installdir"; echo "Workdir = $Workdir"; echo "Datasdir = $Datasdir"; exit 0
if [ "$Fullurl" = "--t" ] || [ "$2" = "--t" ] ; then echo; echo "Global install variables :"; cat $Workdir/vars/installdir.var; fi
#T Test break exit 0
#O Find function findbook
Ligne 100 ⟶ 84 :
Booksdir=$Workdir/books
if test -e $Libdir/annex.lib; then source $Libdir/annex.lib; elif test -e $Libdir/src/findbook.sh; \
then source $Libdir/src/findbook.sh; else echo "Function findbook not found"; exit -1; fi
#O Find book parameter
findbook $Fullurl1
#O If option --t, print the book parameter
if [ "$2" = "--t" ]
Ligne 139 ⟶ 123 :
Projectdir=$Booksdir/$Bookname
if ! test -d "$Projectdir"; then mkdir $Projectdir; fi
 
#O Download the book in html form
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E )
if ! test -d "$Workdir/temp"; then mkdir $Workdir/temp; fi
#O Go in the book directory
cd $Projectdir
#O If $Bookfullurl exist (Contents, Sommaire, etc.) #####################
if test -n "$Bookfullurl"
then
#O Download the book and the contents page ($Fullurl)
echo "Dowload $Bookfullurl"
wget -r -linf -k -p -E "$Bookfullurl" -o $Workdir/temp/wget-log-bookfullurlpre-annex.txt
wget -r -linf -k -p -E "$Fullurl" -o $Workdir/temp/wget-log-contents-preannex.txt
#P Processing of uploaded files
echo -n "$Projectdir/" > localbook.txt
echo "$Bookfullurl" | cut -d '/' -f3- >> localbook.txt
read Localbookdir < localbook.txt
echo "ls -al Localbookdir :"
ls -al $Localbookdir
mkdir $Projectdir/$Lastfield
cp $Localbookdir/*.html $Projectdir/$Lastfield/.
echo "ls -al contents in $Projectdir/$Lastfield :"
ls -al $Projectdir/$Lastfield
cat $Projectdir/$Lastfield/$Lastfield.html | sed -f $Datasdir/conversions.dat > $Projectdir/$Lastfield/$Lastfield.html.converted
cat $Projectdir/$Lastfield/$Lastfield.html.converted | grep -E "<a|'$Bookname'" | grep "<a href=\"https://$Site/wiki/" | grep title | \
sed "s/\"/\n/g" | grep $Site | grep -v -f $Datasdir/unrecognized_links.dat | sed "s/https:\/\/$Site\/wiki\//[[/g" > prebooknamesuffix.txt
tr '\n' ' ' < prebooknamesuffix.txt > prebooknamesuffix2.txt
cat prebooknamesuffix2.txt | sed "s/ /]]\n/g" > bookname.suffix.txt
#T Test break exit 0
 
#O Else-if the book is a Collection #####################
elif test -n "$Compilfullurl"
then
#O Download the book and the compilation page
echo "Dowload $Compilfullurl"
wget -r -linf -k -p -E "$Compilfullurl" -o $Workdir/temp/wget-log-compilfullurl-pre-annex.txt
wget -r -linf -k -p -E "$Fullurl" -o $Workdir/temp/wget-log-collection-preannex.txt
#P Processing of uploaded files
echo -n "$Projectdir/" > localcollectionfile.txt
echo "$Compilfullurl" | awk -F"/" '{ for (i=3 ; i<NF ; i++) print $i }' | tr '\n' '/' >> localcollectiondir.txt
echo "$Compilfullurl" | cut -d '/' -f3- >> localcollectionfile.txt
#exit 0 ###################
read Localcollectionfile < localcollectionfile.txt
ls -al $Localcollectionfile.html
echo "Penultimatefield = $Penultimatefield"
mkdir $Projectdir/$Penultimatefield
cp $Localcollectionfile.html $Projectdir/$Penultimatefield
echo "ls -l content in $Projectdir/$Penultimatefield :"
ls -l $Projectdir/$Penultimatefield
cat $Projectdir/$Penultimatefield/$Bookname.html | sed -f $Datasdir/conversions.dat > $Projectdir/$Penultimatefield/$Bookname.html.converted
#Techo "Compilfullurl = $Compilfullurl"
cat $Projectdir/$Penultimatefield/$Bookname.html.converted | grep "<dd><a href=\"https://$Site/wiki/" | grep title | sed "s/\"/\n/g" \
| grep -v "<dd><a href=" |grep -v "title="| grep -v '>' | grep $Site | sed "s/https:\/\/$Site\/wiki\//[[/g" > prebooknamesuffix.txt
tr '\n' ' ' < prebooknamesuffix.txt > prebooknamesuffix2.txt
cat prebooknamesuffix2.txt | sed "s/ /]]\n/g" > bookname.suffix.txt
#T Test break exit 0
else echo " book full url not found to download"
fi
#O Create the file bookname.suffix
if test -e $Projectdir/$Bookname.$Suffix
then
echo "Actual $Bookname.$Suffix : "
echo "----------"
cat $Projectdir/$Bookname.$Suffix
echo -e "\033[47m\033[1;30m Want you update $Projectdir/$Bookname.$Suffix ? \033[0m"
echo "----------"
echo "Bookname.suffix found:"
echo "----------"
cat bookname.suffix.txt
echo "----------"
#T Test break exit 0
echo -e "\033[47m\033[1;30m Want you update actual $Projectdir/$Bookname.$Suffix ? \033[0m"
read -s -n1 -p "inkey y/n : " Inkey; echo $Inkey
if [ "$Inkey" = "y" ]
then
echo; chmod 755 $Projectdir/$Bookname.$Suffix
#O Modify bookname.suffix r-w mod
echo;if chmod 666[ $Projectdir/$Bookname."$Suffix" = "compiled" ]
then
cat "bookname.suffix.txt" > $Projectdir/$Bookname.$Suffix
if test -n $MWcompilurl; then echo "[[$MWcompilurl]]" > $Projectdir/$Bookname.suffix$Suffix; updatedfi : "
else
cat $Projectdir/$Bookname.$Suffix
chmod 444 if test -n $MWbookurl; then echo "[[$MWbookurl]]" > $Projectdir/$Bookname.$Suffix; fi
fi
fi
else
echoif [ "Bookname.suffix$Suffix" = proposed:"compiled" ]
echothen "----------"
if test -n $MWcompilurl; then echo "[[$MWcompilurl]]" > $Projectdir/$Bookname.$Suffix; fi
cat bookname.suffix.txt
echo "----------"else
echo if test -en "\033[47m\033[1$MWbookurl;30m then Wantecho you"[[$MWbookurl]]" create this> $Projectdir/$Bookname.$Suffix; ?fi \033[0m"
fi
read -s -n1 -p "inkey y/n : " Inkey; echo $Inkey
if [ "$Inkey" = "y" ]
then
#O Create bookname.suffix r-w mod
cat "bookname.suffix.txt" > $Projectdir/$Bookname.$Suffix
echo "Bookname.suffix created : "
cat $Projectdir/$Bookname.$Suffix
chmod 444 $Projectdir/$Bookname.$Suffix
fi
fi
#O Download the book in html form
 
#O Télécharger le site récursivement avec une profondeur infinie ( -linf ), \
#O convertit les liens pour une consultation en local ( -k ), \
#O rapatrie tous les fichiers nécessaires à l'affichage convenable d'une page HTML ( -p ) \
#O et renomme toutes les pages HTML avec l'extension .html ( -E )
if ! test -d "$Workdir/temp"; then mkdir $Workdir/temp; fi
cd $Projectdir
if test -n "$Bookfullurl"; then echo "Dowload $Bookfullurl"; wget -r -linf -k -p -E "$Bookfullurl" -o $Workdir/temp/wget-log-télécharger.txt
elif test -n "$Compilfullurl"; then echo "Dowload $Compilfullurl"; wget -r -linf -k -p -E "$Compilfullurl" -o $Workdir/temp/wget-log-télécharger.txt
else echo " book full url not found to download"
fi
#O If everything is correct, edit a collection file or a book contents file
#O to manually copy the content to the project/project.suffix file
if test $Site || test $Bookname || test $Suffix
then
echo -e "\033[31mAttention : See and possibly complete the $Bookname.$Suffix "; echo -e "Edit and copy the wiki-code in $ProjectdirWorkdir/$Bookname/$Bookname.$Suffix :\033[0m"
echo -e "\033[47m\033[1;30m Go forward to edit the book and copy wiki-code to $Bookname.$Suffix ? \033[0m"
read -s -n1 -p "inkey y/n : " Inkey; echo "$Inkey"
if [ "$Inkey" = 'y' ]
then
gedit $ProjectdirWorkdir/$Book/$Bookname/$Bookname.$Suffix&
xdg-open $Fullurl1
fi
else
echo -e "\033[31m Non-compliant result \033[0m"
fi
#T xdg-open file:///home/jpl/Annexer/Faire_fleurir_le_sel/fr.wikibooks.org/wiki/Faire_fleurir_le_sel.html
 
#T xdg-open https://fr.wikibooks.org/w/index.php?title=Auto-%C3%A9diter_un_wikilivre/Auto-r%C3%A9f%C3%A9rencer/LivreTest/LivreTest.compil%C3%A9&action=edit
#O If exist localbook.txt
echo -n "$Projectdir/" > localbook.txt
unset $Htmlbook
ifecho test"$Bookfullurl" | cut -ed '/' -f3- >> localbook.txt
#T cat localbook.txt
then
read Localbook cat< localbook.txt
read Htmlbook=$Localbook < localbook.txthtml
echo "Htmlbook = $Localbook.htmlHtmlbook"
echo "Htmlbook = $Htmlbook"
fi
#T Test break exit 0
if test -ne "$Htmlbook"
then
echo -e "\033[47m\033[1;30m Do you want to see the local html book ? \033[0m"
read -s -n1 -p "inkey y/n : " Inkey; echo "$Inkey"; echo
if [ "$Inkey" = 'y' ]; then xdg-open file://$Htmlbook ; fi
else echo "$Htmlbook not found"
echo "$Htmlbook not found"
fi
Varsdir=$Workdir/vars
Ligne 284 ⟶ 199 :
if test -n "$Compilfullurl"; then echo "Compilfullurl=$Compilfullurl" >> $Varsdir/$Bookname.var; fi
if test -n "$Htmlbook"; then echo "Htmlbook=$Htmlbook" >> $Varsdir/$Bookname.var; fi
exit 0
echo "$Varsdir/$Bookname.var : "; echo "----"; cat $Varsdir/$Bookname.var
#O clean projectdir
rm *.txt
#O End pre-annex.sh
</syntaxhighlight>