Static site generator

demindiro - 2 months ago (last modified 2 months ago)

I use this script to generate my personal website (https://www.demindiro.com/). It assumes you use Markdown files but it should be easy to adapt to other formats.

#!/usr/bin/env bash

for file in `find . -name '*.md'`; do
    output=${file::-3}.html
    if [ -z "$REBUILD" ] && [ -e "../$output" ] && [ "../$output" -nt "$file" ]
    then
        echo "Skipping $file"
        continue
    fi
    mkdir -p ../$(dirname $output)
    echo Generating $output from $file
    title=$(sed -nr 's:^# (.*):\1:p' $file | head -n 1)
    if [ -z "$title" ]
    then
        title="Demindiro"
    fi
    cat << EOF > ../$output
<!DOCTYPE html>
<head>
<title>$title</title>
`cat head.html`
</head>
<body>
`cat navigation.html`
<main>
`pandoc $file`
</main>
<footer>
    <span>The content on this page is licensed under the CC BY-ND 4.0</span>
    <a style="float:right" href="/md/$file">Source</a>
</footer>
</body>
EOF
done;

Captcha: 4 * 2 + 13 =

(I already have an account)

hmumfdtuagqo - 2 months ago | thread

A <body> followed by </menu>? What‘s up with that?

reply
demindiro - 2 months ago | thread parent

That is a mistake. It seems I forgot to delete it with the rest of the <menu> element.

I used to have a <menu> there with some silly buttons but since all major browsers removed support by now I also removed it.

reply
kifax11520 - 2 months ago | thread

cool

reply
q_q - 2 months ago | thread

line 4: -3: substring expression < 0

noob here, why i got this? i thought it's only remove '.md' from fileName.md

reply
demindiro - 2 months ago | thread parent

How are you running it? That error seems to only occur if you use `sh` instead of `bash`.

reply