foundry-to-dokuwiki.sh
· 945 B · Bash
Sin formato
#!/bin/bash
# This is the FoundryVTT export plugin used to generate these markdown files:
# https://foundryvtt.com/packages/export-markdown
set -e
# TODO: Change PREFIX to be optional, get some argparse type things going
PREFIX=$1
SRC=$2
DST=$3
# 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
find . -regex '.*journalentry\.[a-z0-9]+\.txt' -exec grep -m 1 -H '.' {} \; | sed -E "s/\.\/(journalentry\.[a-z0-9]+)\.txt:====== (.*) ======/ \* [[$PREFIX\1|\2]]/"
# Go back
cd -
| 1 | #!/bin/bash |
| 2 | |
| 3 | # This is the FoundryVTT export plugin used to generate these markdown files: |
| 4 | # https://foundryvtt.com/packages/export-markdown |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | # TODO: Change PREFIX to be optional, get some argparse type things going |
| 9 | PREFIX=$1 |
| 10 | SRC=$2 |
| 11 | DST=$3 |
| 12 | |
| 13 | # Create dokuwiki files "in place" or rather, alongside markdown |
| 14 | find "$SRC" -iname "*.md" -type f -exec sh -c 'pandoc -f markdown -t dokuwiki "${0}" -o "${0%.md}.txt"' {} \; |
| 15 | |
| 16 | # Copy over the dokuwiki .txt files, flatten along the way: |
| 17 | # FoundryVTT uses uuids so names shouldn't clash |
| 18 | find "$SRC" -mindepth 1 -type f -iname "*.txt" -exec cp -t "$DST" -i '{}' + |
| 19 | |
| 20 | # Move into destination folder for renaming |
| 21 | cd $DST |
| 22 | |
| 23 | # Do the rename |
| 24 | rename 'y/A-Z/a-z/' * |
| 25 | |
| 26 | # While here, spit out a TOC of top level journal name links |
| 27 | find . -regex '.*journalentry\.[a-z0-9]+\.txt' -exec grep -m 1 -H '.' {} \; | sed -E "s/\.\/(journalentry\.[a-z0-9]+)\.txt:====== (.*) ======/ \* [[$PREFIX\1|\2]]/" |
| 28 | |
| 29 | # Go back |
| 30 | cd - |