Created
June 1, 2025 15:22
-
-
Save dregad/6e1a818dce4b387324643b053b73cf1d to your computer and use it in GitHub Desktop.
Dokuwiki remove square brackets around tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ---------------------------------------------------------------------------- | |
# Update a Dokuwiki instance to remove [] around tags. | |
# | |
# See https://github.com/ADOdb/ADOdb/issues/1071 | |
# | |
# 2025-06-01 dregad Created | |
# ---------------------------------------------------------------------------- | |
# Dokuwiki instance and user - edit as appropriate | |
DWROOT=dokuwiki | |
DWUSER= | |
MSG="Remove square brackets in tags" | |
# ---------------------------------------------------------------------------- | |
# Exit if error | |
set -e | |
DWPAGES=$DWROOT/data/pages | |
# Dokuwiki page editing tool | |
# https://www.dokuwiki.org/cli#dwpagephp | |
DWP="$DWROOT/bin/dwpage.php --no-colors" | |
if [[ -n "$DWUSER" ]] | |
then | |
DWP="$DWP -u $DWUSER" | |
fi | |
# Temp directory | |
TMPDIR=$(mktemp -d) | |
#cd "$TMPDIR" | |
echo "Ready to $MSG in '$DWROOT'" | |
read -p "Press enter to continue" LINE | |
echo | |
COUNT=0 | |
# List all pages defining tags with square brackets | |
find "$DWPAGES" -type f -name '*.txt' -print0 | | |
xargs -0 grep -l '{{tag>.*[][]' | sort | | |
{ | |
while read -r LINE | |
do | |
# Dokuwiki page name from path | |
PAGE="${LINE#$DWPAGES/}" | |
PAGE="${PAGE%.txt}" | |
PAGE="${PAGE//\//:}" | |
TMPPAGE=$TMPDIR/$(basename $LINE) | |
# Checkout page | |
php $DWP checkout "$PAGE" $TMPPAGE | |
# Update page | |
echo "$MSG" | |
sed -r -i "/\{\{tag\>/s/(\[ *| *])//g" $TMPPAGE | |
# Commit changes | |
php $DWP commit -m "$MSG" $TMPPAGE "$PAGE" | |
((++COUNT)) | |
echo | |
done | |
echo "$COUNT pages updated" | |
} | |
echo | |
echo "Cleaning up" | |
rm -r "$TMPDIR" | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment