-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTaskfile.yml
129 lines (116 loc) · 3.53 KB
/
Taskfile.yml
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
version: '3'
dotenv: ['.env']
vars:
TERMUX: '{{and .PREFIX (contains "com.termux" .PREFIX)}}'
TODAY: '{{now | date "2006-01-02"}}'
HUGO: '{{default "hugo" .HUGO}}'
tasks:
serve:
desc: Runs hugo serve, all posts visible.
cmds:
- |
{{.HUGO}} serve -D -E -F {{if .TERMUX}}--noBuildLock{{end}} --bind=0.0.0.0 --baseURL=http://0.0.0.0:1313
build:
desc: Create a production build of the site in ./public.
cmds:
- |
{{.HUGO}} --minify {{if .TERMUX}}--noBuildLock{{end}}
new-blog:
desc: Creates a new blog post.
vars:
TITLE: '{{.CLI_ARGS}}'
SLUG: '{{trimall "-" (regexReplaceAll "--+" (regexReplaceAll "[^A-Za-z0-9-]" (regexReplaceAll "\\s+" (lower .TITLE) "-") "") "-")}}'
DIR: 'content/blog/{{.TODAY}}-{{.SLUG}}'
FILE: '{{.DIR}}/index.md'
preconditions:
- sh: '[ ! -d "{{.DIR}}" ]'
cmds:
- |
mkdir "{{.DIR}}"
cat > "{{.FILE}}" <<EOF
---
title: "{{.TITLE}}"
#description:
date: {{.TODAY}}
cover:
image: cover.jpg
alt: Add cover.jpg at ~1200x600px and describe it here
relative: true
draft: true
---
EOF
echo "{{.FILE}}"
new-til:
desc: Creates a new TIL post.
vars:
TITLE: '{{.CLI_ARGS}}'
SLUG: '{{trimall "-" (regexReplaceAll "--+" (regexReplaceAll "[^A-Za-z0-9-]" (regexReplaceAll "\\s+" (lower .TITLE) "-") "") "-")}}'
FILE: 'content/til/{{.SLUG}}.md'
preconditions:
- sh: '[ ! -f "{{.FILE}}" ]'
cmds:
- |
cat > {{.FILE}} <<EOF
---
title: "{{.TITLE}}"
date: {{.TODAY}}
tags: []
draft: true
---
EOF
echo {{.FILE}}
to-bundle:
desc: Turns a single page (page.md) into a bundle (page/index.md).
vars:
PAGE: 'content/{{trimPrefix "content/" .CLI_ARGS}}'
DIR: '{{trimSuffix ".md" .PAGE}}'
preconditions:
- test -f "{{.PAGE}}"
- sh: "[ ! -d \"{{.DIR}}\" ]"
cmds:
- |
mkdir "{{.DIR}}"
mv "{{.PAGE}}" "{{.DIR}}/index.md"
to-single:
desc: Turns a bundle (page/index.md) into a single page (page.md).
vars:
BUNDLE: 'content/{{trimPrefix "content/" (trimSuffix "/" .CLI_ARGS)}}'
PAGE: '{{.BUNDLE}}.md'
preconditions:
- test -d "{{.BUNDLE}}"
- test -f "{{.BUNDLE}}/index.md"
- sh: "[ ! -f \"{{.BUNDLE}}.md\" ]"
- sh: "[ -n $(find \"{{.BUNDLE}}\" -mindepth 1 -maxdepth 1 | grep -v index.md) ]"
cmds:
- |
mv "{{.BUNDLE}}/index.md" "{{.PAGE}}"
rm -r "{{.BUNDLE}}"
redate:
desc: Redates a page to today's date.
vars:
PATH: 'content/{{trimPrefix "content/" (trimSuffix "/" .CLI_ARGS)}}'
cmds:
- |
if [ -d "{{.PATH}}" ]; then
# bundle
file="{{.PATH}}/index.md"
path="{{.PATH}}"
elif [ -f "{{.PATH}}.md" ]; then
# page
file="{{.PATH}}.md"
path="$file"
fi
current=$(yq -f extract '.date | format_datetime("2006-01-02")' $file)
echo $current
yq -i -f process '.date=now' $file
now=$(yq -f extract '.date | format_datetime("2006-01-02")' $file)
echo $now
rename="${path//$current/$now}"
echo $rename
mv "$path" "$rename" || true
update-mods:
desc: Updates all submodules.
cmds:
- git submodule update --remote --merge
- cd themes/PaperMod && git pull origin master
- cd themes/hugo-notice && git pull origin main