Skip to content

Commit

Permalink
Try pagination
Browse files Browse the repository at this point in the history
- Adds pagination with jekyll-paginate-v3
- Switch to a custom CI builder
- Add a monkey patch to hide some posts from the paginator
  • Loading branch information
itspriddle committed Mar 3, 2024
1 parent 4159e23 commit f4a317b
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 76 deletions.
95 changes: 51 additions & 44 deletions .github/workflows/jekyll.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -115,6 +117,7 @@ DEPENDENCIES
jekyll-feed
jekyll-gist
jekyll-github-metadata
jekyll-paginate-v2
jekyll-redirect-from
jekyll-sitemap
jemoji
Expand Down
13 changes: 8 additions & 5 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -54,6 +56,7 @@ plugins:
- jekyll-feed
- jekyll-gist
- jekyll-github-metadata
- jekyll-paginate-v2
- jekyll-redirect-from
- jekyll-sitemap
- jemoji
Expand Down
2 changes: 1 addition & 1 deletion _includes/head.html
Original file line number Diff line number Diff line change
@@ -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 -%}
Expand Down
32 changes: 15 additions & 17 deletions _includes/paginator.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{% if site.paginate %}
<div class="pager">
<ul class="pagination">
{%- if paginator.previous_page %}
<li><a href="{{ paginator.previous_page_path | relative_url }}" class="previous-page">{{ paginator.previous_page }}</a></li>
{%- else %}
<li><div class="pager-edge"></div></li>
{%- endif %}
<li><div class="current-page">{{ paginator.page }}</div></li>
{%- if paginator.next_page %}
<li><a href="{{ paginator.next_page_path | relative_url }}" class="next-page">{{ paginator.next_page }}</a></li>
{%- else %}
<li><div class="pager-edge"></div></li>
{%- endif %}
</ul>
</div>
{%- endif %}
{% if paginator.total_pages > 1 %}
<div class="pager">
{%- if paginator.previous_page %}
<a href="{{ paginator.previous_page_path | relative_url }}" class="previous-page">&larr; Previous</a> ::
{%- endif %}

{%- if paginator.page > 1 %}
<span class="current-page">Page {{ paginator.page }}</span>
{%- endif %}

{%- if paginator.next_page %}
{% unless paginator.page == 1 %}::{% endunless %} <a href="{{ paginator.next_page_path | relative_url }}" class="next-page">Next &rarr;</a>
{%- endif %}
</div>
{% endif %}
10 changes: 3 additions & 7 deletions _pages/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
---
layout: default
permalink: /
pagination:
enabled: true
---

<div class="home">
{%- 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 %}
Expand Down
12 changes: 12 additions & 0 deletions _plugins/custom_paginator.rb
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions stylesheets/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,7 @@
padding-left: calc(#{$spacing-unit} / 2);
}
}

.pager {
text-align: center;
}

0 comments on commit f4a317b

Please sign in to comment.