-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhehugo.sh
executable file
·57 lines (48 loc) · 1.12 KB
/
hehugo.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
56
57
#!/bin/bash
function usage() {
echo "Usage: $0 <command> [args]"
echo "Commands:"
echo " new 'Article title'"
echo " preview"
echo " build"
exit 1
}
function new() {
if [ -z "$1" ]; then
echo "Usage: $0 new 'Article title'"
exit 1
fi
TITLE="$1"
SLUG=$(echo "$TITLE" | tr '[:upper:]' '[:lower:]')
SLUG=$(echo "$SLUG" | sed 's/ /-/g')
SLUG=$(echo "$SLUG" | sed 's/[^a-z0-9-]//g')
CURRENT_YEAR=$(date +%Y)
CURRENT_DATE=$(date +%Y-%m-%d)
export HUGO_TITLE="$TITLE"
hugo new --kind article "articles/$CURRENT_YEAR/$CURRENT_DATE-$SLUG"
}
function preview() {
hugo server --buildDrafts --disableFastRender --navigateToChanged --templateMetrics --templateMetricsHints --watch --forceSyncStatic -e production --minify
}
function build() {
rm -rf ./output
hugo -e production --minify --logLevel debug --printI18nWarnings --printPathWarnings
}
if [ "$#" -lt 1 ]; then
usage
fi
case "$1" in
new)
shift
new "$@"
;;
preview)
preview
;;
build)
build
;;
*)
usage
;;
esac