« Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/pre-annex.sh » : différence entre les versions
Contenu supprimé Contenu ajouté
Création |
(Aucune différence)
|
Version du 12 mai 2021 à 17:21
pre-annex.sh
- Documentation
#D pre-annex program documentation #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 - to manually copy the content to the project/project.suffix file #D It is also proposed to display the local book in the navigator #D #F Documentation du programme pre-annex #F Ce programme pré-annexe la construction de l'annexe du livre #F Si ce programme s'est bien exécuté, le répertoire de projet aura été créé #F - le fichier projet.suffixe et un livre local auront été créés dans le #F - répertoire projet #F Si tout est correct il est proposé d'éditer la compilation ou la page de #F - contenu afin d'être recopiée manuellement dans le fichier projet.suffixe #F Il est également proposé d'afficher le livre local dans le navigateur
- Program code
#!/bin/bash
#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
#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
#H Created : 12/05/2021 by GC
#H Last Update on fr:Wikibooks :
#H Tested : by GC 12/05/2021
#H Updated : by user GC For layout
#H
#D pre-annex program documentation
#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 to manually copy the content to the project/project.suffix file
#D
#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
#w Attention, the character ';' at the end of the line is equal to '\' before NL
#w if the following line is a comment, it will concatenate it at the end of
#w the previous line and the command with grep -v deletes the whole line
#w
VERSION=210512
#O If first parameter is "--v", print pre-annex version
if [ "$1" = "--v" ]; then echo " pre-annex version $VERSION"; exit 0; fi
#O If first parameter is empty, print the syntax
if test -z $1
then
echo "Syntax : pre-annex [ Full-url-of-book | --v | --t ] (bin directory in environment variables)"
echo " Example in tests directory tests/pre-annex.sh/ :"
echo " ./pre-annex.sh https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_fleurir_le_sel"
exit -1
fi
#O Else, the first parameter is not empty
#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 "Workind drectory not found"; exit -1;fi
rm pwd.txt
source $Workdir/datas/installdir.var
if [ "$1" = "--t" ] || [ "$2" = "--t" ] ; then echo;echo "Global install variables :";cat $Workdir/datas/installdir.var; fi
#T Test break exit 0
#O Find function findbook
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 $1
#O If option --t, print the book parameter
if [ "$2" = "--t" ]
then
echo
echo "Global variables after findbook execution : "
echo "Site name :"$Site
echo "Bookname : "$Bookname
echo "Suffix : "$Suffix
echo "Bookname.Suffix = "$Bookname.$Suffix
echo " ----"
fi
#O If all parameter are found carry continue otherwise print the error
if ! test $Site || ! test $Bookname || ! test $Suffix
then
if ! test $Site; then echo "Site not found";fi
if ! test $Bookname; then echo "Bookname not found";fi
if ! test $Suffix; then echo "Suffix not found";fi
fi
#O Create the project directory
Projectdir=$Workdir/$Bookname
if ! test -d "$Projectdir"; then mkdir $Projectdir; fi
#O Create the file bookname.suffix
echo "; $Bookname" > $Projectdir/$Bookname.$Suffix
#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
Book=https://$Site/wiki/$Bookname
#T echo $Book
#T exit 0
wget -r -linf -k -p -E $Book -o $Workdir/temp/wget-log-télécharger.txtl
#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 : Complete the result "; echo -e "Edit and copy the wiki-code in $Workdir/$Bookname/$Bookname.$Suffix :\033[0m"
echo "Go forward ? y/n"
read -s -n1 -p "inkey" Inkey; echo;
if [ "$Inkey" = "y" ]
then
xdg-open $1
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
Localbook=$Projectdir/$Site/wiki/$Bookname.html
if test -e $Localbook;
then
echo "do you want to see the local book ? y/n"
read -s -n1 -p "inkey" Inkey; echo;
if [ "$Inkey" = "y" ]; then xdg-open file://$Localbook ; fi
else echo "$Localbook not found"
fi