PEE51_SPC_documents/push_to_hd.sh

51 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
server='https://live.kladjes.nl'
main_index_id="tPb3Up1fQEuZ86yrJSkYRQ"
cli_url="https://raw.githubusercontent.com/hedgedoc/cli/refs/heads/master/bin/hedgedoc"
HEDGEDOC_SERVER="$server"
if [ ! -f "./hedgedoc" ]; then
curl $cli_url -o "./hedgedoc"
chmod +x "./hedgedoc"
fi
. ./hedgedoc --import
function get_md() {
local note_id="$1"
local out_path="$2"
echo "get_md: '$note_id' '$out_path'"
export_note --md "$note_id" "$out_path"
}
function push_md() {
local note_id="$1"
local src_path="$2"
echo "push_md: '$src_path' '$note_id'"
import_note "$src_path" "$note_id"
}
function get_index() {
local note_id="$1"
local src_dir="$2"
local index_file="$(mktemp)"
echo "get_index: '$note_id' '$src_dir'"
get_md "$note_id" "$index_file"
# get all unsorted list line (`^- `) that have a link with lable ending with '.md'
local index=$(cat "$index_file" | grep -e '^- \[[^\}]*\.md\]' | sed -e 's/^.*\[\(.*\)\](\(.*\))/\1=\2/')
rm "$index_file"
for f in $index
do
local name="$(echo "$f" | sed -e 's/=.*$//')"
local id="$(echo "$f" | sed -e 's/^.*=//' | tr -dc '[:alnum:]-_')"
push_md "$id" "$src_dir/$name"
done
}
user_login --email kladjes@finnvanreenen.nl
get_index "$main_index_id" "./markdown"