62 lines
2 KiB
Bash
Executable file
62 lines
2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# This script will generate a completely static website by downloading page generated by PHP
|
|
|
|
PORT=8452
|
|
echo "Trying to start a PHP server on port $PORT"
|
|
php -S 127.0.0.1:$PORT -t ./public &
|
|
phpPID=$!
|
|
echo "PHP server running with PID $phpPID"
|
|
|
|
sleep 0.3
|
|
mkdir ./build
|
|
cd build
|
|
|
|
locales=('fr' 'en')
|
|
for locale in "${locales[@]}"; do
|
|
echo "Downloading $locale..."
|
|
mkdir $locale
|
|
cd $locale
|
|
|
|
# wget with custom header to not render link to change language because wget will follow them
|
|
wget -k -K -E -r -l 10 -p -N -F -nH http://127.0.0.1:$PORT/$locale --header="Enable-Locale-Switch: no"
|
|
|
|
mv $locale.html index.html
|
|
|
|
# Multiple sed commands to clean up the mess made by wget replacing stuff
|
|
# sed -E -i 's/\"([a-z]{2})\.html/\"\/\1/g' *.html
|
|
|
|
# for the main page, remove broken link to the same page (because we renamed to index.html)
|
|
sed -E -i "s/\"$locale\.html/\"/g" index.html
|
|
|
|
# for each file other than index.html, put a proper link back to the main page
|
|
find ./ -not -name "index.html" -name "*.html" -exec sed -E -i "s/\"(\.\.\/)?$locale\.html/\"\1index.html/g" {} \+
|
|
|
|
# remove assets
|
|
rm -rv *.woff dist imgs
|
|
|
|
cd ..
|
|
done
|
|
|
|
# repair the links of the footer locale switcher
|
|
# for each line with data-lang-switch="{locale}" replace the href with the link to /{locale}/path...
|
|
# attempt to do with pipe failed, so I use a non optimal for loop
|
|
# find ./ -name "*.html" -exec sh -c 'sed -E -i "s/data-lang-switch=\"([a-z]{2})\".+href\=\".*\"/href\=\"\/\1\/{}\"/g" {}' \;
|
|
for path in $(find ./ -name "*.html"); do
|
|
pathM=`echo $path | cut -c 6-`
|
|
sed -E -i "s%data-lang-switch=\"([a-z]{2})\".+href\=\".*\"%href\=\"/\1/$pathM\"%g" $path
|
|
done
|
|
|
|
find ./ -name '*.orig' -delete
|
|
|
|
# change the path of all assets
|
|
find ./ -name "*.html" -exec sed -E -i "s%\"\.\./dist/%\"/dist/%g; s%\"dist/%\"/dist/%g; s%\"\.\./imgs/%\"/imgs/%g; s%\"imgs/%\"/imgs/%g" {} \+
|
|
|
|
|
|
cp -r ../public/* ./
|
|
rm index.php
|
|
|
|
kill $phpPID
|
|
|
|
echo "Done."
|
|
|