From c13d147ac61b2cb44964e23892ebc06cadb5b42c Mon Sep 17 00:00:00 2001 From: Erick Ruiz de Chavez Date: Sat, 21 Dec 2024 12:08:08 -0500 Subject: [PATCH] Add gemini site builder --- .gitignore | 1 + Dockerfile.gemini | 6 ++++ Makefile | 17 ++++++---- _config.yml | 13 ++------ _includes/header.gmi | 1 + _includes/header.html | 31 +++++++++-------- _includes/links.gmi | 6 ++++ _layouts/article.gmi | 5 +++ _layouts/home.gmi | 5 +++ compose.yaml | 7 ++++ generate_capsule.sh | 77 +++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 138 insertions(+), 31 deletions(-) create mode 100644 Dockerfile.gemini create mode 100644 _includes/header.gmi create mode 100644 _includes/links.gmi create mode 100644 _layouts/article.gmi create mode 100644 _layouts/home.gmi create mode 100755 generate_capsule.sh diff --git a/.gitignore b/.gitignore index 8a3876e..5fb49ab 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .jekyll-metadata vendor _site +_capsule diff --git a/Dockerfile.gemini b/Dockerfile.gemini new file mode 100644 index 0000000..e77eb5c --- /dev/null +++ b/Dockerfile.gemini @@ -0,0 +1,6 @@ +FROM alpine:latest + +RUN apk add perl lowdown +WORKDIR /app +COPY generate_capsule.sh . +ENTRYPOINT [ "./generate_capsule.sh" ] diff --git a/Makefile b/Makefile index 5e47eea..5693257 100644 --- a/Makefile +++ b/Makefile @@ -12,23 +12,28 @@ stop: docker compose down clean: - \rm -rf .jekyll-cache _site + \rm -rf .jekyll-cache .saas-cache _site _capsule docker compose down -v logs: docker compose logs --follow --since 1m -build: - docker compose run --rm -e JEKYLL_ENV=production jekyll build +build: build-jekyll build-gemini + +build-gemini: + docker compose run --rm gemini + +build-jekyll: + docker compose run --rm jekyll build install: docker compose run --rm --entrypoint bash jekyll -c bundle add ${args} -make draft: +draft: docker compose run --rm jekyll draft ${args} -make publish: +publish: docker compose run --rm jekyll publish ${args} -make unpublish: +unpublish: docker compose run --rm jekyll unpublish ${args} diff --git a/_config.yml b/_config.yml index f42e72d..afbadbc 100644 --- a/_config.yml +++ b/_config.yml @@ -2,20 +2,11 @@ title: Erick Ruiz de Chavez author: Erick Ruiz de Chavez url: https://erickruizdechavez.com -site_links: - - title: 💼 LinkedIn - url: https://linkedin.com/in/erickruizdechavez - - title: 🐙 GitHub - url: https://github.com/eruizdechavez - - title: 🗣 Fediverse - url: https://erick.social/@erick - - title: 🦋 Bluesky - url: https://bsky.app/profile/erick.social - exclude: - - Dockerfile + - Dockerfile* - compose.yaml - Makefile + - generate_capsule.sh jekyll_compose: default_front_matter: diff --git a/_includes/header.gmi b/_includes/header.gmi new file mode 100644 index 0000000..62b342e --- /dev/null +++ b/_includes/header.gmi @@ -0,0 +1 @@ +# Erick Ruiz de Chavez diff --git a/_includes/header.html b/_includes/header.html index 739040d..cb2361e 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -5,18 +5,21 @@ alt="Generated Image of an anthropomorphic Panda wearing a sweater and jeans, sitting on a couch, using a laptop." /> - {%- if site.site_links -%} - - {%- endif -%} + diff --git a/_includes/links.gmi b/_includes/links.gmi new file mode 100644 index 0000000..b822652 --- /dev/null +++ b/_includes/links.gmi @@ -0,0 +1,6 @@ +## Links + +=> https://linkedin.com/in/erickruizdechavez LinkedIn +=> https://github.com/eruizdechavez GitHub +=> https://erick.social/@erick Fediverse +=> https://bsky.app/profile/erick.social Bluesky diff --git a/_layouts/article.gmi b/_layouts/article.gmi new file mode 100644 index 0000000..2a05df5 --- /dev/null +++ b/_layouts/article.gmi @@ -0,0 +1,5 @@ +%%header%% +=> index.gmi Front page +## %%title%% +%%body%% +%%links%% diff --git a/_layouts/home.gmi b/_layouts/home.gmi new file mode 100644 index 0000000..a40c528 --- /dev/null +++ b/_layouts/home.gmi @@ -0,0 +1,5 @@ +%%header%% +%%body%% +%%articles%% +%%drafts%% +%%links%% diff --git a/compose.yaml b/compose.yaml index f480fd8..cb0df71 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,3 +7,10 @@ services: - 35729:35729 volumes: - .:/app + gemini: + build: + context: . + dockerfile: Dockerfile.gemini + platform: linux/amd64 + volumes: + - .:/app diff --git a/generate_capsule.sh b/generate_capsule.sh new file mode 100755 index 0000000..4d870eb --- /dev/null +++ b/generate_capsule.sh @@ -0,0 +1,77 @@ +#!/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"