Skip to content

Commit e296f04

Browse files
committed
Setup Parklife to build a static site
1 parent 4ab2107 commit e296f04

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
/tmp/
99

1010
/demo/app/assets/builds
11+
/demo/build
1112
/demo/storage/*.sqlite3
1213
/demo/tmp/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Parklife
2+
3+
on:
4+
# Run on every push.
5+
push:
6+
# Allow manually triggering a build.
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: ruby/setup-ruby@v1
20+
with:
21+
bundler-cache: true
22+
- uses: actions/configure-pages@v5
23+
id: pages
24+
25+
# Build with Parklife and use its GitHub Pages URL (either its custom
26+
# domain or username.github.io/repository).
27+
- run: bin/static-build --base "${{ steps.pages.outputs.base_url }}"
28+
29+
- name: Upload artifact
30+
uses: actions/upload-pages-artifact@v3
31+
if: github.ref == 'refs/heads/main' # Only upload on main branch.
32+
with:
33+
path: build/
34+
35+
deploy:
36+
environment:
37+
name: github-pages
38+
url: ${{ steps.deployment.outputs.page_url }}
39+
runs-on: ubuntu-latest
40+
needs: build
41+
if: github.ref == 'refs/heads/main' # Only deploy on main branch.
42+
concurrency:
43+
group: deploy
44+
cancel-in-progress: true
45+
steps:
46+
- name: Deploy to GitHub Pages
47+
id: deployment
48+
uses: actions/deploy-pages@v4

demo/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ gem "tzinfo-data", platforms: %i[windows jruby]
1515
gem "flowbite-components", path: "../.." # Load the gem files from the parent directory
1616
gem "tailwindcss-rails", "~> 4.3"
1717

18+
gem "parklife"
19+
1820
group :development, :test do
1921
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
2022
gem "debug", platforms: %i[mri windows], require: "debug/prelude"

demo/Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ GEM
168168
racc (~> 1.4)
169169
nokogiri (1.18.9-x86_64-linux-musl)
170170
racc (~> 1.4)
171+
parklife (0.7.0)
172+
nokogiri
173+
rack-test
174+
thor
171175
pp (0.6.2)
172176
prettyprint
173177
prettyprint (0.2.0)
@@ -284,6 +288,7 @@ DEPENDENCIES
284288
flowbite-components!
285289
listen
286290
lookbook (>= 2.3.11)
291+
parklife
287292
propshaft
288293
puma (>= 5.0)
289294
rails (~> 8.0.2)

demo/Parkfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'parklife/rails'
2+
require_relative 'config/environment'
3+
4+
Parklife.application.configure do |config|
5+
# Serve trailing slash-less URLs from GitHub Pages.
6+
config.nested_index = false
7+
8+
# See configuration options here:
9+
# https://github.com/benpickles/parklife#configuration
10+
end
11+
12+
Parklife.application.routes do
13+
root crawl: true
14+
15+
# Add further paths not discovered by crawling from the root - Parklife's
16+
# Rails integration lets you use the app's route helpers:
17+
#
18+
# get hidden_pages_path, crawl: true
19+
# get feed_path(format: :atom)
20+
21+
# Services typically allow a custom 404 page.
22+
# get '/404.html'
23+
end

demo/bin/static-build

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env sh
2+
3+
set -eu
4+
5+
# Run the app in production mode to ensure correct asset URLs are generated etc.
6+
export RAILS_ENV=production
7+
export SECRET_KEY_BASE=dummy
8+
9+
# If your Rails app uses ActiveRecord then this is a good point to create and
10+
# seed the database from db/seeds.rb.
11+
# bundle exec rails db:setup
12+
13+
# Generate production-optimised assets with Sprockets and friends. This must be
14+
# done before generating the Parklife build as Rails will blow up if it detects
15+
# missing assets in production.
16+
bundle exec rails assets:precompile
17+
18+
# Build with Parklife - and forward arguments sent to this script.
19+
bundle exec parklife build "$@"
20+
21+
# Copy all public resources to ./build.
22+
if [ -d public ]; then
23+
cp -R public/* build
24+
fi
25+
26+
# List all files in the build (useful for debugging).
27+
find build -type f | sort

0 commit comments

Comments
 (0)