-
Notifications
You must be signed in to change notification settings - Fork 7
/
import_to_hugo.sh
executable file
·55 lines (42 loc) · 1.57 KB
/
import_to_hugo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
##!/bin/bash
set -e
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: move_logseq_content.sh <export_folder> <blog_folder>"
exit 1
fi
# Extract arguments
export_folder="$1"
blog_folder="$2"
# Check if the export folder exists
if [ ! -d "$export_folder" ]; then
echo "Error: The export folder does not exist."
exit 1
fi
# Check if the blog folder exists
if [ ! -d "$blog_folder" ]; then
echo "Error: The blog folder does not exist."
exit 1
fi
blog_content_folder="${BLOG_CONTENT_FODLER:-/graph}"
images_folder="${BLOG_IMAGES_FOLDER:-/assets/graph}"
# by default the files get copied as follows
# - /logseq-pages -> /content/graph
# - /logseq-assets -> /static/assets/graph
pages_destination="$blog_folder/content$blog_content_folder"
assets_destination="$blog_folder/static$images_folder"
# delete existing pages and assets
rm -rf "$pages_destination"
rm -rf "$assets_destination"
# prepare the directories
mkdir -p "$pages_destination"
mkdir -p "$assets_destination"
# Move the content of logseq-pages to the new destination
cp -R "$export_folder/logseq-pages"/* "$pages_destination/"
# Move the content of logseq-assets to the new destination
cp -R "$export_folder/logseq-assets"/* "$assets_destination/"
# replace the /logseq-asstes/ paths with the hugo image folder
find "$pages_destination" -type f -exec sed -i.bak -e "s@/logseq-assets/@$images_folder/@g" {} \;
find "$pages_destination" -type f -exec sed -i.bak -e "s@/logseq-pages/@$blog_content_folder/@g" {} \;
rm -f "$pages_destination"/*.bak
echo "Content moved successfully."