77 lines
2 KiB
Bash
Executable file
77 lines
2 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
mkdir -p _capsule
|
|
|
|
articles_list=""
|
|
|
|
header_body=$(cat _includes/header.gmi)
|
|
links_body=$(cat _includes/links.gmi)
|
|
|
|
for post in $(ls _posts/*.md); do
|
|
article_title=$(lowdown -X title $post)
|
|
article_date=$(lowdown -X date $post | awk '{print $1}')
|
|
article_body=$(lowdown -tgemini $post)
|
|
|
|
echo "Rendering post $article_title..."
|
|
|
|
gemfile=$post
|
|
gemfile=${gemfile/_posts/_capsule}
|
|
gemfile=${gemfile/.md/.gmi}
|
|
|
|
cat _layouts/article.gmi \
|
|
| perl -pe "s|%%header%%|${header_body}|" \
|
|
| perl -pe "s|%%links%%|${links_body}|" \
|
|
| perl -pe "s|%%title%%|${article_title}\n${article_date}\n|" \
|
|
| perl -pe "s|%%body%%|${article_body}|" \
|
|
> $gemfile
|
|
|
|
articles_list="$articles_list=> ${gemfile/_capsule\//} $article_date $article_title\n"
|
|
done
|
|
|
|
drafts_list=""
|
|
|
|
if [ "${GEMINI_ENV}" != 'production' ]; then
|
|
for post in $(ls _drafts/*.md); do
|
|
article_title=$(lowdown -X title $post)
|
|
article_body=$(lowdown -tgemini $post)
|
|
|
|
echo "Rendering draft $article_title..."
|
|
|
|
gemfile=$post
|
|
gemfile=${gemfile/_drafts/_capsule}
|
|
gemfile=${gemfile/.md/.gmi}
|
|
|
|
cat _layouts/article.gmi \
|
|
| perl -pe "s|%%header%%|${header_body}|" \
|
|
| perl -pe "s|%%links%%|${links_body}|" \
|
|
| perl -pe "s|%%title%%|${article_title}|" \
|
|
| perl -pe "s|%%body%%|${article_body}|" \
|
|
> $gemfile
|
|
|
|
drafts_list="$drafts_list=> ${gemfile/_capsule\//} $article_title\n"
|
|
done
|
|
fi
|
|
|
|
echo "Rendering index..."
|
|
|
|
index_body=$(lowdown -tgemini index.md)
|
|
|
|
articles=""
|
|
if [ ! -z "$articles_list" ]; then
|
|
articles="## Articles\n\n${articles_list}"
|
|
fi
|
|
|
|
drafts=""
|
|
if [ ! -z "$drafts_list" ]; then
|
|
drafts="## Drafts\n\n${drafts_list}"
|
|
fi
|
|
|
|
cat _layouts/home.gmi \
|
|
| perl -pe "s|%%header%%|${header_body}|" \
|
|
| perl -pe "s|%%links%%|${links_body}|" \
|
|
| perl -pe "s|%%body%%|${index_body}|" \
|
|
| perl -pe "s|%%articles%%|${articles}|" \
|
|
| perl -pe "s|%%drafts%%|${drafts}|" \
|
|
> _capsule/index.gmi
|
|
|
|
echo "Done"
|