From f4a317b7f8f78b68cecd50f16b79ac2eb331ed0f Mon Sep 17 00:00:00 2001 From: Joshua Priddle Date: Sat, 2 Mar 2024 23:30:03 -0500 Subject: [PATCH] Try pagination - Adds pagination with jekyll-paginate-v3 - Switch to a custom CI builder - Add a monkey patch to hide some posts from the paginator --- .github/workflows/jekyll.yml | 95 +++++++++++++++++++----------------- Gemfile | 1 + Gemfile.lock | 7 ++- _config.yml | 13 +++-- _includes/head.html | 2 +- _includes/paginator.html | 32 ++++++------ _pages/index.html | 10 ++-- _plugins/custom_paginator.rb | 12 +++++ stylesheets/_layout.scss | 4 ++ 9 files changed, 100 insertions(+), 76 deletions(-) create mode 100644 _plugins/custom_paginator.rb diff --git a/.github/workflows/jekyll.yml b/.github/workflows/jekyll.yml index cb890b97..1ffb8343 100644 --- a/.github/workflows/jekyll.yml +++ b/.github/workflows/jekyll.yml @@ -1,56 +1,63 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# Sample workflow for building and deploying a Jekyll site to GitHub Pages name: Deploy Jekyll site to Pages -on: - # Runs on pushes targeting the default branch - push: - branches: ["gh-pages"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: group: "pages" cancel-in-progress: false +on: + push: + branches: + - master + +env: + RUBY_VERSION: 3.2 + +# Define a job named `build-and-publish` in your workflow. jobs: - # Build job - build: - runs-on: ubuntu-latest + build-and-publish: + runs-on: ubuntu-latest # This job uses a GitHub-hosted runner. + + # env: + # BUNDLE_PATH: "vendor/bundle" + # BUNDLE_JOBS: 4 + # BUNDLE_RETRY: 3 + + # Skip builds with "[ci skip]" in the commit + if: "!contains(github.event.head_commit.message, '[ci skip]')" + steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup Pages - uses: actions/configure-pages@v3 - - name: Build with Jekyll - uses: actions/jekyll-build-pages@v1 + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 with: - source: ./ - destination: ./_site - - name: Upload artifact - uses: actions/upload-pages-artifact@v1 - - # Deployment job - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: + ruby-version: ${{ env.RUBY_VERSION }} + bundler-cache: true + - name: Clone target branch + run: | + REMOTE_BRANCH="${REMOTE_BRANCH:-gh-pages}" + REMOTE_REPO="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" + + echo "Publishing to ${GITHUB_REPOSITORY} on branch ${REMOTE_BRANCH}" + rm -rf _site/ + git clone --depth=1 --branch="${REMOTE_BRANCH}" --single-branch --no-checkout \ + "${REMOTE_REPO}" _site/ + - name: Build site + run: bundle exec jekyll build --destination _site --verbose --trace + env: + # For jekyll-github-metadata + JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v1 + run: | + SOURCE_COMMIT="$(git log -1 --pretty="%an: %B" "$GITHUB_SHA")" + pushd _site &>/dev/null + : > .nojekyll + + git add --all + git -c user.name="${GITHUB_ACTOR}" -c user.email="${GITHUB_ACTOR}@users.noreply.github.com" \ + commit --quiet \ + --message "Deploy site from ${GITHUB_SHA}" \ + --message "$SOURCE_COMMIT" + git push + + popd &>/dev/null diff --git a/Gemfile b/Gemfile index 804d5384..21514dee 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ gem "jekyll", "~> 4.3.2" gem "jekyll-feed" gem "jekyll-gist" gem "jekyll-github-metadata" +gem "jekyll-paginate-v2" gem "jekyll-redirect-from" gem "jekyll-sitemap" gem "jemoji" diff --git a/Gemfile.lock b/Gemfile.lock index 6f781beb..015f4420 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,6 +52,8 @@ GEM jekyll-github-metadata (2.15.0) jekyll (>= 3.4, < 5.0) octokit (~> 4.0, != 4.4.0) + jekyll-paginate-v2 (3.0.0) + jekyll (>= 3.0, < 5.0) jekyll-redirect-from (0.16.0) jekyll (>= 3.3, < 5.0) jekyll-sass-converter (3.0.0) @@ -74,9 +76,9 @@ GEM rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.4.0) minitest (5.19.0) - nokogiri (1.16.2-arm64-darwin) + nokogiri (1.15.5-arm64-darwin) racc (~> 1.4) - nokogiri (1.16.2-x86_64-linux) + nokogiri (1.15.5-x86_64-linux) racc (~> 1.4) octokit (4.25.1) faraday (>= 1, < 3) @@ -115,6 +117,7 @@ DEPENDENCIES jekyll-feed jekyll-gist jekyll-github-metadata + jekyll-paginate-v2 jekyll-redirect-from jekyll-sitemap jemoji diff --git a/_config.yml b/_config.yml index b3cc1ec7..38ad7f3b 100644 --- a/_config.yml +++ b/_config.yml @@ -25,11 +25,13 @@ timezone: 'America/New_York' # Permalink settings permalink: '/:year/:title/' -# Pagination settings Tried enabling this on 2022-01-24 and found it requires -# moving from post.html => post/index.html for permalinks. Not sure I want to -# just yet -# paginate: 10 -# paginate_path: 'browse/page:num' +# Pagination settings +pagination: + enabled: true + per_page: 10 + permalink: '/page:num/' + title: ':title - page :num' + sort_reverse: true # Files to exclude exclude: @@ -54,6 +56,7 @@ plugins: - jekyll-feed - jekyll-gist - jekyll-github-metadata + - jekyll-paginate-v2 - jekyll-redirect-from - jekyll-sitemap - jemoji diff --git a/_includes/head.html b/_includes/head.html index d5703529..ef41aba3 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -1,5 +1,5 @@ {%- assign asset_hash = site.time | date: "%s" -%} -{%- if page.title -%} +{%- if page.title and (page.title != site.title) -%} {%- assign page_title = page.title | append: " --- " | append: site.title | smartify -%} {%- else -%} {%- assign page_title = site.title | smartify -%} diff --git a/_includes/paginator.html b/_includes/paginator.html index 9793c2ab..b623fafc 100644 --- a/_includes/paginator.html +++ b/_includes/paginator.html @@ -1,17 +1,15 @@ -{% if site.paginate %} -
- -
-{%- endif %} +{% if paginator.total_pages > 1 %} +
+ {%- if paginator.previous_page %} + ← Previous :: + {%- endif %} + + {%- if paginator.page > 1 %} + Page {{ paginator.page }} + {%- endif %} + + {%- if paginator.next_page %} + {% unless paginator.page == 1 %}::{% endunless %} Next → + {%- endif %} +
+{% endif %} diff --git a/_pages/index.html b/_pages/index.html index dc94a28c..f0852d1a 100644 --- a/_pages/index.html +++ b/_pages/index.html @@ -1,16 +1,12 @@ --- layout: default permalink: / +pagination: + enabled: true ---
- {%- if site.paginate -%} - {%- assign posts = paginator.posts -%} - {%- else -%} - {%- assign posts = site.posts -%} - {%- endif -%} - - {%- assign posts = posts | where_exp: "post", "post.category != 'archive'" | where_exp: "post", "post.category != 'vault'" | where_exp: "post", "post.archive != true" -%} + {%- assign posts = paginator.posts %} {%- for post in posts -%} {% include post.html homepage=true post=post %} diff --git a/_plugins/custom_paginator.rb b/_plugins/custom_paginator.rb new file mode 100644 index 00000000..676cc929 --- /dev/null +++ b/_plugins/custom_paginator.rb @@ -0,0 +1,12 @@ +require "jekyll-paginate-v2" + +# Exclude posts with categories archive, vault, or an archive attribute set +Jekyll::PaginateV2::Generator::PaginationModel.prepend Module.new { + def paginate(template, config, site_title, all_posts, all_tags, all_categories, all_locales) + all_posts.reject! do |post| + %w(archive vault).include?(post["category"].to_s) || post["archive"] + end + + super + end +} diff --git a/stylesheets/_layout.scss b/stylesheets/_layout.scss index ea4d806c..636dbfe9 100644 --- a/stylesheets/_layout.scss +++ b/stylesheets/_layout.scss @@ -201,3 +201,7 @@ padding-left: calc(#{$spacing-unit} / 2); } } + +.pager { + text-align: center; +}