diff --git a/.github/scripts/update-readable-css.sh b/.github/scripts/update-readable-css.sh new file mode 100755 index 0000000..4efb067 --- /dev/null +++ b/.github/scripts/update-readable-css.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -o errexit +set -o pipefail +set -o nounset + +# Query the codeberg.org API (see +# https://codeberg.org/api/swagger#/repository/repoListReleases +# ) and use jq to get the tag name of the +# latest release (i.e. the first element of the +# array in the JSON output, that is not a +# prerelease). +# The '-r' option will give us "raw" output, +# i.e. without surrounding double-quotes. +# We use 'map' and 'select' in combination, +# because jq won't return a list otherwise. +# Only using 'select' returns just the matching +# elements, which is not a valid json that we +# can process further. +TAG_VERSION=$(curl -s \ + -H 'accept: application/json' \ + https://codeberg.org/api/v1/repos/Freedom-to-Write/readable.css/releases \ + | jq -r '.|map(select(.prerelease==false))[0].tag_name') + +echo "Latest tag: ${TAG_VERSION}" + +# Get the current version. +# The '-o' option will only output the match grep found. +# We look for readable.min.css and a set of three numbers seperated by dots, +# i.e. a semantic version. readable.min.css is used to make sure that we match +# the right numbers in the file. +# We use sed to get rid of the readable.min.css prefix. +CURRENT_VERSION=$(grep -o \ + 'readable.min.css?v=v[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+' \ + layouts/partials/head.html \ + | sed 's/readable.min.css?v=//') +echo "Current version: ${CURRENT_VERSION}" + +if [[ $TAG_VERSION == $CURRENT_VERSION ]] +then + echo "Nothing to do. The current version is already up to date." +else + curl -s "https://codeberg.org/Freedom-to-Write/readable.css/raw/tag/${TAG_VERSION}/readable.css" > static/css/readable.css + curl -s "https://codeberg.org/Freedom-to-Write/readable.css/raw/tag/${TAG_VERSION}/readable.min.css" > static/css/readable.min.css + sed -i "s/readable.min.css?v=${CURRENT_VERSION}/readable.min.css?v=${TAG_VERSION}/" layouts/partials/head.html +fi + +# Add the latest tag version to the workflow environment, so we can access +# it in later steps. +echo "READABLE_CSS_TAG=${TAG_VERSION}" >> "$GITHUB_ENV" diff --git a/.github/workflows/update-readable-css.yml b/.github/workflows/update-readable-css.yml new file mode 100644 index 0000000..cab3bf0 --- /dev/null +++ b/.github/workflows/update-readable-css.yml @@ -0,0 +1,42 @@ +name: update-readable-css + +on: + schedule: + # Every day at 3:28. + - cron: '28 3 * * *' + +jobs: + update-readable-css: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Download CSS files for latest tag + run: .github/scripts/update-readable-css.sh + - name: Create pull request if files have changed + # https://github.com/marketplace/actions/create-pull-request + uses: peter-evans/create-pull-request@v5 + with: + # First line is the commit subject as always. The rest goes + # into the body. + commit-message: | + Update readable.css to ${{ env.READABLE_CSS_TAG }} + + See the changelog here: + + https://codeberg.org/Freedom-to-Write/readable.css/src/tag/${{ env.READABLE_CSS_TAG }}/CHANGELOG.md + branch: update-readable-css + delete-branch: true + # Use 'GitHub' both times. + # This is already the default for committer, but the author defaults + # to the user who triggered the workflow run, which is the owner of + # the repository. + # We use the same value for the author to indicate that the + # commit was created by a bot. + committer: GitHub + author: GitHub + title: Update readable.css to ${{ env.READABLE_CSS_TAG }} + body: | + See the changelog here: + + https://codeberg.org/Freedom-to-Write/readable.css/src/tag/${{ env.READABLE_CSS_TAG }}/CHANGELOG.md + labels: update-readable-css diff --git a/README.md b/README.md index 010fb78..c7a9a7f 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Readable is a theme for the static-site generator [Hugo](https://gohugo.io/) usi Shoutout to [Benjamin Hollon](https://benjaminhollon.com/) for his amazing work building this CSS framework and making it so simple to use. -**This is a fork of the project [hugo-theme-readable](https://codeberg.org/Freedom-to-Write/hugo-theme-readable)** -https://codeberg.org/Freedom-to-Write/hugo-theme-readable +**This is a fork of the project [hugo-theme-readable](https://github.com/cjtheham/hugo-theme-readable)** + ![demo image](/docs/demo_image.png) ## Installation @@ -26,7 +26,7 @@ Freedom to Write has provided some awesome guides on writing HTML that works aut ## The rest -As mentioned, This is a fork of [hugo-theme-readable](https://codeberg.org/Freedom-to-Write/hugo-theme-readable), and will continue to cherry-pick commits from the upstream. I also commit to pushing certain things I think work with the upstream project, to the upstream. +As mentioned, This is a fork of [hugo-theme-readable](https://github.com/cjtheham/hugo-theme-readable), and will continue to cherry-pick commits from the upstream. I also commit to pushing certain things I think work with the upstream project, to the upstream. This is very much a opinonized theme for my site, and you can use it for yours, I however ask that you credit me as I credit Benjamin, and CJ for the work done on this project. @@ -35,4 +35,4 @@ Without Benjamin Hollon or C.J this theme wouldn't exist. Projects used: - [hugo](https://gohugo.io/) created by [Bep](https://bep.is/en/) - [Readable.css](https://codeberg.org/Freedom-to-Write/readable.css) created by [Benjamin Hollon](https://benjaminhollon.com/) -- [Hugo Readable Theme](https://codeberg.org/Freedom-to-Write/hugo-theme-readable) created by [C.J](https://github.com/cjtheham) +- [Hugo Readable Theme](https://github.com/cjtheham/hugo-theme-readable) created by [C.J](https://github.com/cjtheham) \ No newline at end of file