fsfe-website/tools/update_localmenus.sh
Sebastiano Pistore ac826f11fa
All checks were successful
continuous-integration/drone/pr Build is passing
-synced text files to latest version.
-updated ita trans.

-Typos fixing in comments of txt and sh.
2020-07-24 16:46:53 +02:00

86 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Update local menus
# -----------------------------------------------------------------------------
# This script is called from the phase 1 Makefile and updates all the
# .localmenu.*.xml files containing the local menus.
# -----------------------------------------------------------------------------
set -e
echo "* Updating local menus"
# -----------------------------------------------------------------------------
# Get a list of all source files containing local menus
# -----------------------------------------------------------------------------
all_files=$(
find * -name "*.xhtml" -not -name "*-template.*" \
| xargs grep -l "</localmenu>" \
| sort
)
# -----------------------------------------------------------------------------
# Split that list by localmenu directory
# -----------------------------------------------------------------------------
declare -A files_by_dir
for file in ${all_files}; do
dir=$(xsltproc build/xslt/get_localmenu_dir.xsl ${file})
dir=${dir:-$(dirname ${file})}
files_by_dir[${dir}]="${files_by_dir[${dir}]} ${file}"
done
# -----------------------------------------------------------------------------
# If any of the source files has been updated, rebuild all .localmenu.*.xml
# -----------------------------------------------------------------------------
for dir in ${!files_by_dir[@]}; do
for file in ${files_by_dir[${dir}]}; do
if [ "${file}" -nt "${dir}/.localmenu.en.xml" ]; then
# Find out which languages to generate.
languages=$(
ls ${files_by_dir[${dir}]} \
| sed 's/.*\.\(..\)\.xhtml/\1/' \
| sort --uniq
)
# Compile the list of base filenames of the source files.
basefiles=$(
ls ${files_by_dir[${dir}]} \
| sed 's/\...\.xhtml//' \
| sort --uniq
)
# For each language, create the .localmenu.${lang}.xml file.
for lang in $languages; do
echo "* Creating ${dir}/.localmenu.${lang}.xml"
{
echo "<?xml version=\"1.0\"?>"
echo ""
echo "<feed>"
for basefile in ${basefiles}; do
if [ -f "${basefile}.${lang}.xhtml" ]; then
file="${basefile}.${lang}.xhtml"
else
file="${basefile}.en.xhtml"
fi
xsltproc \
--stringparam "link" "/${basefile}.html" \
build/xslt/get_localmenu_line.xsl \
"${file}"
echo ""
done | sort
echo "</feed>"
} > "${dir}/.localmenu.${lang}.xml"
done
# The local menu for this directory has been built, no need to check
# further source files.
break
fi
done
done