From 6fcf79d9ad137d762110606aac820c9b0de31b0a Mon Sep 17 00:00:00 2001 From: Sven Schwyn Date: Fri, 23 May 2025 21:26:48 +0200 Subject: [PATCH] Add guide for building a static site --- .../introduction/building-a-static-site.md | 50 +++++++++++++++++++ content/v2.3/introduction/building-an-api.md | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 content/v2.3/introduction/building-a-static-site.md diff --git a/content/v2.3/introduction/building-a-static-site.md b/content/v2.3/introduction/building-a-static-site.md new file mode 100644 index 00000000..f6d99d49 --- /dev/null +++ b/content/v2.3/introduction/building-a-static-site.md @@ -0,0 +1,50 @@ +--- +title: "Building a static site" +order: 30 +--- + +Once we've [created our web app](/v2.2/introduction/building-a-web-app/), it's very easy to convert it fully or partially into a static site – with a little help of the [Parklife gem](https://rubygems.org/gems/parklife) which renders any Rack app into a build of static pages. + +## Install Parklife + +Add Parklife to the Gemfile and install it. + +``` +bundle add parklife +bundle exec parklife init +``` + +## Configure Parklife + +The generated Parkfile does not work for Hanami, here's a more suitable blueprint which: + +* Boots the Hanami app. +* Crawls the root page and all pages linked from there recursively. +* Gets the explicitly declared page /errors/not-found which is not linked from anywhere. +* Raises an error if it encounters a dead local link. + +``` +require "hanami/boot" + +Parklife.application.configure do |config| + config.app = Hanami.app + config.on_404 = :error +end + +Parklife.application.routes do + root crawl: true + + get '/errors/not-found' +end +``` + +Please refer to the [Parklife config documentation](https://parklife.dev/config) for more. + +## Build + +To build the static pages into the `/build` directory: + +``` +bundle exec hanami assets compile +bin/static-build +``` diff --git a/content/v2.3/introduction/building-an-api.md b/content/v2.3/introduction/building-an-api.md index 7b223975..64f23a1c 100644 --- a/content/v2.3/introduction/building-an-api.md +++ b/content/v2.3/introduction/building-an-api.md @@ -1,6 +1,6 @@ --- title: "Building an API" -order: 30 +order: 40 --- Now that we've [created our app](/v2.3/introduction/getting-started/), let's turn it into an API.