Packages
phoenix_kit
1.7.175
1.7.207
1.7.206
1.7.205
1.7.204
1.7.203
1.7.202
1.7.201
1.7.200
1.7.199
1.7.198
1.7.197
1.7.196
1.7.194
1.7.193
1.7.192
1.7.191
1.7.190
1.7.189
1.7.187
1.7.186
1.7.185
1.7.184
1.7.183
1.7.182
1.7.181
1.7.180
1.7.179
1.7.178
1.7.177
1.7.176
1.7.175
1.7.174
1.7.173
1.7.172
1.7.171
1.7.170
1.7.169
1.7.168
1.7.167
1.7.166
1.7.165
1.7.164
1.7.162
1.7.161
1.7.160
1.7.159
1.7.157
1.7.156
1.7.155
1.7.154
1.7.153
1.7.152
1.7.151
1.7.150
1.7.149
1.7.146
1.7.145
1.7.144
1.7.143
1.7.138
1.7.133
1.7.132
1.7.131
1.7.130
1.7.128
1.7.126
1.7.125
1.7.121
1.7.120
1.7.119
1.7.118
1.7.117
1.7.116
1.7.115
1.7.114
1.7.113
1.7.112
1.7.111
1.7.110
1.7.109
1.7.108
1.7.107
1.7.106
1.7.105
1.7.104
1.7.103
1.7.102
1.7.101
1.7.100
1.7.99
1.7.98
1.7.97
1.7.96
1.7.95
1.7.94
1.7.93
1.7.92
1.7.91
1.7.90
1.7.89
1.7.88
1.7.87
1.7.86
1.7.85
1.7.84
1.7.83
1.7.82
1.7.81
1.7.80
1.7.79
1.7.78
1.7.77
1.7.76
1.7.75
1.7.74
1.7.71
1.7.70
1.7.69
1.7.66
1.7.65
1.7.64
1.7.63
1.7.62
1.7.61
1.7.59
1.7.58
1.7.57
1.7.56
1.7.55
1.7.54
1.7.53
1.7.52
1.7.51
1.7.49
1.7.44
1.7.43
1.7.42
1.7.41
1.7.39
1.7.38
1.7.37
1.7.36
1.7.34
1.7.33
1.7.31
1.7.30
1.7.29
1.7.28
1.7.27
1.7.26
1.7.25
1.7.24
1.7.23
1.7.22
1.7.21
1.7.20
1.7.19
1.7.18
1.7.17
1.7.16
1.7.15
1.7.14
1.7.13
1.7.12
1.7.11
1.7.10
1.7.9
1.7.8
1.7.7
1.7.6
1.7.5
1.7.4
1.7.3
1.7.2
1.7.1
1.7.0
1.6.20
1.6.19
1.6.18
1.6.17
1.6.16
1.6.15
1.6.14
1.6.13
1.6.12
1.6.11
1.6.10
1.6.9
1.6.8
1.6.7
1.6.6
1.6.5
1.6.4
1.6.3
1.5.2
1.5.1
1.5.0
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.10
1.2.9
1.2.8
1.2.7
1.2.5
1.2.4
1.2.2
1.2.1
1.2.0
1.1.0
1.0.0
A foundation for building Elixir Phoenix apps — SaaS, social networks, ERP systems, marketplaces, and more
Current section
221 Versions
Jump to
Current section
221 Versions
Compare versions
25
files changed
+674
additions
-33
deletions
unknownCHANGELOG.md
File is too large to be displayed (100 KB limit).
| @@ -1,6 +1,6 @@ | |
| 1 1 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/BeamLabEU/phoenix_kit">>}]}. |
| 2 2 | {<<"name">>,<<"phoenix_kit">>}. |
| 3 | - {<<"version">>,<<"1.7.174">>}. |
| 3 | + {<<"version">>,<<"1.7.175">>}. |
| 4 4 | {<<"description">>, |
| 5 5 | <<65,32,102,111,117,110,100,97,116,105,111,110,32,102,111,114,32,98,117,105, |
| 6 6 | 108,100,105,110,103,32,69,108,105,120,105,114,32,80,104,111,101,110,105, |
| @@ -166,6 +166,48 @@ defmodule PhoenixKit.Modules.Sitemap.Sources.RouterDiscovery do | |
| 166 166 | [] |
| 167 167 | end |
| 168 168 | |
| 169 | + ## Settings UI helpers |
| 170 | + |
| 171 | + @doc """ |
| 172 | + Returns the subset of `patterns` that fail to compile as regexes. |
| 173 | + |
| 174 | + Mirrors the same `Regex.compile/1` check `compile_patterns/2` applies at |
| 175 | + collection time, so a pattern accepted here is guaranteed not to be |
| 176 | + silently dropped later. Used by the settings UI to reject invalid |
| 177 | + exclude/include-only patterns before saving, instead of persisting them |
| 178 | + and only discovering the problem in the logs. |
| 179 | + |
| 180 | + ## Examples |
| 181 | + |
| 182 | + iex> PhoenixKit.Modules.Sitemap.Sources.RouterDiscovery.invalid_patterns(["^/admin", "*"]) |
| 183 | + ["*"] |
| 184 | + """ |
| 185 | + @spec invalid_patterns([String.t()]) :: [String.t()] |
| 186 | + def invalid_patterns(patterns) when is_list(patterns) do |
| 187 | + Enum.filter(patterns, &match?({:error, _}, Regex.compile(&1))) |
| 188 | + end |
| 189 | + |
| 190 | + @doc """ |
| 191 | + Returns the built-in default exclude patterns. |
| 192 | + |
| 193 | + These apply whenever `sitemap_router_discovery_exclude_patterns` is unset. |
| 194 | + Once that setting is saved (even as an empty list), it replaces this list |
| 195 | + entirely rather than adding to it. Exposed so the settings UI can show |
| 196 | + admins what's excluded today, before they touch the setting. |
| 197 | + """ |
| 198 | + @spec default_exclude_patterns() :: [String.t()] |
| 199 | + def default_exclude_patterns, do: @default_exclude_patterns |
| 200 | + |
| 201 | + @doc """ |
| 202 | + Returns the built-in default protected pipelines. |
| 203 | + |
| 204 | + Unlike exclude patterns, `sitemap_protected_pipelines` only *adds* to this |
| 205 | + list — these defaults always apply. Exposed so the settings UI can show |
| 206 | + admins which pipelines are already protected without configuration. |
| 207 | + """ |
| 208 | + @spec default_protected_pipelines() :: [atom()] |
| 209 | + def default_protected_pipelines, do: @default_protected_pipelines |
| 210 | + |
| 169 211 | defp do_collect(opts) do |
| 170 212 | base_url = Keyword.get(opts, :base_url) |
| 171 213 | exclude_patterns = compile_patterns(get_exclude_patterns(), "exclude") |
| @@ -15,12 +15,31 @@ defmodule PhoenixKit.Modules.Sitemap.Sources.Source do | |
| 15 15 | |
| 16 16 | - `sitemap_filename/0` - Custom filename for the module's sitemap file |
| 17 17 | - `sub_sitemaps/1` - Split into multiple sub-sitemap files (e.g., per-blog, per-entity-type) |
| 18 | + - `sitemap_settings_schema/0` - Declare source-specific settings for the admin UI |
| 18 19 | """ |
| 19 20 | |
| 20 21 | require Logger |
| 21 22 | |
| 22 23 | alias PhoenixKit.Modules.Sitemap.UrlEntry |
| 23 24 | |
| 25 | + @typedoc """ |
| 26 | + Describes one source-specific setting for the admin settings UI. |
| 27 | + |
| 28 | + - `key` - the `PhoenixKit.Settings` key this field reads/writes |
| 29 | + - `type` - controls both the input widget and how the stored string is |
| 30 | + parsed (`:boolean` -> toggle, `:string` -> text input, `:integer` -> number input) |
| 31 | + - `label` - field label shown to the admin |
| 32 | + - `help` - optional helper text shown below the label |
| 33 | + - `default` - value used when the setting has never been saved |
| 34 | + """ |
| 35 | + @type settings_field :: %{ |
| 36 | + key: String.t(), |
| 37 | + type: :boolean | :string | :integer, |
| 38 | + label: String.t(), |
| 39 | + help: String.t() | nil, |
| 40 | + default: term() |
| 41 | + } |
| 42 | + |
| 24 43 | @doc """ |
| 25 44 | Returns the unique name/identifier for this source. |
| 26 45 | """ |
| @@ -53,7 +72,36 @@ defmodule PhoenixKit.Modules.Sitemap.Sources.Source do | |
| 53 72 | """ |
| 54 73 | @callback sub_sitemaps(opts :: keyword()) :: [{String.t(), [UrlEntry.t()]}] | nil |
| 55 74 | |
| 56 | - @optional_callbacks [sitemap_filename: 0, sub_sitemaps: 1] |
| 75 | + @doc """ |
| 76 | + Declares source-specific settings for the sitemap admin settings page. |
| 77 | + |
| 78 | + Optional. A source that implements this returns a list of field |
| 79 | + descriptors; the settings page renders one input per field (grouped |
| 80 | + under the source's name), reads/writes each through `PhoenixKit.Settings` |
| 81 | + using its `key` and `default`, and invalidates the sitemap cache on save |
| 82 | + — the same way the page's built-in settings work. |
| 83 | + |
| 84 | + Only add this for settings that don't already have a UI. Don't |
| 85 | + reimplement fields the core sitemap settings page already exposes (e.g. |
| 86 | + the built-in `sitemap_include_*` toggles). |
| 87 | + |
| 88 | + ## Example |
| 89 | + |
| 90 | + def sitemap_settings_schema do |
| 91 | + [ |
| 92 | + %{ |
| 93 | + key: "sitemap_entities_include_index", |
| 94 | + type: :boolean, |
| 95 | + label: "Include entity index pages", |
| 96 | + help: "Adds the /entities listing page alongside individual entries", |
| 97 | + default: true |
| 98 | + } |
| 99 | + ] |
| 100 | + end |
| 101 | + """ |
| 102 | + @callback sitemap_settings_schema() :: [settings_field()] |
| 103 | + |
| 104 | + @optional_callbacks [sitemap_filename: 0, sub_sitemaps: 1, sitemap_settings_schema: 0] |
| 57 105 | |
| 58 106 | @doc """ |
| 59 107 | Helper function to check if a source module is valid. |
| @@ -100,6 +148,21 @@ defmodule PhoenixKit.Modules.Sitemap.Sources.Source do | |
| 100 148 | end |
| 101 149 | end |
| 102 150 | |
| 151 | + @doc """ |
| 152 | + Returns the settings schema for a source module. |
| 153 | + |
| 154 | + Calls the optional `sitemap_settings_schema/0` callback if implemented, |
| 155 | + otherwise returns `[]` (no source-specific settings to render). |
| 156 | + """ |
| 157 | + @spec get_settings_schema(module()) :: [settings_field()] |
| 158 | + def get_settings_schema(source_module) do |
| 159 | + if function_exported?(source_module, :sitemap_settings_schema, 0) do |
| 160 | + source_module.sitemap_settings_schema() |
| 161 | + else |
| 162 | + [] |
| 163 | + end |
| 164 | + end |
| 165 | + |
| 103 166 | @doc """ |
| 104 167 | Safely collects entries from a source, handling errors gracefully. |
| 105 168 | """ |
| @@ -91,6 +91,18 @@ defmodule PhoenixKit.Modules.Sitemap.Sources.Static do | |
| 91 91 | @impl true |
| 92 92 | def sitemap_filename, do: "sitemap-static" |
| 93 93 | |
| 94 | + @doc """ |
| 95 | + Returns the built-in default static routes (always includes the homepage). |
| 96 | + |
| 97 | + These apply whenever `sitemap_static_routes` is unset. Once that setting |
| 98 | + is saved (even as an empty list), it replaces this list entirely — so |
| 99 | + saving `[]` removes the homepage entry too. Exposed so the settings UI can |
| 100 | + pre-fill the editor with the current effective routes instead of an empty |
| 101 | + list that looks safe to submit as-is but isn't. |
| 102 | + """ |
| 103 | + @spec default_static_routes() :: [map()] |
| 104 | + def default_static_routes, do: @default_static_routes |
| 105 | + |
| 94 106 | @impl true |
| 95 107 | def collect(opts \\ []) do |
| 96 108 | is_default = Keyword.get(opts, :is_default_language, true) |
Loading more files…