`generate_page_path` lifecycle
- Dominant language
- Elixir
- Stars
- 1.3k
- Forks
- 134
- PR merge metrics
- No merged PRs in 30d
Description
Add a Lifecycle Stage named `:generate_page_path` to allow generating `page.path` with custom rules.
Users can already input a page's path at https://github.com/BeaconCMS/beacon/blob/7790eb72769a026c0bdfc3167aab394a9b73ce91/lib/beacon_web/live/admin/page_live/page_editor_live.html.heex#L22
but inputting long urls manually is not viable for eg: "/blog/2023/01/31/looking-back-at-the-first-year-of-creating-the-dockyard-academy". It's better to provide a [button](https://github.com/BeaconCMS/beacon_live_admin/issues/29) to generate such paths automatically, which would call `Beacon.Lifecycle.generate_path(page)` which has a default implementation, similar to how it's done here https://github.com/BeaconCMS/beacon/blob/7790eb72769a026c0bdfc3167aab394a9b73ce91/lib/beacon/config.ex#L140
A good start point for that function is:
```elixir
def generate_path(%Page{title: title}) when is_binary(title) do
title
|> String.downcase()
|> remove_non_printable()
|> remove_special_characters()
|> remove_leading_trailing_delimiter()
end
def generate_path(_page), do: ""
defp remove_non_printable(field), do: String.replace(field, ~r/[^\x00-\x7f]+/, "")
defp remove_special_characters(field), do: String.replace(field, ~r/[^\w]+/, "-")
defp remove_special_characters(field), do: String.replace(field, ~r/[^\w]+/, "-")
```
Note that button should be hidden if `page.status == :published`
Contributor guide
Research direction
Start with Beacon.Lifecycle.generate_path(page), the lifecycle implementation around lib/beacon/config.ex, and the page editor template linked in the issue. Trace how lifecycle stages are configured and how the editor reads page.status; done means custom path generation is available, the editor can request it, and the button is hidden for published pages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- full-stack
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100