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

→‎script addapendix.sh : Ajout de code
(→‎script addapendix.sh : Mise à jour)
(→‎script addapendix.sh : Ajout de code)
#P -------------------------------
#O ============================================================================
#O Create variable Pagesclipco
echo $Pagesclipco
#O Wikibooks sclipco personalized page initialization with the title 'Images sources, etc.
cat $Projectdir/$Bookname.scli > $Pagesclipco
cat $Pagesclipco
#O ============================================================================
#O Create an identification loop of the directories corresponding to the articles
#O As long as we can read the lines of the file $Projectdir/$Bookname.pj
while read pjline
#O If the line read is not $Bookname (name of the book)
#T echo "line read : " $line
if [ $pjline != $Bookname ]
#O Then:
#O Enter in the article directory,
cd $Projectdir/$pjline
#O Create image documentation files
#O Open the stream of $ Projectdir/$Bookname/$Bookname.str of the image and select
#O the character strings containing: File:, Image; and put in files
#O $Projectdir/$line/$line/.files, .pict, .illustration, .images, .links
cat $Projectdir/$pjline/$pjline.str | grep -n -i -e Fichier: -e file: -e image: | sed -f $RepCom/$Conversions > $Projectdir/$pjline/$pjline.files
cat $Projectdir/$pjline/$pjline.str | grep -n -i -e fichier: -e .jpg -e .png -e .gif | sed -f $RepCom/$Conversions> $Projectdir/$pjline/$pjline.picts
cat $Projectdir/$pjline/$pjline.files | grep title |sed "s/<\/div>//g" | awk -F">" '{print $NF}' > $Projectdir/$pjline/$pjline.illustrations
#T cat $Projectdir/$pjline/$pjline.files | awk -F"=" '{for (i=1;i<=NF;i++) print $i "\n"}' | grep https | sed "s/\"/!/g" | cut -d '!' -f3 | grep https | tr '>' ! | sed "s/<\/a//g" |sed "s/!//g" > $Projectdir/$pjline/$pjline.links
cat $Projectdir/$pjline/$pjline.files | awk -F"=" '{for (i=1;i<=NF;i++) print $i "\n"}' | grep https://$Site | sed "s/\"/!/g" | cut -d '!' -f2 > $Projectdir/$pjline/$pjline.images
#O Transform the links of the image file on wikibooks into an image file on commons
cat $Projectdir/$pjline/$pjline.images | sed "s/$Site/commons.wikimedia.org/g"| sed "s/Fichier/File/g" > $Projectdir/$pjline/$pjline.commonsimages
#O Download the image files from the wikimedia server.
#P Note: the -N option allows you to avoid downloading an up-to-date file,
#P and without adding a numbering.
#T #T wget -N -P $Projectdir/$pjline -i $Projectdir/$pjline/$pjline.images
wget -P $Projectdir/$pjline -r -linf -k -p -E -i $Projectdir/$pjline/$pjline.commonsimages
#T echo "*** Commonsimages ***"; cat $Projectdir/$pjline/$pjline.commonsimages; exit 0
#O Copy the downloaded images to the directory of the current article..
cp $Projectdir/$pjline/commons.wikimedia.org/wiki/*.html $Projectdir/$pjline/.
#O Initialize the commonshtml.list file with empty text.
echo -n "" > commonshtml.doublons
#O List the image files in the order of printing or display,
#O using the list $Projectdir/$pjline/$pjline.commons.images
#O As long as we can read lines in $Projectdir/$pjline/$pictline.images
while read pictline
#O Cut the lignes at carriage return, sélect the last field and add '.html'
#echo $pictline | awk -F"/" '{for (i=1;i<=NF;i+=2) print $i "\n"}' #| cut -d '%' -f1 | cut -d '.' -f1 > tmp
echo $pictline | awk -F"/" '{ print $NF".html"}' >> commonshtml.doublons
#O Cut the duplicated lines and select even fields.
echo -n "" > commonshtml.list
{memfile [NR] = $0 }
END { for ( i = 1 ; i <= NR ; i=i+2 ) {
print memfile[i] >> "commonshtml.list"
# print "Fin"
} ' commonshtml.doublons
#O End of while $Projectdir/$pjline/$pjline.commonsimages
done < $Projectdir/$pjline/$pjline.commonsimages
#T Afficher html.list
#T echo "*** commonshtml.list ***"; cat commonshtml.listexit 0
#O Copy article name in file $Bookname.sclipco
echo "'''Article : $pjline'''<br \>" >> $Pagesclipco
echo "'''Article : $pjline'''"
#P## Annexe version 'wikimedia commons' ##############################
#O As long as there are (local) links in the commonshtml.list image file
while read htmlline
#O Afficher la ligne lue,
echo ""
echo ""
echo "$(gettext ' ---- line read = $htmlline --- ')"
echo ""
#O With mkd (sofware), select the character strings from the image file $htmlline
#O and copy them to $ htmlline.co.str after replacing the character ',' with
#O 'new-line'
mkd -pw '**' $htmlline $htmlline.tmp
cat $htmlline.tmp | tr ',' '\n' > $htmlline.co.str
#T echo "*** $htmlline.co.str : ***"; cat $htmlline.co.str; exit 0
#O images,
echo -n "'''$(gettext ' Illustration : ')'''" > $htmlline.co.title
cat $htmlline.co.str | grep wgTitle | cut -d '"' -f4 >> $htmlline.co.title
cat $htmlline.co.title >> $Pagesclipco
cat $htmlline.co.title
#T echo "*** $htmlline.co.title : ***"; cat $htmlline.co.title; exit 0
#O source,
echo -n $", ''source : ''https://commons.wikimedia.org/wiki/" > $htmlline.co.source
##echo -n ",''$(gettext 'source : ')''https://commons.wikimedia.org/wiki/" > $htmlline.co.source
echo -n $htmlline | sed "s/.html//g" | sed "s/.str//g" >> $htmlline.co.source
if [ "$Site" = "fr.wikibooks.org" ]; then echo "?uselang=fr" >> $htmlline.co.source
elif [ "$Site" = "en.wikibooks.org" ]; then echo "?uselang=en" >> $htmlline.co.source
else echo
cat $htmlline.co.source >> $Pagesclipco
cat $htmlline.co.source
#T echo "*** $htmlline.co.source : ***"; cat $htmlline.co.source; exit 0
#O license,
echo -n ", ''$(gettext 'license : ')'' " > $htmlline.co.license
cat $htmlline.co.str | grep licensetpl_short | sed "s/<td>//g" | sed "s/<span class//g" | sed "s/<\/span>//g" | sed "s/style=\"display:none;\"//g" | tr '=' '\n' | grep licensetpl_short | awk -F">" '{print $NF}' >> $htmlline.co.license
cat $htmlline.co.license >> $Pagesclipco
cat $htmlline.co.license
#T echo "*** $htmlline.co.license : ***"; cat $htmlline.co.license; exit 0
#O authors.
rm -rf tmp
#Pwww echo -n ", ''$(gettext ' authors : ')'' " > $htmlline.co.authors
#echo -n $", ''authors :''" > $htmlline.co.authors
echo -n ", ''authors :''" > $htmlline.co.authors
#Test cat tmp; echo "$htmlline.co.authors"; exit -1
cat $htmlline.co.str | grep -i -n -m1 -A 1 -e Author -e Auteur | tr '/' '\n' | grep -i -e user -e utilisteur -e auteur -e author | cut -d '"' -f1 | grep -i -e user -e utilisteur -e auteur -e author > tmp
if test -s tmp; then echo ; else echo "-" > tmp; fi
cat tmp >> $htmlline.co.authors
cat $htmlline.co.authors >> $Pagesclipco
cat $htmlline.co.authors
#O Finish the page $Pagesclipco
echo "" >> $Pagesclipco
#O End of as long as there are lines in commonshtml.list
done < commonshtml.list
#O End of 'if the line is not the name of book'.
#O End of while line in $Bookname.pj
done < $Projectdir/$Bookname.pj
#O clean intermediate files
rm -rf tmp
#O End of page $Pagesclipco
echo "</div>" >> $Pagesclipco
#T echo "$(gettext ' {{Newpage}} ')" >> $Pagesclipco
echo "<div style='page-break-before:always'></div>" >> $Pagesclipco
exit 0
9 775