#!/bin/bash
###############################################################################
# #
# This script replaces XML codes with HUGO shortcodes and then outputs #
# the result as a new file named "index.md" in the same folder as #
# the source file. #
# #
# Drag and drop a markdown file onto one of the .desktop files in this folder #
# index.md will appear next to the original file that you dragged. #
# The original file will remain unchanged. #
# #
###############################################################################
# Check for input file
if [ ! -f "$1" ]; then
echo No file was dropped onto this Desktop file.
exit 1
fi
if [[ "$1" == *"index.md"* ]]; then
echo You dropped the index.md on here file by accident!
exit 1
fi
input="$1"
# Create a temp file
temp=$(mktemp)
cp "$input" "$temp"
# Replace text
# sed -i 's/oldtext/newtext/g' "$temp"
#
sed -i 's/<\/codeFile>/">}}{{<\/codeFile>}}/g' "$temp"
#
sed -i 's/<\/imgSource>/>}}{{<\/imgSource>}}/g' "$temp"
#
sed -i 's/<\/markdownFile>/>}}{{<\/markdownFile>}}/g' "$temp"
#
sed -i 's/<\/textFile>/>}}{{<\/textFile>}}/g' "$temp"
#
sed -i 's/<\/date>/{{}}{{<\/date>}}/g' "$temp"
#
sed -i 's/<\/video>/>}}{{<\/video>}}/g' "$temp"
# [Project name](/makes/games/platformer/)
sed -i 's//{{}}/g' "$temp"
sed -i 's/<\/project>/{{<\/project>}}/g' "$temp"
# convert * * into * *
sed -i 's/\*\ \;\*/\*\&\#32\;\*/g' "$temp"
# Copy the new modified file to the destination
outfolder=$(dirname "$input")
if [ -d "$outfolder" ]; then
cp "$temp" "$outfolder/index.md"
fi
#######################################################
# Wait for me to debug the results
echo Done! Press ENTER to continue
#read
# Delete temp file
if [ -f "$temp" ]; then
rm "$temp"
fi
# End program
exit 0