-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask
More file actions
executable file
·130 lines (104 loc) · 2.97 KB
/
Copy pathtask
File metadata and controls
executable file
·130 lines (104 loc) · 2.97 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
set -e
if [[ -a ".env" ]]; then
source .env
fi
function help() {
echo
echo "task <command> [options]"
echo
echo "commands:"
echo
local -a rows
local max_cmd=7 max_opt=6 max_desc=11
rows+=("Command|Option|Description")
rows+=("install||Install hugo and Vercel cli.")
rows+=("build-hugo|[url]|Build with Hugo.")
rows+=("serve-hugo||Serve output from public folder.")
rows+=("dev-hugo|[url]|Start Hugo dev server.")
rows+=("new-post|[title]|Create new post from Hugo template.")
rows+=("version||Show version of required tools.")
for row in "${rows[@]}"; do
IFS='|' read -r cmd opt desc <<< "$row"
(( ${#cmd} > max_cmd )) && max_cmd=${#cmd}
(( ${#opt} > max_opt )) && max_opt=${#opt}
(( ${#desc} > max_desc )) && max_desc=${#desc}
done
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "Command" \
"$max_opt" "Option" \
"$max_desc" "Description"
printf '|-%*s-|-%*s-|-%*s-|\n' \
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
for row in "${rows[@]:1}"; do
IFS='|' read -r cmd opt desc <<< "$row"
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "$cmd" \
"$max_opt" "$opt" \
"$max_desc" "$desc"
done
}
BASE_URL="http://localhost:1313"
# Import commands
if [[ -d "$HOME/taskfile.build/bin" ]]; then
for file in "$HOME/taskfile.build/bin/"*; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
fi
# Project commands
install() {
echo "Install hugo from binary source"
curl -L -o hugo.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.141.0/hugo_0.141.0_Linux-64bit.tar.gz
mkdir -p tmp
tar -xzf hugo.tar.gz -C tmp
mv tmp/hugo .
rm hugo.tar.gz
echo "Install Node dependencies."
pnpm install
}
build-hugo() {
if [[ -n "$1" ]]; then
BASE_URL=$1
fi
pnpm run build
./hugo -b "$BASE_URL"
}
serve-hugo() {
pnpx serve public
}
dev-hugo() {
if [[ -n "$1" ]]; then
BASE_URL=$1
fi
pnpm run build
echo "Remove public folder."
rm -rf public
open-url-with-delay 'http://localhost:1313/' & ./hugo server -b "$BASE_URL"
}
new-post() {
if [[ -z "$1" ]]; then
echo "Error: Title is required. Usage: task new-post \"Post Title\""
return 1
fi
# Format title (replace spaces with dashes)
local formatted_title=$(echo "$1" | sed 's/ /-/g' | tr '[:upper:]' '[:lower:]')
# Create filename
local filename="$formatted_title.md"
# Create post using hugo
./hugo new "blog/posts/$filename"
echo "Created new post: content/de/blog/posts/$filename"
}
version() {
./hugo --version
}
if declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
echo "Unknown command: $1"
help
exit 1
fi