50 lines
1.2 KiB
Bash
Executable File
50 lines
1.2 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 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'"
|
|
export_note --md "$note_id" "$out_path"
|
|
}
|
|
|
|
function get_index() {
|
|
local note_id="$1"
|
|
local out_dir="$2"
|
|
local index_file="$(mktemp)"
|
|
|
|
echo "get_index: '$note_id' '$out_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:]-_')"
|
|
get_md "$id" "$out_dir/$name"
|
|
done
|
|
}
|
|
|
|
# mkdir -p "./out"
|
|
get_index "$main_index_id" "./markdown"
|