Skip to content

Commit

Permalink
Switch to shifting heading levels
Browse files Browse the repository at this point in the history
Fewer title extractions required
  • Loading branch information
bewuethr committed Aug 8, 2023
1 parent aa72aa8 commit 2e9b786
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions assets/pbb.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ div.index-title p {
margin: initial;
}

h1.title {
font-size: 2.2em;
}

a {
outline: none;
-wekbit-tap-highlight-color: transparent;
Expand Down
18 changes: 8 additions & 10 deletions pbb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ extracttitle() {
# Convert a markdown file to HTML and store it in the docs directory
md2html() {
local file=$1
local title=$2
[[ $file == *.md ]] || die "not a markdown file: $file"

echo "Building $file..." >&2
Expand All @@ -181,9 +180,9 @@ md2html() {
"--lua-filter=dotgraph.lua"
"--metadata=document-css:true"
"--metadata=lang:$(getlang)"
"--metadata=title:$(pandoc --to plain <<< "$title")"
"--metadata-file=.metadata.yml"
"--output=docs/${file/%.md/.html}"
"--shift-heading-level-by=-1"
"--standalone"
"--table-of-contents"
"--to=html"
Expand Down Expand Up @@ -214,8 +213,7 @@ md2html() {
args+=("--metadata=pagetitle:$(getconfvalue 'blogtitle')")
fi

# Delete level 1 heading because it's already printed as the title
pandoc "${args[@]}" <(sed '0,/^# /{/^# /d}' "$file") || die "error while converting $file"
pandoc "${args[@]}" "$file" || die "error while converting $file"
}

# Empty docs and copy images directory
Expand Down Expand Up @@ -288,17 +286,17 @@ build() {

# Build index file and convert posts
{
local f title
printf '%s\n' '# All posts'
local f
for f in ????-??-??-*.md; do
title=$(extracttitle "$f")
printf -- ':::\n[%s](%s)\n:::index-title\n\n:::\n%s\n:::index-date\n\n' \
"$title" "${f/%.md/.html}" "${f:0:10}"
md2html "$f" "$title"
"$(extracttitle "$f")" "${f/%.md/.html}" "${f:0:10}"
md2html "$f"
done | tac
} > index.md

# Convert index file
md2html index.md 'All posts'
md2html index.md

rm index.md
cp "$cssfile" docs
Expand Down Expand Up @@ -331,7 +329,7 @@ serve() {
case $fname in
./*.md)
echo "Rebuilding $fname..."
md2html "${fname#./}" "$(extracttitle "$fname")"
md2html "${fname#./}"
;;
./images/*)
echo "Copying $fname to images..."
Expand Down

0 comments on commit 2e9b786

Please sign in to comment.