-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjustfile
More file actions
194 lines (179 loc) · 4.45 KB
/
Copy pathjustfile
File metadata and controls
194 lines (179 loc) · 4.45 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# List all available recipes
default:
@just --list
# Compile Tailwind css, then build the site with Zola
build: tailwind-build
zola build
# Try to build site without rendering (checks links)
check:
zola check
# Clear public directory generated by Zola
reset:
rm -rf public
# Install Node.js dependencies
install:
npm install
# Move basecoat component js files from node_modules to static/js
basecoat:
#!/usr/bin/env bash
cp node_modules/basecoat-css/dist/js/*.js static/js/
echo "Successfully copied basecoat component js to static/js"
# Render a single qmd file at content/{{path}}
render path:
#!/usr/bin/env bash
set -euo pipefail
src='{{path}}'
src="${src#content/}"
if [[ "$src" == blog/* ]]; then
echo "render: found 'blog/' path, use 'just render-post'" >&2
exit 1
fi
# move to content folder so _quarto.yml is invoked
cd content
# clear .md file to prevent quarto from writing to another file
rm -f "${src%.qmd}.md"
quarto render "$src" -M engine:knitr
# Render all qmd files in content/{{path}}/ non-recursively (fails if path="blog/")
render-dir path:
#!/usr/bin/env bash
set -euo pipefail
target='{{path}}'
target="${target#content/}"
target="${target%/}"
if [ "$target" = "blog" ]; then
echo "render-dir: found 'blog/' path, use 'just render-post' instead" >&2
exit 1
fi
cd content
shopt -s nullglob
files=( "$target"/*.qmd )
if [ ${#files[@]} -eq 0 ]; then
echo "No .qmd files found under content/$target" >&2
exit 1
fi
for src in "${files[@]}"; do
rm -f "${src%.qmd}.md"
base=$(basename "$src")
dir=$(dirname "$src")
tmp_src="$dir/x${base}"
mv "$src" "$tmp_src"
trap 'mv "$tmp_src" "$src" 2>/dev/null' EXIT
quarto render "$tmp_src" -M engine:knitr
mv "${tmp_src%.qmd}.md" "${src%.qmd}.md"
mv "$tmp_src" "$src"
trap - EXIT
done
# Render all qmd files in content/ (except those in "blog/")
render-all:
#!/usr/bin/env bash
set -euo pipefail
cd content
shopt -s globstar nullglob
files=()
for f in **/*.qmd; do
[[ "$f" == blog/* ]] && continue
files+=( "$f" )
done
if [ ${#files[@]} -eq 0 ]; then
echo "No .qmd files to render" >&2
exit 1
fi
for src in "${files[@]}"; do
rm -f "${src%.qmd}.md"
base=$(basename "$src")
dir=$(dirname "$src")
tmp_src="$dir/x${base}"
mv "$src" "$tmp_src"
trap 'mv "$tmp_src" "$src" 2>/dev/null' EXIT
quarto render "$tmp_src" -M engine:knitr
mv "${tmp_src%.qmd}.md" "${src%.qmd}.md"
mv "$tmp_src" "$src"
trap - EXIT
done
# Generate Tailwind static/style.css from css/style.css
tailwind-build:
npm run tailwind:build
# Create a new documentation page at content/{{path}}
new-page path:
#!/usr/bin/env bash
set -euo pipefail
rel='{{path}}'
rel="${rel#content/}"
if [[ "$rel" == blog/* ]]; then
echo "new-page: found 'blog/' path, use 'just new-post' instead" >&2
exit 1
fi
file="content/$rel"
parent=$(dirname "$file")
if [ ! -d "$parent" ]; then
echo "new-page: section $parent does not exist, use 'just new-section' first" >&2
exit 1
fi
if [ -e "$file" ]; then
echo "File exists: $file" >&2
exit 1
fi
cat > "$file" <<-EOF
---
title:
description: ""
weight: 0
extra:
short_title:
---
EOF
echo "Created $file"
# Create a new documentation section at content/{{path}}/
new-section path:
#!/usr/bin/env bash
set -euo pipefail
dir="content/{{path}}"
dir="${dir%/}"
file="$dir/_index.qmd"
if [ -e "$file" ]; then
echo "File exists: $file" >&2
exit 1
fi
mkdir -p "$dir"
cat > "$file" <<-EOF
---
title:
description: ""
weight: 0
extra:
section_title:
---
EOF
echo "Created $file"
# Create a new blog post at content/blog/{{date}}-{{title}}/index.qmd
new-post title:
#!/usr/bin/env bash
set -euo pipefail
date=$(date +%Y-%m-%d)
dir="content/posts/${date}-{{title}}"
mkdir -p "$dir"
cat > "$dir/index.qmd" <<-EOF
---
title: {{title}}
date: "$date"
authors: []
taxonomies:
tags: []
---
EOF
echo "Created $dir/index.qmd"
# Render a blog post at content/blog/{{date}}-{{title}}/index.qmd
render-post title:
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
matches=( content/blog/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-{{title}} )
if [ ${#matches[@]} -eq 0 ]; then
echo "No post found matching *-{{title}}" >&2; exit 1
elif [ ${#matches[@]} -gt 1 ]; then
echo "Ambiguous title, matched: ${matches[*]}" >&2; exit 1
fi
quarto render "${matches[0]}/index.qmd" -M engine:knitr
# Run Tailwind watch and Zola live serve in parallel
dev:
npm run dev