mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 17:56:16 +00:00
Uses Ruby html-proofer to check the links. This commit also fixes the various problems it found, as well as dealing with some of its non-problem complaints (it doesn't like anchor (a) tags without either an href, name, or id). Running HTML proofer takes about 12 minutes on my system (with up to two threads), during which it prints no text. Travis CI times out after 10 minutes of nothing being written to stdout, so this commit also adds a background process the Makefile to print a line every minute while make runs.
119 lines
3.2 KiB
Bash
Executable file
119 lines
3.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# This file is licensed under the MIT License (MIT) available on
|
|
# http://opensource.org/licenses/MIT.
|
|
|
|
PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin
|
|
|
|
# Set variables and create temporary directories
|
|
LANGS=('ar' 'bg' 'bn' 'ca' 'cs' 'da' 'de' 'el' 'es' 'fa' 'fr' 'hi' 'hr' 'hu' 'id' 'it' 'ja' 'ko' 'lv' 'ml' 'nl' 'no' 'pl' 'pt_BR' 'ro' 'ru' 'sl' 'sr' 'sv' 'tr' 'uk' 'zh_CN' 'zh_TW')
|
|
WORKDIR=`mktemp -d`
|
|
LIVEDIR=`mktemp -d`
|
|
SITEDIR='/bitcoin.org/txpreview'
|
|
DESTDIR='/var/www/txpreview'
|
|
|
|
# Stop script in case a single command fails
|
|
set -e
|
|
|
|
# Cleanup on EXIT (even when a command fails)
|
|
trap "rm -rf $WORKDIR $LIVEDIR; kill 0; exit 1;" EXIT
|
|
trap "rm -rf $WORKDIR $LIVEDIR; kill 0;" SIGINT
|
|
|
|
if [[ ! -d $SITEDIR/site || ! -d $SITEDIR/tx ]]; then
|
|
echo 'Working folders missing'
|
|
exit
|
|
fi
|
|
|
|
# Update translations
|
|
cd $SITEDIR/tx/
|
|
tx pull -a -s --skip
|
|
|
|
# Return if all updated languages were previously processed
|
|
update=false
|
|
for la in "${LANGS[@]}"
|
|
do
|
|
checksum=`sha256sum $SITEDIR/tx/translations/bitcoinorg.bitcoinorg/$la.yml`
|
|
checksum=(${checksum//" "/ })
|
|
checksum=${checksum[@]:0:1}
|
|
checksum=${checksum:0:10}
|
|
if [[ -e $SITEDIR/site/_$checksum ]]; then
|
|
continue
|
|
fi
|
|
update=true
|
|
done
|
|
if [[ $update == false ]]; then
|
|
exit
|
|
fi
|
|
|
|
# Update git repository
|
|
cd $SITEDIR/site
|
|
git fetch -a
|
|
git reset --hard origin/master
|
|
git clean -x -f -d
|
|
|
|
# Copy files to temporary directory
|
|
rsync -rt --delete "$SITEDIR/site/" "$WORKDIR/"
|
|
|
|
# Get last modification time for _buildlock
|
|
touch "$SITEDIR/site/_buildlock"
|
|
lasttime=`stat -c %Y "$SITEDIR/site/_buildlock" | cut -d ' ' -f1`
|
|
|
|
# Create new checksum files
|
|
for la in "${LANGS[@]}"
|
|
do
|
|
checksum=`sha256sum $SITEDIR/tx/translations/bitcoinorg.bitcoinorg/$la.yml`
|
|
checksum=(${checksum//" "/ })
|
|
checksum=${checksum[@]:0:1}
|
|
checksum=${checksum:0:10}
|
|
touch $SITEDIR/site/_$checksum
|
|
done
|
|
|
|
# Update languages and generate diff files
|
|
cd $WORKDIR
|
|
linecounten=`cat $SITEDIR/tx/translations/bitcoinorg.bitcoinorg/en.yml | grep -o '^ \+[a-z0-9]\+:' | wc -l`
|
|
echo '<h1>Needs updating</h1>' > $WORKDIR/diff.html
|
|
for la in "${LANGS[@]}"
|
|
do
|
|
rsync -a $SITEDIR/tx/translations/bitcoinorg.bitcoinorg/$la.yml $WORKDIR/_translations/$la.yml
|
|
ruby $WORKDIR/_contrib/updatetx.rb $la
|
|
ruby $SITEDIR/addlang.rb $la
|
|
if [[ ! -e $WORKDIR/$la ]]; then
|
|
mkdir $WORKDIR/$la
|
|
fi
|
|
git diff --color-words master -- _translations/$la.yml | $SITEDIR/ansi2html > $WORKDIR/$la/diff.html
|
|
diff=`git diff master -- _translations/$la.yml`
|
|
linecount=`cat _translations/$la.yml | grep -o '^ \+[a-z0-9]\+:' | wc -l`
|
|
if [[ $diff != '' && $linecount == $linecounten ]]; then
|
|
echo "<a href=\"$la/diff.html\">$la</a><br>" >> $WORKDIR/diff.html
|
|
fi
|
|
done
|
|
|
|
# Build website in a child process
|
|
(
|
|
cd $WORKDIR
|
|
ENABLED_PLUGINS='alerts redirects releases' JEKYLL_COMMAND='jekyll' make
|
|
touch "$WORKDIR/_builddone"
|
|
)&
|
|
|
|
# Loop every 1 second to check status
|
|
while true
|
|
do
|
|
|
|
# Update site and exit if site has been successfully built
|
|
if [ -e "$WORKDIR/_builddone" ]; then
|
|
cd $LIVEDIR
|
|
rsync --delete -zrt --exclude '/.git' $WORKDIR/_site/ $DESTDIR/
|
|
exit
|
|
fi
|
|
|
|
# Cancel script if a concurrent script has touched _buildlock
|
|
time=0
|
|
if [ -e "$SITEDIR/site/_buildlock" ]; then
|
|
time=`stat -c %Y "$SITEDIR/site/_buildlock" | cut -d ' ' -f1`
|
|
fi
|
|
if [ $time != $lasttime ]; then
|
|
exit
|
|
fi
|
|
sleep 1
|
|
|
|
done
|