foundry-to-dokuwiki.sh
· 804 B · Bash
Bruto
#!/bin/bash
set -e
SRC=$1
DST=$2
# Create dokuwiki files "in place" or rather, alongside markdown
find "$SRC" -iname "*.md" -type f -exec sh -c 'pandoc -f markdown -t dokuwiki "${0}" -o "${0%.md}.txt"' {} \;
# Copy over the dokuwiki .txt files, flatten along the way:
# FoundryVTT uses uuids so names shouldn't clash
find "$SRC" -mindepth 1 -type f -iname "*.txt" -exec cp -t "$DST" -i '{}' +
# Move into destination folder for renaming
cd $DST
# Do the rename
rename 'y/A-Z/a-z/' *
# While here, spit out a TOC of top level journal name links
# TODO: Make the dg:foundry: dokuwiki namespace prefix configurable
find . -regex '.*journalentry\.[a-z0-9]+\.txt' -exec grep -m 1 -H '.' {} \; | sed -E 's/\.\/(journalentry\.[a-z0-9]+)\.txt:====== (.*) ======/ \* [[dg:foundry:\1|\2]]/'
# Go back
cd -
| 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | SRC=$1 |
| 6 | DST=$2 |
| 7 | |
| 8 | # Create dokuwiki files "in place" or rather, alongside markdown |
| 9 | find "$SRC" -iname "*.md" -type f -exec sh -c 'pandoc -f markdown -t dokuwiki "${0}" -o "${0%.md}.txt"' {} \; |
| 10 | |
| 11 | # Copy over the dokuwiki .txt files, flatten along the way: |
| 12 | # FoundryVTT uses uuids so names shouldn't clash |
| 13 | find "$SRC" -mindepth 1 -type f -iname "*.txt" -exec cp -t "$DST" -i '{}' + |
| 14 | |
| 15 | # Move into destination folder for renaming |
| 16 | cd $DST |
| 17 | |
| 18 | # Do the rename |
| 19 | rename 'y/A-Z/a-z/' * |
| 20 | |
| 21 | # While here, spit out a TOC of top level journal name links |
| 22 | # TODO: Make the dg:foundry: dokuwiki namespace prefix configurable |
| 23 | find . -regex '.*journalentry\.[a-z0-9]+\.txt' -exec grep -m 1 -H '.' {} \; | sed -E 's/\.\/(journalentry\.[a-z0-9]+)\.txt:====== (.*) ======/ \* [[dg:foundry:\1|\2]]/' |
| 24 | |
| 25 | # Go back |
| 26 | cd - |