Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions content/v2.3/introduction/building-a-static-site.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion content/v2.3/introduction/building-an-api.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down