百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

parklife

> 后端框架
开源

将 Rack 应用程序 (Rails/Sinatra 等) 渲染为静态构建,以便可以通过 Netlify、Now, GitHub Pages、S3 或任何其他 Web 服务器进行服务

301 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

将 Rack 应用程序 (Rails/Sinatra 等) 渲染为静态构建,以便可以通过 Netlify、Now, GitHub Pages、S3 或任何其他 Web 服务器进行服务

Parklife

Parklife is a Ruby library to render a Rack app (Rails/Sinatra/etc) to a static site so it can be served by Netlify, Now, GitHub Pages, S3, or another static server.

Getting started

Add Parklife to your application's Gemfile and run bundle install.

ruby
gem 'parklife'

Now generate a Parkfile configuration file and build script. Include some Rails- or Sinatra-specific settings by passing --rails or --sinatra, create a GitHub Actions workflow to generate your Parklife build and deploy it to GitHub Pages by passing --github-pages.

$ bundle exec parklife init

How to use Parklife

[!NOTE] See the parklife-rails repository for how to use Parklife with Rails.

Parklife is configured with a file called Parkfile in the root of your project, here's an example Parkfile for an imaginary Rack app:

ruby
# Assuming your Rack app lives in ./app.rb:
require_relative 'app'

Parkfile.application.routes do
  # Start from the homepage and crawl all links.
  root crawl: true

  # Some extra paths that aren't discovered while crawling.
  get '/feed.atom'
  get '/sitemap.xml'

  # A couple more hidden pages.
  get '/easter_egg', crawl: true

  # Services typically allow a custom 404 page.
  get '/404.html'
end

Listing the routes included in the above Parklife application with parklife routes would output the following:

$ bundle exec parklife routes
/             crawl=true
/feed.atom
/sitemap.xml
/easter_egg   crawl=true
/404.html

Now you can run parklife build which will fetch all the routes and save them to the build directory ready to be served as a static site. Inspecting the build directory might look like this:

$ find build -type f
build/404.html
build/about/index.html
build/blog/index.html
build/blog/2019/03/07/developers-developers-developers/index.html
build/blog/2019/04/21/modern-life-is-rubbish/index.html
build/blog/2019/05/15/introducing-parklife/index.html
build/easter_egg/index.html
build/easter_egg/surprise/index.html
build/index.html
build/location/index.html
build/feed.atom
build/sitemap.xml

Parklife doesn't know about assets (images, CSS, etc) so you likely also need to generate those and copy them to the build directory.

More examples

Take a look at the parklife-rails example app, the parklife-sinatra example app, and the Rack example in this repository.

Configuration

Linking to full URLs

Sometimes you need to point to a link's full URL - maybe for a feed or a social tag URL. You can tell Parklife to make its mock requests with a particular protocol / host by setting its base so Rails *_url helpers will point to the correct host:

ruby
Parklife.application.config.base = 'https://foo.example.com'

The base URL can also be passed at build-time which will override the Parkfile setting:

$ bundle exec parklife build --base https://benpickles.github.io/parklife

Dealing with trailing slashes (turning off nested index.html)

By default Parklife stores files in an index.html file nested in directory with the same name as the path - so the route /my/nested/route is stored in /my/nested/route/index.html. This is to make sure links within the app work without modification making it easier for any static server to host the build.

However, it's possible to turn this off so that /my/nested/route is stored in /my/nested/route.html. This allows you to serve trailing slash-less URLs with GitHub Pages or with Netlify by using their Pretty URLs feature or with some custom nginx config.

ruby
Parklife.application.config.nested_index = false

Changing the build output directory

The build directory's contents are removed before each build. Defaults to build.

ruby
Parklife.application.config.build_dir = 'my/build/dir'

Handling redirects (301/302 responses)

By default if Parklife encounters a 301/302 response when fetching a route it will raise an exception which stops the build (the :error setting).

Possible values are:

  • :error (default) - raise an exception which stops the build.
  • :skip - do not save the response, continue processing.
  • :warn - output a message to stderr, do not save the response, continue processing.
ruby
Parklife.application.config.on_301 = :warn
Parklife.application.config.on_302 = :warn

Handling a 404

By default if Parklife encounters a 404 response when fetching a route it will raise an exception which stops the build (the :error setting).

Possible values are:

  • :error (default) - raise an exception which stops the build.
  • :skip - do not save the response, continue processing.
  • :warn - output a message to stderr, do not save the response, continue processing.
ruby
Parklife.application.config.on_404 = :warn

Setting the Rack app

If you're not using the Rails configuration you'll need to define this yourself, see the examples.

ruby
Parklife.application.config.app

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Parklife project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Issues· 4 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyjamstackrailsrubystatic-site

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架