Factorisation des encodages d’URL en une fonction
This commit is contained in:
parent
a377748de7
commit
ef92c3e888
1 changed files with 12 additions and 13 deletions
25
generator.sh
25
generator.sh
|
@ -22,6 +22,15 @@ echo "${blue}Start${reset} /$webpath"
|
|||
# Déplacement dans le dossier à traiter
|
||||
cd "${root}/${webpath}"
|
||||
|
||||
# Encode certains caractères posant problème dans le HTML
|
||||
encodeUrl() {
|
||||
encoded="${*//\&/%26}"
|
||||
encoded="${encoded//\?/%3F}"
|
||||
encoded="${encoded//\#/%23}"
|
||||
encoded="${encoded//\"/%22}"
|
||||
printf "%s" "${encoded}"
|
||||
}
|
||||
|
||||
# Définition des différentes parties de la page
|
||||
header() {
|
||||
cat <<DELIM
|
||||
|
@ -46,13 +55,9 @@ DELIM
|
|||
}
|
||||
|
||||
row() {
|
||||
encoded="${1//\&/%26}"
|
||||
encoded="${encoded//\?/%3F}"
|
||||
encoded="${encoded//\#/%23}"
|
||||
encoded="${encoded//\"/%22}"
|
||||
cat <<DELIM
|
||||
<tr>
|
||||
<td><a href="${encoded}">${1}</a></td>
|
||||
<td><a href="$(encodeUrl "${1}")">${1}</a></td>
|
||||
<td class="right-align" data-kbytes="${2}">${3}</td>
|
||||
<td class="right-align">${4}</td>
|
||||
<td>${5}</td>
|
||||
|
@ -80,9 +85,7 @@ IFS=/
|
|||
|
||||
for folder in $webpath
|
||||
do
|
||||
encoded_folder="${folder//\&/%26}"
|
||||
encoded_folder="${encoded_folder//\?/%3F}"
|
||||
tmp+="$encoded_folder/"
|
||||
tmp+="$(encodeUrl "$folder")/"
|
||||
navpath+="<a href=\"$tmp\">$folder</a>/"
|
||||
done
|
||||
|
||||
|
@ -165,11 +168,7 @@ do
|
|||
case $mimetype in
|
||||
audio/*)
|
||||
# Pour l'audio, ajout d'un lecteur
|
||||
encoded_src="${i//\&/%26}"
|
||||
encoded_src="${encoded_src//\?/%3F}"
|
||||
encoded_src="${encoded_src//\#/%23}"
|
||||
encoded_src="${encoded_src//\"/%22}"
|
||||
type="<audio controls preload=\"$preload\"><source src=\"$encoded_src\" type=\"$mimetype\">$mimetype</audio>";;
|
||||
type="<audio controls preload=\"$preload\"><source src=\"$(encodeUrl "${i}")\" type=\"$mimetype\">$mimetype</audio>";;
|
||||
image/*)
|
||||
# Pour les images, une miniature de 60px de haut est créée
|
||||
thumbname="$(md5sum <<<$(readlink -f "$i") | cut -d' ' -f1).${i##*.}" # Nom sur base d'un hash pour éviter les conflits
|
||||
|
|
Loading…
Reference in a new issue