-
Notifications
You must be signed in to change notification settings - Fork 2
/
Taskfile.yml
117 lines (105 loc) · 3.2 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
version: '3'
vars:
TERMUX: '{{and .PREFIX (contains "com.termux" .PREFIX)}}'
TODAY: '{{now | date "2006-01-02"}}'
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:
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