Skip to content

Commit 87ce23d

Browse files
committed
Pass title explicitly to md2html
This avoids extracting it multiple times for the same file.
1 parent af39600 commit 87ce23d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pbb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ extracttitle() {
167167
# Convert a markdown file to HTML and store it in the docs directory
168168
md2html() {
169169
local file=$1
170+
local title=$2
170171
[[ $file == *.md ]] || die "not a markdown file: $file"
171172

172173
echo "Building $file..." >&2
@@ -181,7 +182,7 @@ md2html() {
181182
"--lua-filter=dotgraph.lua"
182183
"--metadata=document-css:true"
183184
"--metadata=lang:$(getlang)"
184-
"--metadata=title:$(extracttitle "$file" | pandoc --to plain)"
185+
"--metadata=title:$(pandoc --to plain <<< "$title")"
185186
"--metadata-file=.metadata.yml"
186187
"--output=docs/${file/%.md/.html}"
187188
"--standalone"
@@ -287,17 +288,17 @@ build() {
287288

288289
# Build index file and convert posts
289290
{
290-
printf '%s\n' "# All posts"
291-
local f
291+
local f title
292292
for f in ????-??-??-*.md; do
293+
title=$(extracttitle "$f")
293294
printf -- ':::\n[%s](%s)\n:::index-title\n\n:::\n%s\n:::index-date\n\n' \
294-
"$(extracttitle "$f")" "${f/%.md/.html}" "${f:0:10}"
295-
md2html "$f"
295+
"$title" "${f/%.md/.html}" "${f:0:10}"
296+
md2html "$f" "$title"
296297
done | tac
297298
} > index.md
298299

299300
# Convert index file
300-
md2html index.md
301+
md2html index.md 'All posts'
301302

302303
rm index.md
303304
cp "$cssfile" docs
@@ -330,7 +331,7 @@ serve() {
330331
case $fname in
331332
./*.md)
332333
echo "Rebuilding $fname..."
333-
md2html "${fname#./}"
334+
md2html "${fname#./}" "$(extracttitle "$fname")"
334335
;;
335336
./images/*)
336337
echo "Copying $fname to images..."

0 commit comments

Comments
 (0)