94 lines
3.3 KiB
Bash
94 lines
3.3 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
OUT_DIR="output"
|
||
|
NAMESPACE="vintage/"
|
||
|
|
||
|
rm -rf "$OUT_DIR"
|
||
|
mkdir "$OUT_DIR"
|
||
|
mkdir "$OUT_DIR/pages"
|
||
|
mkdir "$OUT_DIR/attic"
|
||
|
mkdir "$OUT_DIR/meta"
|
||
|
mkdir "$OUT_DIR/media"
|
||
|
mkdir "$OUT_DIR/media_attic"
|
||
|
|
||
|
SOURCE_DIR="$(pwd)/lol-wiki"
|
||
|
export GIT_DIR="$SOURCE_DIR/.git"
|
||
|
|
||
|
baseref=master
|
||
|
lastref=$baseref
|
||
|
|
||
|
git checkout $baseref > /dev/null
|
||
|
|
||
|
for page in $(cd $SOURCE_DIR && find ./ -not -path "./.git/*" -type f); do
|
||
|
extension="${page##*.}"
|
||
|
|
||
|
if [ "$extension" == "mdwn" ]; then
|
||
|
mkdir -p "$OUT_DIR/pages/$NAMESPACE$(dirname "$page")"
|
||
|
pandoc --from=markdown --to=dokuwiki "$SOURCE_DIR/$page" -o "$OUT_DIR/pages/$NAMESPACE${page%.$extension}.txt"
|
||
|
echo PAGE "$page"
|
||
|
else
|
||
|
mkdir -p "$OUT_DIR/media/$NAMESPACE$(dirname "$page")"
|
||
|
cp "$SOURCE_DIR/$page" "$OUT_DIR/media/$NAMESPACE$page"
|
||
|
echo MEDIA "$page"
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
for ref in $(git rev-list $baseref); do
|
||
|
date="$(git show --no-patch --format=%ct "$ref")"
|
||
|
subject="$(git show --no-patch --format=%s "$ref")"
|
||
|
commiter="$(git show --no-patch --format=%cn "$ref")"
|
||
|
|
||
|
files=$(git -c "core.quotePath=false" diff --compact-summary --stat=999999 --no-renames $lastref $ref | head -n -1)
|
||
|
|
||
|
IFS=$'\n'
|
||
|
for line in $files; do
|
||
|
|
||
|
fileState=$(echo "$line" | cut -d'|' -f1 | awk '{$1=$1};1')
|
||
|
fileChanges=$(echo "$line" | cut -d'|' -f2 | awk '{$1=$1};1' | cut -d' ' -f1)
|
||
|
|
||
|
page=$(echo "$fileState" | rev | cut -d" " -f2- | rev)
|
||
|
status=$(echo "$fileState" | rev | cut -d" " -f1 | rev)
|
||
|
|
||
|
filename="$(basename "$page")"
|
||
|
extension="${filename##*.}"
|
||
|
|
||
|
if [ "$status" != "(gone)" ]; then
|
||
|
|
||
|
if [ "$extension" == "mdwn" ]; then
|
||
|
|
||
|
namespace=$(echo "$NAMESPACE${page%.$extension}" | tr "/" ":")
|
||
|
changesFile="$OUT_DIR/meta/$NAMESPACE${page%.$extension}.changes"
|
||
|
|
||
|
mkdir -p "$OUT_DIR/attic/$NAMESPACE$(dirname "$page")"
|
||
|
mkdir -p "$OUT_DIR/meta/$NAMESPACE$(dirname "$page")"
|
||
|
|
||
|
git show "$ref:$page" | pandoc --from=markdown --to=dokuwiki - -o - | gzip -c > "$OUT_DIR/attic/$NAMESPACE${page%.$extension}.$date.txt.gz"
|
||
|
|
||
|
touch "$changesFile"
|
||
|
if [ "$status" == "(new)" ]; then
|
||
|
printf '%s\n%s\n' "$date 127.0.0.1 C ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile"
|
||
|
else
|
||
|
printf '%s\n%s\n' "$date 127.0.0.1 E ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile"
|
||
|
fi
|
||
|
|
||
|
echo ATTIC PAGE "$page" from $ref "($subject)"
|
||
|
else
|
||
|
namespace=$(echo "$NAMESPACE${page}" | tr "/" ":")
|
||
|
changesFile="$OUT_DIR/media_meta/$NAMESPACE${page}.changes"
|
||
|
|
||
|
mkdir -p "$OUT_DIR/media_attic/$NAMESPACE$(dirname "$page")"
|
||
|
git show "$ref:$page" | gzip -c > "$OUT_DIR/media_attic/$NAMESPACE${page%.$extension}.$date.$extension.gz"
|
||
|
echo ATTIC MEDIA "$page" from $ref "($subject)"
|
||
|
|
||
|
mkdir -p "$OUT_DIR/media_meta/$NAMESPACE$(dirname "$page")"
|
||
|
touch "$changesFile"
|
||
|
printf '%s\n%s\n' "$date 127.0.0.1 E ${namespace} $subject $fileChanges $commiter" "$(cat "$changesFile")" > "$changesFile"
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
done
|
||
|
|
||
|
lastref=$ref
|
||
|
done
|
||
|
|
||
|
find "$OUT_DIR/meta/" -name '*.changes' ! -name '_media.changes' -exec cat {} + | sort -u > "$OUT_DIR/meta/_dokuwiki.changes"
|