56 lines
1.3 KiB
Bash
Executable File
56 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"
|
|
hd_cli="./hedgedoc"
|
|
# HEDGEDOC_SERVER="https://live.kladjes.nl"
|
|
hd="$hd_cli"
|
|
|
|
function download_cli() {
|
|
if [ ! -f "$hd_cli" ]; then
|
|
curl $cli_url -o "$hd_cli"
|
|
chmod +x "$hd_cli"
|
|
fi
|
|
}
|
|
|
|
function get_md() {
|
|
local note_id="$1"
|
|
local out_path="$2"
|
|
echo "get_md: '$note_id' '$out_path'"
|
|
$hd export --md "$note_id" "$out_path"
|
|
}
|
|
|
|
function push_md() {
|
|
local note_id="$1"
|
|
local src_path="$2"
|
|
echo "push_md: '$note_id' '$src_path'"
|
|
$hd import "$note_id" "$out_path"
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
download_cli
|
|
|
|
# mkdir -p "./out"
|
|
get_index "$main_index_id" "./markdown"
|