Astroport.ONE/RUNTIME/TW/import_tiddler.sh

42 lines
1.0 KiB
Bash
Raw Normal View History

2024-04-21 22:55:49 +02:00
#!/bin/bash
2024-04-22 19:17:32 +02:00
# Generate a unique timestamp
2024-04-21 22:55:49 +02:00
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
2024-04-22 19:17:32 +02:00
# Check if TiddlyWiki file exists
2024-04-21 22:55:49 +02:00
TW="$1"
[[ ! -s $TW ]] \
&& echo "Missing TiddlyWiki index.html \$1: $TW" \
&& exit 1
2024-04-22 19:17:32 +02:00
# Check if Tiddler JSON file exists
2024-04-21 22:55:49 +02:00
TIDDLER="$2"
[[ ! -s $TIDDLER || $TIDDLER == "" ]] \
&& echo "Missing Tiddler JSON file \$2: $TIDDLER" \
&& exit 1
2024-04-22 19:17:32 +02:00
# Add created and modified fields to the Tiddler JSON file
echo "Putting ${TIDDLER} in ${TW}"
2024-04-22 19:17:32 +02:00
jq '.[] + {created: $MOATS, modified: $MOATS}' --arg MOATS "$MOATS" "$TIDDLER" > "${TIDDLER}.tmp"
2024-04-21 22:55:49 +02:00
2024-04-22 19:17:32 +02:00
# Run TiddlyWiki import command
echo "Running TiddlyWiki import..."
tiddlywiki --load "${TW}" \
--import "${TIDDLER}.tmp" 'application/json' \
--output /tmp \
--render '$:/core/save/all' "${MOATS}.html" 'text/plain'
2024-04-21 22:55:49 +02:00
2024-04-22 19:17:32 +02:00
# Check if import was successful
if [[ -s /tmp/${MOATS}.html ]]; then
echo "Import successful."
cp /tmp/${MOATS}.html ${TW}
rm /tmp/${MOATS}.html
rm "${TIDDLER}.tmp"
echo "Updated TiddlyWiki:
${TW}"
exit 0
2024-04-22 19:17:32 +02:00
else
echo "ERROR"
2024-04-22 19:17:32 +02:00
exit 1
fi