Skip to content

Commit

Permalink
docs: Add github pages (#1273)
Browse files Browse the repository at this point in the history
* build(docs): Add github pages

* ci: only execute pages generation on pull requests and pushes to `main`

---------

Co-authored-by: Micah Halter <[email protected]>
  • Loading branch information
Kamilcuk and mehalter authored Nov 20, 2024
1 parent aaaa844 commit f5f3442
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
on:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- run: ./pages_create.sh
- uses: actions/upload-pages-artifact@v3
with:
path: pages
deploy:
needs: build
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
timeout-minutes: 1
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
environment:
name: github-pages # Deploy to the github-pages environment
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ luac.out

# MacOS
.DS_Store

pages
49 changes: 49 additions & 0 deletions pages_create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
set -xeuo pipefail
cd "$(dirname "$(readlink -f "$0")")"
mkdir -vp pages
repourl="${GITHUB_SERVER_URL:-https://github.com}/${GITHUB_REPOSITORY:-AstroNvim/astrocommunity}/tree/main"

{
# Generate pandoc metadata file.
cat <<EOF
---
title: "[AstroNvim Community Repository Pages]($repourl)"
date: $(LC_ALL=C date --utc)
abstract: |
Autogenerated site from README.md of all the plugins in astrocommunity repository.
---
EOF
} >pages/metadata.yaml

{
# Generate markdown of all descriptions.
prevsection=
shopt -s globstar
for readme in lua/astrocommunity/**/README.md; do
IFS=/ read -r _ _ section name _ <<<"$readme"
if [[ "$prevsection" != "$section" ]]; then
echo "# [$section]($repourl/lua/astrocommunity/$section)"
echo
prevsection=$section
fi
cat <<EOF
## [$section.$name]($repourl/lua/astrocommunity/$section/$name/init.lua)
\`\`\`
{ import = "astrocommunity.$section.$name" }
\`\`\`
EOF
# Indent markdown sections two sections up.
sed "s/^#/###/" <"$readme"
echo
done
} >pages/index.md

# Use pandoc to convert from markdown to html.
docker run -i --rm --mount type=bind,source="$PWD",target="$PWD",readonly --workdir "$PWD" pandoc/core:3.5 \
--from markdown --standalone --toc --toc-depth 2 --number-sections \
--metadata-file pages/metadata.yaml pages/index.md >pages/index.html

echo "SUCCESS - generated pages/index.html"

0 comments on commit f5f3442

Please sign in to comment.