Auto-éditer un wikilivre/Annexer (Version internationalisée)/src/findbook.sh

Un livre de Wikilivres.
Sauter à la navigation Sauter à la recherche
Code d'extraction pour la librairie annex.lib
mkd -Cst L findbook.sh findbook.function

ou

mkd -Cst L findbook.sh > lib/annex.lib/findbook.sh
# /*L
#H File    : findbook.sh for tests and function findbook ()
#H Version : 200626
#H Syntax  : findbook <url-book-name> 
#H Example : ./findbook LivreTest (on the terminal for unit tests)
#H Creation: 2020-06-16 by fr wikibookuser Goelette Cardabela
#H Updated : 2020-06-26 by GC for tests
#H Update on fr:Wikibooks : 2020-06-26
#H Extract the function findbook with mkd -Ct L findbook.sh findbook.function
#H   and place the findbook function il lib directory
#H

#P Returnvalue=  # External global variables sup of 255, for the the return to app.
#T Bookname=
#T Suffix=
#T Site=

                 
function findbook ()
{
#T   echo $1
   echo $1 | awk -F "/" '{for (i=1;i<=NF;i++) print $i}' > bookname.txt
   cat bookname.txt | grep wikibooks > sitename.txt
   read Site < sitename.txt
   wc -l bookname.txt | cut -d" " -f1 > N.txt; read N < N.txt; #T echo " N Fields = "$N   
   let n=N;
   
   #let n-=1; 
   echo $1 | cut -d '/' -f$n > lastfield.txt
   read Lastfield < lastfield.txt; #T echo "Lastfield = "$Lastfield
   if [ "$Lastfield" = "Contenu" ] || [ "$Lastfield" = "Contenus" ]; 
     then Suffix=$Lastfield; 
     else Bookname=$Lastfield; 
   fi;

   let n-=1; echo $1 | cut -d '/' -f$n > penultimatefield.txt
   read Penultimatefield < penultimatefield.txt; #T echo "Penultimate field = "$Penultimatefield
   if [ "$Penultimatefield" = "Compilations" ]; 
     then Suffix=$Penultimatefield; 
     else Bookname=$Penultimatefield; 
   fi;
   
#T   echo "Edit the html input file and copy content in "$Bookname.$Suffix
#T   firefox $1&action=edit
   
   rm *.txt

  return=0; 
} 
# */ C comment to extract the function for annex.lib

#T URL simulation Bookurl
Bookurl=https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Sandbox/LivreTest/Contenus
findbook $Bookurl
#T findbook https://fr.wikibooks.org/wiki/Utilisateur:Goelette_Cardabela/Compilations/LivreTest
#T findbook LivreTest/Contenu
echo "Site name :"$Site
echo "Bookname : "$Bookname
echo "Suffix : "$Suffix
echo "Bookname.Suffix = "$Bookname.$Suffix
echo "Edit the html input file and copy content in "$Bookname.$Suffix
firefox $Bookurl

# End test function findbook()