« Auto-éditer un wikilivre/addappendix/reconstruction et tests du script addappendix » : différence entre les versions

Contenu supprimé Contenu ajouté
→‎Résultat des tests : WL:RD : ! mise en page
→‎script addapendix.sh : WL:RD : ! mise en page
Ligne 7 :
#H -------------------------------
#H File : tests/addappendix/addapendix.sh
#H Syntax : addapendix [ ? | --v ]
#H Created : 220113 by GC
#H Updated : 220113 by ... for
Ligne 15 :
#P -------------------------------
 
VERSION=220117220126
TEXTDOMAIN=addappendix
TEXTDOMAINDIR="/usr/share/locale"
Ligne 29 :
then
echo -n -e "\033[31m"
echo -n $"No parameter. addappendix [ <full url of book> | ? | --v ]"
echo -e "\033[0m"
exit -1
Ligne 39 :
then
echo -n -e "\033[32m"
echo $"Syntax: addappendix [ <full url of book> | --v ]"
echo $" Example 1 : addappendix https://en.wikibooks.org/wiki/Wikibooks:Collections/Guide_to_Unix"
echo $" Example 2 : addappendix https://fr.wikibooks.org/wiki/Wikilivres:Compilations/Faire_sa_fleur_de_sel"
Ligne 45 :
exit 0
fi
#O IF first parameter is "--v"
if [ "$1" = "--v" ]
#O Then print addapendix version
then
Ligne 61 :
then
echo -n -e "\033[32m"
echo -n $" is a wiki-booksbook"
echo -e "\033[0m"
else
Ligne 87 :
echo -n $"Book name : $Bookname"
echo -e "\033[0m"
echo $1 | awk -F"/" ' { print $5 }' > Compilations.txt
echo $1 | awk -F"/" ' { print $3 }' > site.txt
read Compilations<Compilations.txt
read Site<site.txt
echo; echo -n -e "\033[1;32m"
echo -n $"Site name : $Site"
echo -e "\033[0m"
echo $1 | awk -F"/" ' { print $5 }' > compilations.txt
read Compilations<compilations.txt
echo -n -e "\033[1;32m"
echo -n $"Compilations name: $Compilations"
echo -e "\033[0m"
if [ "$Compilations" = "Wikilivres:Compilations" ]; then Suffix=compiled; fi
if [ "$Compilations" = "WikibokoksWikibooks:Collections" ]; then Suffix=collectioncompiled; fi
if test -z $Suffix; then Suffix=compiled; fi
echo -n -e "\033[1;32m"
Ligne 150 ⟶ 157 :
echo; echo "Dowload $1"
wget -r -linf -k -p -E "$1" -o $Workdir/temp/wget-log-télécharger.txt
 
# Create lists
if test -e /usr/local/datas/content_cleaner.dat; then Datasdir=/usr/local/datas
else
echo -n -e "\033[12;31m"
echo -n $"content_cleaner.dat not found in /usr/local/datas"
echo -e "\33[0m"
exit -1
fi
 
if test -e "$Projectdir/$Bookname.compiled"
then
{
echo "$(gettext ' Found Compiled page : ')$Projectdir/$Bookname.compiled"; echo
echo " Create $Projectdir/$Bookname.list with :"; echo " $Projectdir/$Bookname.compiled"; echo
cat "$Projectdir/$Bookname.compiled" | sed -f $Datasdir/content_cleaner.dat > $Projectdir/$Bookname.compiled.cleaned
cat "$Projectdir/$Bookname.compiled.cleaned" | grep -v '=' | sed "s/\[\[/https:\/\/$Site\/wiki\//g" | sed "s/\]\]//g" | grep "wiki" | tr ' ' '_' | cut -d '|' -f1 > $Projectdir/$Bookname.list
cat "$Projectdir/$Bookname.compiled.cleaned" | grep -v '=' | sed "s/\[\[//g" | sed "s/\]\]//g" | cut -d '|' -f1 > $Projectdir/$Bookname.prj
}
fi
#T Print $Projectdir/$Bookname.prj
cat $Projectdir/$Bookname.prj
 
#O Download the complete book structure in project directory
cd $Projectdir
echo $"download all sub-directories of the book '$Bookname'"
wget -r -linf -k -p -E -i $Bookname.list -o $Workdir/temp/wget-log-download.txt
echo "----------"
#T Testspoint exit 0
#O Move the html pages into working sub-directories to document the pages and sub pages
#O create a local list to the downloaded directories $ Projectdir/$1.locale.list
echo "create the complete concatenated hierarchy of the directories of the book '$Bookname'"
cat $Projectdir/$Bookname.list | sed "s/https:\/\///g" | sed "s/\ /\\\ /g" | tr '\n' ',' > $Projectdir/$Bookname.locale.list
echo " Concatenated local list $Projectdir/$Bookname.locale.list :"
echo ""
cat $Projectdir/$Bookname.locale.list
echo "----------"
#O Copy the html files to respective directories
#O Create a file with the pagename $Projectdir/$Bookname.mainPage
echo "créer la page du lien local vers la page principale, 'le livre'."
echo "create the page from the local link to the main page, 'the book'"
cat $Projectdir/$Bookname.locale.list | sed "s/ /\\ /g" | cut -d ',' -f1 > $Projectdir/$Bookname.mainPage
echo "----------"
#O Initialize the variable $mainPage
read mainPage < $Projectdir/$Bookname.mainPage
echo "variable mainPage = $mainPage"
#T cat $Projet/$1.mainPage | awk -F"/" '{print NF}' > nbchamps
#T read NbChamps < nbchamps
#T echo "Variable NbChamps = $NbChamps"
echo "----------"
#O Create a file of the working directories to be created.
ls "$mainPage" | sed "s/.html//g" > $Projectdir/$Bookname.dirs
echo "sub-working-diectories : "
cat $Projectdir/$Bookname.dirs
echo "----------"
#O Copy the html pages and subpages in the respective directories
while read line
do
echo "$line".html | sed "s/https:\/\///g" | tr '\n' ' ' > source
read Source < source
echo "Source = $Source"
 
echo "$line" | awk -F"/" '{ print $NF }'| tr '\n' '/' > destination
read dir < destination
mkdir $dir
echo "$line".html | awk -F"/" '{ print $NF }' >> destination
read Destination < destination
echo "Destination = $Destination"
echo "To copy : 'cp -f ./$Source $Destination'"
cp -f "./$Source" "$Destination"
done < $Projectdir/$Bookname.list
rm source ; rm destination
#O Create variable PageSclt
PageSclt=$Projectdir/$Bookname.sclt
#O File creation '$Bookname.sclt' and print the contents.
echo "----------"
echo "$(gettext '= Appendix = ')" > $PageSclt
echo >> $PageSclt
 
#O Add <references />
echo "$(gettext '== References == ')" >> $PageSclt
echo "$(gettext '<references /> ')" >> $PageSclt
echo >> $PageSclt
echo "<div style='page-break-before:always'></div>" >> $PageSclt
#O Add the link to printable book and to articles.
echo "$(gettext '== Contents == ')" >> $PageSclt
echo "<div style="font-zize:85%">" >> $PageSclt
cat $Projectdir/$Bookname.list | tr ' ' '_' | tr '\n' '%' | sed "s/%/\n\n/g" >> $PageSclt
echo "</div>" >> $PageSclt
 
#0 Add the link to the source of this edition.
echo "$(gettext '=== Source for this edition === ')" >> $PageSclt
echo "<div style="font-zize:85%";>" >> $PageSclt
echo -n "https://" >> $PageSclt
cat $Projectdir/$Bookname.mainPage | sed "s/\\\ /_/g" >> $PageSclt
#P other version : cat $Projectdir/Bookname".list" | tr ' ' '_' | tr '\n' '%' | sed "s/%/%\n/g" | grep $1% | tr -d % >> $PageSclt
echo "</div>" >> $PageSclt
echo " " >> $PageSclt
echo "<div style='page-break-before:always'></div>" >> $PageSclt
 
#O Create section 'Article', 'Source', 'License', 'Contributors(?)'
echo "$(gettext '== Articles Sources, and contributors == ')" >> $PageSclt
#O add the text : style PediaPress or personalized.
#O The ''sources'' listed for each article provide more detailled licencing
#O information including the copyright status, the copyleft owner and the license conditions.
echo -n "<span style="font-zize:85%";>" >> $PageSclt
echo "$(gettext 'The ''sources'' listed for each article provide more detailled licencing information including the copyright status, the copyleft owner and the license conditions..</span> ')" >> $PageSclt
#O or, validate one or the other of these texts :
# echo $"The texts are available with their respective licenses, however other terms may apply.<br />See the terms of use for more details : <br />https://wikimediafoundation.org/wiki/Conditions_d'utilisation.</span>" >> $PageSclt
echo " " >> $PageSclt
echo "<div style="font-zize:72%";>" >> $PageSclt
echo "----------"
#O Create or recreate the list-file $Projectdir/$1.pj
cat $Projectdir/$Bookname.list | awk -F"/" '{ print $NF }' > $Projectdir/$Bookname.pj
Pjlist=$Projectdir/$Bookname.pj
echo "Pjlist : "$PjList
 
#O While exist line in file $PjList ,
while read line
do
#O Print the line read,
echo
echo "$(gettext ' line read = ')"$line
echo
#O Extract and copy all strings from the html file
#O $line.html in the file $line.str and add to screen
#T pwd
mkd -pws '**' "$line/$line.html" $Projectdir/$line/$line.tmp | tr ',' '\n' > $Projectdir/$line/$line.str
#T break
#O Create the documentation file of pages :
echo "*** References : articles, src, lic, contrib. "
#O Print article,
if [ $line != $Bookname ]
then
echo "'''$line'''" >> $PageSclt
fi
echo "'''"$line"'''" > $Projectdir/$line/$line.article
cat $Projectdir/$line/$line.article
#O Print source,
echo -n "$(gettext ', ''source :'' ')https://"$Site"/w/index.php?oldid=" > $Projectdir/$line/$line.RevisionId
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRevisionId | tr -d ':' | sed "s/\"/%/g" | cut -d'%' -f3 >> $Projectdir/$line/$line.RevisionId
if [ "$line" != "$Bookname" ]
then
cat $Projectdir/$line/$line.RevisionId >> $PageSclt
fi
cat $Projectdir/$line/$line.RevisionId
 
#P license du bas de page :
#P <li id="footer-info-copyright">Les textes sont disponibles sous <a href="https://creativecommons.org/licenses/by-sa/3.0/">license Creative Commons attribution partage à l’identique</a> ; d’autres termes peuvent s’appliquer.<br/>
#P Voyez les <a href="https://wikimediafoundation.org/wiki/Conditions_d'utilisation">termes d’utilisation</a> pour plus de détails.<br/></li>
#P
#P Print license :
#P <link rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/"/>
 
 
#T echo ", ''Copyright :''" >> ArticleUn.tmp
#T cat ArticleUn.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f2 |sed "s/\/\//https:\/\//g" >> ArticleUn.tmp
#O Print license :
echo -n "$(gettext ', ''license :'' ')" > $Projectdir/$line/$line.license
#T cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f4 >> $Projectdir/$line/$line.license
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | tr '"' '%' | cut -d'%' -f4 >> $Projectdir/$line/$line.license
#T cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e license | sed "s/\"\//%\//g" | cut -d'%' -f2 | sed "s/\/\//https:\/\//g" >> $Projectdir/$line/$line.license
if [ $line != $Bookname ]
then
cat $Projectdir/$line/$line.license >> $PageSclt
fi
cat $Projectdir/$line/$line.license
#
#P spécial pour bas de page fr ##
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e footer-info-copyright | sed "s/\"\//%\//g" | tr '"' '%' | cut -d'%' -f4 > $Projectdir/$line/$line.license
 
#O Author(s).
echo -n "$(gettext ', ''author(s) : '' ')" > $Projectdir/$line/$line.author
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRelevantUserName | sed "s/\"/%/g" | cut -d'%' -f4 > tmp
if test -s tmp
then cat tmp >> $Projectdir/$line/$line.author; rm tmp
else
echo "Author(s) not found ! " >> $Projectdir/$line/$line.author
if wget --spider https://xtools.wmflabs.org/articleinfo/en.wikibooks.org/$line 2>/dev/null
then
echo "$(gettext '. -see :') https://xtools.wmflabs.org/articleinfo/$Sitename/$line" >> $Projectdir/$line/$line.author
elif wget --spider https://xtools.wmflabs.org/articleinfo/$Sitename/$Bookname/$line 2>/dev/null
then
echo "$(gettext '. -see :') https://xtools.wmflabs.org/articleinfo/$Sitename/$Bookname/$line" >> $Projectdir/$line/$line.author
else
cat $Projectdir/$line/$line.str | grep -n -m 1 -i -e wgRelevantPageName | sed "s/\"/%/g" | cut -d'%' -f4 > tmp
if test -s tmp
then
#T echo "&action=history" >> tmp
echo -n "$(gettext '. -see ''contributors'' in book, history page of ')" >> $Projectdir/$line/$line.author
cat tmp >> $Projectdir/$line/$line.author; rm tmp
fi
fi
fi
#https://xtools.wmflabs.org/articleinfo/en.wikibooks.org/Guide_to_Unix/Introduction
if [ $line != $Bookname ]
then
cat $Projectdir/$line/$line.author >> $PageSclt
cat $Projectdir/$line/$line.author
fi
echo >> $PageSclt
#O end of while.
done < $Pjlist