-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.sh
More file actions
executable file
·106 lines (77 loc) · 2.79 KB
/
Copy pathaction.sh
File metadata and controls
executable file
·106 lines (77 loc) · 2.79 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# Only print echos
set +x
# To fetch and use this script in a GitHub action:
#
# curl -s -S https://raw.githubusercontent.com/saberzero1/quartz-themes/master/action.sh | bash -s -- <THEME_NAME>
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
BLUE='\033[1;34m'
NC='\033[0m'
echo_err() { echo -e "${RED}$1${NC}"; }
echo_warn() { echo -e "${YELLOW}$1${NC}"; }
echo_ok() { echo -e "${GREEN}$1${NC}"; }
echo_info() { echo -e "${BLUE}$1${NC}"; }
THEME_DIR="themes"
QUARTZ_STYLES_DIR="quartz/styles"
FINAL_THEME_DIR="./$QUARTZ_STYLES_DIR/$THEME_DIR"
if [ -f "./$QUARTZ_STYLES_DIR/custom.scss" ]; then
echo_ok "Quartz root succesfully detected..."
FINAL_THEME_DIR="./$QUARTZ_STYLES_DIR/$THEME_DIR"
else
echo_warn "Quartz root not detected, checking if we are in the styles directory..."
if [ -f "./custom.scss" ]; then
echo_ok "Styles directory detected..."
FINAL_THEME_DIR="./$THEME_DIR"
else
echo_err "Cannot detect Quartz repository. Are you in the correct working directory?" 1>&2
exit 1
fi
fi
echo -e "Input theme: ${BLUE}$*${NC}"
echo "Parsing input theme..."
# Concat parameters
result=""
for param in "$@"; do
if [[ -n "$result" ]]; then
result="$result-"
fi
result="$result$param"
done
if [ -z "$result" ]; then
echo_warn "No theme provided, defaulting to Tokyo Night..."
result="tokyo-night"
fi
# Convert to lowercase
THEME=$(echo "$result" | tr '[:upper:]' '[:lower:]')
echo -e "Theme ${BLUE}$*${NC} parsed to $(echo_info ${THEME})"
echo "Validating theme..."
echo "Cleaning theme directory..."
rm -rf ${FINAL_THEME_DIR}
echo "Creating theme directory..."
mkdir -p ${FINAL_THEME_DIR}
echo "Fetching theme files..."
# clone only the specified theme using sparse checkout to save bandwidth and time
git clone -n --depth=1 --filter=tree:0 https://github.com/saberzero1/quartz-themes.git &> /dev/null
git -C quartz-themes sparse-checkout set --no-cone /themes/${THEME} &> /dev/null
git -C quartz-themes checkout &> /dev/null
echo "Installing theme files..."
mv quartz-themes/themes/${THEME}/* ${FINAL_THEME_DIR}
rm -rf quartz-themes
echo "Applying patches..."
if grep -q -e "quartz themes dark-only" -e "quartz themes light-only" "$FINAL_THEME_DIR/_index.scss"; then
echo_warn "Single mode theme detected, applying patch..."
sed -i "/Component\.Darkmode\(\)/d" "quartz.layout.ts"
fi
echo "Verifying setup..."
cd ${FINAL_THEME_DIR}
if grep -q '^@use "./themes";' "../custom.scss"; then
# Import already present in custom.scss
echo_warn "Theme import line already present in custom.scss. Skipping..."
else
# Add `@use "./themes";` import to custom.scss
sed -ir 's#@use "./base.scss";#@use "./base.scss";\n@use "./themes";#' "../custom.scss"
echo_info "Added import line to custom.scss..."
fi
echo_ok "Finished fetching and applying theme '${THEME}'."