Routes
Perron uses standard Rails routing, allowing the use of familiar route helpers.
The config/routes.rb
could look like this:
Rails.application.routes.draw do
resources :posts, module: :content, only: %w[index show]
resources :pages, module: :content, only: %w[show]
root to: "content/pages#root"
end
Route configuraton
In config/initializers/perron.rb
you can change your site's route configuraton:
Perron.configure do |config|
# …
config.default_url_options = {host: "perron.railsdesigner.com", protocol: "https", trailing_slash: true}
# …
end
For a typical “clean slug”, the filename without extensions serves as the id
parameter.
<%# For app/content/posts/announcement.md %>
<%= link_to "Announcment", post_path("announcement") %> # => <a href="/posts/announcement/">Announcment</a>
Include extension
By default Perron creates clean slugs, like /about/
. To create pages with specific extensions directly (e.g., pricing.html
), the route must first be configured to treat the entire filename as the ID. In config/routes.rb
, modify the generated resources
line by adding a constraints
option:
# Change from…
resources :pages, module: :content, only: %w[show]
# …to…
resources :pages, module: :content, only: %w[show], constraints: { id: /[^\/]+/ }
With this change, a content file named app/content/pages/pricing.html.erb
can be linked like so:
<%= link_to "View Pricing", page_path("pricing", format: :html) %> # => <a href="/pricing.html">View Pricing</a>
Perron will then create pricing.html
upon build.