elm-pages 2.1.6 → 2.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generator/review/elm.json +34 -0
- package/generator/review/src/ReviewConfig.elm +10 -0
- package/generator/src/basepath-middleware.js +15 -9
- package/generator/src/build.js +100 -6
- package/generator/src/cli.js +13 -9
- package/generator/src/compile-elm.js +43 -0
- package/generator/src/dev-server.js +63 -11
- package/generator/src/error-formatter.js +62 -9
- package/generator/src/generate-template-module-connector.js +17 -4
- package/generator/src/init.js +4 -0
- package/generator/src/pre-render-html.js +19 -12
- package/generator/src/render-worker.js +0 -1
- package/generator/src/render.js +1 -2
- package/generator/src/seo-renderer.js +21 -2
- package/generator/static-code/hmr.js +43 -6
- package/generator/template/elm-tooling.json +9 -0
- package/generator/template/package.json +5 -1
- package/package.json +16 -9
- package/src/ApiRoute.elm +178 -0
- package/src/AriaLiveAnnouncer.elm +36 -0
- package/src/BuildError.elm +60 -0
- package/src/DataSource/File.elm +288 -0
- package/src/DataSource/Glob.elm +1050 -0
- package/src/DataSource/Http.elm +467 -0
- package/src/DataSource/Internal/Glob.elm +74 -0
- package/src/DataSource/Port.elm +87 -0
- package/src/DataSource/ServerRequest.elm +60 -0
- package/src/DataSource.elm +801 -0
- package/src/Head/Seo.elm +516 -0
- package/src/Head/Twitter.elm +109 -0
- package/src/Head.elm +452 -0
- package/src/HtmlPrinter.elm +27 -0
- package/src/Internal/ApiRoute.elm +89 -0
- package/src/Internal/OptimizedDecoder.elm +18 -0
- package/src/KeepOrDiscard.elm +6 -0
- package/src/OptimizedDecoder/Pipeline.elm +335 -0
- package/src/OptimizedDecoder.elm +818 -0
- package/src/Pages/ContentCache.elm +248 -0
- package/src/Pages/Flags.elm +26 -0
- package/src/Pages/Http.elm +10 -0
- package/src/Pages/Internal/ApplicationType.elm +6 -0
- package/src/Pages/Internal/NotFoundReason.elm +256 -0
- package/src/Pages/Internal/Platform/Cli.elm +1015 -0
- package/src/Pages/Internal/Platform/Effect.elm +14 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +540 -0
- package/src/Pages/Internal/Platform/ToJsPayload.elm +138 -0
- package/src/Pages/Internal/Platform.elm +745 -0
- package/src/Pages/Internal/RoutePattern.elm +122 -0
- package/src/Pages/Internal/Router.elm +116 -0
- package/src/Pages/Internal/StaticHttpBody.elm +54 -0
- package/src/Pages/Internal/String.elm +39 -0
- package/src/Pages/Manifest/Category.elm +240 -0
- package/src/Pages/Manifest.elm +412 -0
- package/src/Pages/PageUrl.elm +38 -0
- package/src/Pages/ProgramConfig.elm +73 -0
- package/src/Pages/Review/NoContractViolations.elm +397 -0
- package/src/Pages/Secrets.elm +83 -0
- package/src/Pages/SiteConfig.elm +13 -0
- package/src/Pages/StaticHttp/Request.elm +42 -0
- package/src/Pages/StaticHttpRequest.elm +320 -0
- package/src/Pages/Url.elm +60 -0
- package/src/Path.elm +96 -0
- package/src/QueryParams.elm +216 -0
- package/src/RenderRequest.elm +163 -0
- package/src/RequestsAndPending.elm +20 -0
- package/src/Secrets.elm +111 -0
- package/src/SecretsDict.elm +45 -0
- package/src/StructuredData.elm +236 -0
- package/src/TerminalText.elm +242 -0
- package/src/Test/Html/Internal/ElmHtml/Constants.elm +53 -0
- package/src/Test/Html/Internal/ElmHtml/Helpers.elm +17 -0
- package/src/Test/Html/Internal/ElmHtml/InternalTypes.elm +529 -0
- package/src/Test/Html/Internal/ElmHtml/Markdown.elm +56 -0
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +197 -0
- package/src/Test/Internal/KernelConstants.elm +34 -0
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
module Pages.Manifest exposing
|
|
2
|
+
( Config, Icon
|
|
3
|
+
, init
|
|
4
|
+
, withBackgroundColor, withCategories, withDisplayMode, withIarcRatingId, withLang, withOrientation, withShortName, withThemeColor
|
|
5
|
+
, DisplayMode(..), Orientation(..), IconPurpose(..)
|
|
6
|
+
, toJson
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
{-| Represents the configuration of a
|
|
10
|
+
[web manifest file](https://developer.mozilla.org/en-US/docs/Web/Manifest).
|
|
11
|
+
|
|
12
|
+
You pass your `Pages.Manifest.Config` record into the `Pages.application` function
|
|
13
|
+
(from your generated `Pages.elm` file).
|
|
14
|
+
|
|
15
|
+
import Pages.Manifest as Manifest
|
|
16
|
+
import Pages.Manifest.Category
|
|
17
|
+
|
|
18
|
+
manifest : Manifest.Config
|
|
19
|
+
manifest =
|
|
20
|
+
Manifest.init
|
|
21
|
+
{ name = static.siteName
|
|
22
|
+
, description = "elm-pages - " ++ tagline
|
|
23
|
+
, startUrl = Route.Index {} |> Route.toPath
|
|
24
|
+
, icons =
|
|
25
|
+
[ icon webp 192
|
|
26
|
+
, icon webp 512
|
|
27
|
+
, icon MimeType.Png 192
|
|
28
|
+
, icon MimeType.Png 512
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
|> Manifest.withShortName "elm-pages"
|
|
32
|
+
|
|
33
|
+
@docs Config, Icon
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Builder options
|
|
37
|
+
|
|
38
|
+
@docs init
|
|
39
|
+
|
|
40
|
+
@docs withBackgroundColor, withCategories, withDisplayMode, withIarcRatingId, withLang, withOrientation, withShortName, withThemeColor
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
## Config options
|
|
44
|
+
|
|
45
|
+
@docs DisplayMode, Orientation, IconPurpose
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Functions for use by the generated code (`Pages.elm`)
|
|
49
|
+
|
|
50
|
+
@docs toJson
|
|
51
|
+
|
|
52
|
+
-}
|
|
53
|
+
|
|
54
|
+
import Color exposing (Color)
|
|
55
|
+
import Color.Convert
|
|
56
|
+
import Json.Encode as Encode
|
|
57
|
+
import LanguageTag exposing (LanguageTag, emptySubtags)
|
|
58
|
+
import LanguageTag.Country as Country
|
|
59
|
+
import LanguageTag.Language
|
|
60
|
+
import MimeType
|
|
61
|
+
import Pages.Manifest.Category as Category exposing (Category)
|
|
62
|
+
import Pages.Url
|
|
63
|
+
import Path exposing (Path)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
{- TODO serviceworker https://developer.mozilla.org/en-US/docs/Web/Manifest/serviceworker
|
|
68
|
+
This is mandatory... need to process this in a special way
|
|
69
|
+
-}
|
|
70
|
+
-- TODO use language https://developer.mozilla.org/en-US/docs/Web/Manifest/lang
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
{-| See <https://developer.mozilla.org/en-US/docs/Web/Manifest/display>
|
|
74
|
+
-}
|
|
75
|
+
type DisplayMode
|
|
76
|
+
= Fullscreen
|
|
77
|
+
| Standalone
|
|
78
|
+
| MinimalUi
|
|
79
|
+
| Browser
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
{-| <https://developer.mozilla.org/en-US/docs/Web/Manifest/orientation>
|
|
83
|
+
-}
|
|
84
|
+
type Orientation
|
|
85
|
+
= Any
|
|
86
|
+
| Natural
|
|
87
|
+
| Landscape
|
|
88
|
+
| LandscapePrimary
|
|
89
|
+
| LandscapeSecondary
|
|
90
|
+
| Portrait
|
|
91
|
+
| PortraitPrimary
|
|
92
|
+
| PortraitSecondary
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
{-| Setup a minimal Manifest.Config. You can then use the `with...` builder functions to set additional options.
|
|
96
|
+
-}
|
|
97
|
+
init :
|
|
98
|
+
{ description : String
|
|
99
|
+
, name : String
|
|
100
|
+
, startUrl : Path
|
|
101
|
+
, icons : List Icon
|
|
102
|
+
}
|
|
103
|
+
-> Config
|
|
104
|
+
init options =
|
|
105
|
+
{ backgroundColor = Nothing
|
|
106
|
+
, categories = []
|
|
107
|
+
, displayMode = Standalone
|
|
108
|
+
, orientation = Portrait
|
|
109
|
+
, description = options.description
|
|
110
|
+
, iarcRatingId = Nothing
|
|
111
|
+
, name = options.name
|
|
112
|
+
, themeColor = Nothing
|
|
113
|
+
, startUrl = options.startUrl
|
|
114
|
+
, shortName = Nothing
|
|
115
|
+
, icons = options.icons
|
|
116
|
+
, lang = usEnglish
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
usEnglish : LanguageTag
|
|
121
|
+
usEnglish =
|
|
122
|
+
LanguageTag.Language.en
|
|
123
|
+
|> LanguageTag.build
|
|
124
|
+
{ emptySubtags
|
|
125
|
+
| region = Just Country.us
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/background_color>.
|
|
130
|
+
-}
|
|
131
|
+
withBackgroundColor : Color -> Config -> Config
|
|
132
|
+
withBackgroundColor color config =
|
|
133
|
+
{ config | backgroundColor = Just color }
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/categories>.
|
|
137
|
+
-}
|
|
138
|
+
withCategories : List Category -> Config -> Config
|
|
139
|
+
withCategories categories config =
|
|
140
|
+
{ config | categories = categories ++ config.categories }
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/display>.
|
|
144
|
+
-}
|
|
145
|
+
withDisplayMode : DisplayMode -> Config -> Config
|
|
146
|
+
withDisplayMode displayMode config =
|
|
147
|
+
{ config | displayMode = displayMode }
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/orientation>.
|
|
151
|
+
-}
|
|
152
|
+
withOrientation : Orientation -> Config -> Config
|
|
153
|
+
withOrientation orientation config =
|
|
154
|
+
{ config | orientation = orientation }
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/iarc_rating_id>.
|
|
158
|
+
-}
|
|
159
|
+
withIarcRatingId : String -> Config -> Config
|
|
160
|
+
withIarcRatingId iarcRatingId config =
|
|
161
|
+
{ config | iarcRatingId = Just iarcRatingId }
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/theme_color>.
|
|
165
|
+
-}
|
|
166
|
+
withThemeColor : Color -> Config -> Config
|
|
167
|
+
withThemeColor themeColor config =
|
|
168
|
+
{ config | themeColor = Just themeColor }
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/short_name>.
|
|
172
|
+
-}
|
|
173
|
+
withShortName : String -> Config -> Config
|
|
174
|
+
withShortName shortName config =
|
|
175
|
+
{ config | shortName = Just shortName }
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
{-| Set <https://developer.mozilla.org/en-US/docs/Web/Manifest/lang>.
|
|
179
|
+
-}
|
|
180
|
+
withLang : LanguageTag -> Config -> Config
|
|
181
|
+
withLang languageTag config =
|
|
182
|
+
{ config | lang = languageTag }
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
orientationToString : Orientation -> String
|
|
186
|
+
orientationToString orientation =
|
|
187
|
+
case orientation of
|
|
188
|
+
Any ->
|
|
189
|
+
"any"
|
|
190
|
+
|
|
191
|
+
Natural ->
|
|
192
|
+
"natural"
|
|
193
|
+
|
|
194
|
+
Landscape ->
|
|
195
|
+
"landscape"
|
|
196
|
+
|
|
197
|
+
LandscapePrimary ->
|
|
198
|
+
"landscape-primary"
|
|
199
|
+
|
|
200
|
+
LandscapeSecondary ->
|
|
201
|
+
"landscape-secondary"
|
|
202
|
+
|
|
203
|
+
Portrait ->
|
|
204
|
+
"portrait"
|
|
205
|
+
|
|
206
|
+
PortraitPrimary ->
|
|
207
|
+
"portrait-primary"
|
|
208
|
+
|
|
209
|
+
PortraitSecondary ->
|
|
210
|
+
"portrait-secondary"
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
{-| Represents a [web app manifest file](https://developer.mozilla.org/en-US/docs/Web/Manifest)
|
|
214
|
+
(see above for how to use it).
|
|
215
|
+
-}
|
|
216
|
+
type alias Config =
|
|
217
|
+
{ backgroundColor : Maybe Color
|
|
218
|
+
, categories : List Category
|
|
219
|
+
, displayMode : DisplayMode
|
|
220
|
+
, orientation : Orientation
|
|
221
|
+
, description : String
|
|
222
|
+
, iarcRatingId : Maybe String
|
|
223
|
+
, name : String
|
|
224
|
+
, themeColor : Maybe Color
|
|
225
|
+
|
|
226
|
+
-- https://developer.mozilla.org/en-US/docs/Web/Manifest/start_url
|
|
227
|
+
, startUrl : Path
|
|
228
|
+
|
|
229
|
+
-- https://developer.mozilla.org/en-US/docs/Web/Manifest/short_name
|
|
230
|
+
, shortName : Maybe String
|
|
231
|
+
, icons : List Icon
|
|
232
|
+
, lang : LanguageTag
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
{-| <https://developer.mozilla.org/en-US/docs/Web/Manifest/icons>
|
|
237
|
+
-}
|
|
238
|
+
type alias Icon =
|
|
239
|
+
{ src : Pages.Url.Url
|
|
240
|
+
, sizes : List ( Int, Int )
|
|
241
|
+
, mimeType : Maybe MimeType.MimeImage
|
|
242
|
+
, purposes : List IconPurpose
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
{-| <https://w3c.github.io/manifest/#dfn-icon-purposes>
|
|
247
|
+
-}
|
|
248
|
+
type IconPurpose
|
|
249
|
+
= IconPurposeMonochrome
|
|
250
|
+
| IconPurposeMaskable
|
|
251
|
+
| IconPurposeAny
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
displayModeToAttribute : DisplayMode -> String
|
|
255
|
+
displayModeToAttribute displayMode =
|
|
256
|
+
case displayMode of
|
|
257
|
+
Fullscreen ->
|
|
258
|
+
"fullscreen"
|
|
259
|
+
|
|
260
|
+
Standalone ->
|
|
261
|
+
"standalone"
|
|
262
|
+
|
|
263
|
+
MinimalUi ->
|
|
264
|
+
"minimal-ui"
|
|
265
|
+
|
|
266
|
+
Browser ->
|
|
267
|
+
"browser"
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
encodeIcon : String -> Icon -> Encode.Value
|
|
271
|
+
encodeIcon canonicalSiteUrl icon =
|
|
272
|
+
encodeMaybeObject
|
|
273
|
+
[ ( "src", icon.src |> Pages.Url.toAbsoluteUrl canonicalSiteUrl |> Encode.string |> Just )
|
|
274
|
+
, ( "type", icon.mimeType |> Maybe.map MimeType.Image |> Maybe.map MimeType.toString |> Maybe.map Encode.string )
|
|
275
|
+
, ( "sizes", icon.sizes |> nonEmptyList |> Maybe.map sizesString |> Maybe.map Encode.string )
|
|
276
|
+
, ( "purpose", icon.purposes |> nonEmptyList |> Maybe.map purposesString |> Maybe.map Encode.string )
|
|
277
|
+
]
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
purposesString : List IconPurpose -> String
|
|
281
|
+
purposesString purposes =
|
|
282
|
+
purposes
|
|
283
|
+
|> List.map purposeToString
|
|
284
|
+
|> String.join " "
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
purposeToString : IconPurpose -> String
|
|
288
|
+
purposeToString purpose =
|
|
289
|
+
case purpose of
|
|
290
|
+
IconPurposeMonochrome ->
|
|
291
|
+
"monochrome"
|
|
292
|
+
|
|
293
|
+
IconPurposeMaskable ->
|
|
294
|
+
"maskable"
|
|
295
|
+
|
|
296
|
+
IconPurposeAny ->
|
|
297
|
+
"any"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
sizesString : List ( Int, Int ) -> String
|
|
301
|
+
sizesString sizes =
|
|
302
|
+
sizes
|
|
303
|
+
|> List.map (\( x, y ) -> String.fromInt x ++ "x" ++ String.fromInt y)
|
|
304
|
+
|> String.join " "
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
nonEmptyList : List a -> Maybe (List a)
|
|
308
|
+
nonEmptyList list =
|
|
309
|
+
if List.isEmpty list then
|
|
310
|
+
Nothing
|
|
311
|
+
|
|
312
|
+
else
|
|
313
|
+
Just list
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
{-| Feel free to use this, but in 99% of cases you won't need it. The generated
|
|
317
|
+
code will run this for you to generate your `manifest.json` file automatically!
|
|
318
|
+
-}
|
|
319
|
+
toJson : String -> Config -> Encode.Value
|
|
320
|
+
toJson canonicalSiteUrl config =
|
|
321
|
+
[ ( "dir", Encode.string "auto" |> Just )
|
|
322
|
+
, ( "lang"
|
|
323
|
+
, config.lang
|
|
324
|
+
|> LanguageTag.toString
|
|
325
|
+
|> Encode.string
|
|
326
|
+
|> Just
|
|
327
|
+
)
|
|
328
|
+
, ( "icons"
|
|
329
|
+
, config.icons
|
|
330
|
+
|> Encode.list (encodeIcon canonicalSiteUrl)
|
|
331
|
+
|> Just
|
|
332
|
+
)
|
|
333
|
+
, ( "background_color"
|
|
334
|
+
, config.backgroundColor
|
|
335
|
+
|> Maybe.map Color.Convert.colorToHex
|
|
336
|
+
|> Maybe.map Encode.string
|
|
337
|
+
)
|
|
338
|
+
, ( "orientation"
|
|
339
|
+
, config.orientation
|
|
340
|
+
|> orientationToString
|
|
341
|
+
|> Encode.string
|
|
342
|
+
|> Just
|
|
343
|
+
)
|
|
344
|
+
, ( "display"
|
|
345
|
+
, config.displayMode
|
|
346
|
+
|> displayModeToAttribute
|
|
347
|
+
|> Encode.string
|
|
348
|
+
|> Just
|
|
349
|
+
)
|
|
350
|
+
, ( "categories"
|
|
351
|
+
, config.categories
|
|
352
|
+
|> List.map Category.toString
|
|
353
|
+
|> Encode.list Encode.string
|
|
354
|
+
|> Just
|
|
355
|
+
)
|
|
356
|
+
, ( "description"
|
|
357
|
+
, config.description
|
|
358
|
+
|> Encode.string
|
|
359
|
+
|> Just
|
|
360
|
+
)
|
|
361
|
+
, ( "iarc_rating_id"
|
|
362
|
+
, config.iarcRatingId
|
|
363
|
+
|> Maybe.map Encode.string
|
|
364
|
+
)
|
|
365
|
+
, ( "name"
|
|
366
|
+
, config.name
|
|
367
|
+
|> Encode.string
|
|
368
|
+
|> Just
|
|
369
|
+
)
|
|
370
|
+
, ( "prefer_related_applications"
|
|
371
|
+
, Encode.bool False
|
|
372
|
+
|> Just
|
|
373
|
+
-- TODO remove hardcoding
|
|
374
|
+
)
|
|
375
|
+
, ( "related_applications"
|
|
376
|
+
, Encode.list (\_ -> Encode.object []) []
|
|
377
|
+
|> Just
|
|
378
|
+
-- TODO remove hardcoding https://developer.mozilla.org/en-US/docs/Web/Manifest/related_applications
|
|
379
|
+
)
|
|
380
|
+
, ( "theme_color"
|
|
381
|
+
, config.themeColor
|
|
382
|
+
|> Maybe.map Color.Convert.colorToHex
|
|
383
|
+
|> Maybe.map Encode.string
|
|
384
|
+
)
|
|
385
|
+
, ( "start_url"
|
|
386
|
+
, Path.toAbsolute config.startUrl
|
|
387
|
+
|> Encode.string
|
|
388
|
+
|> Just
|
|
389
|
+
)
|
|
390
|
+
, ( "short_name"
|
|
391
|
+
, config.shortName |> Maybe.map Encode.string
|
|
392
|
+
)
|
|
393
|
+
, ( "scope"
|
|
394
|
+
, Encode.string "/" |> Just
|
|
395
|
+
)
|
|
396
|
+
]
|
|
397
|
+
|> encodeMaybeObject
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
encodeMaybeObject : List ( String, Maybe Encode.Value ) -> Encode.Value
|
|
401
|
+
encodeMaybeObject list =
|
|
402
|
+
list
|
|
403
|
+
|> List.filterMap
|
|
404
|
+
(\( key, maybeValue ) ->
|
|
405
|
+
case maybeValue of
|
|
406
|
+
Just value ->
|
|
407
|
+
Just ( key, value )
|
|
408
|
+
|
|
409
|
+
Nothing ->
|
|
410
|
+
Nothing
|
|
411
|
+
)
|
|
412
|
+
|> Encode.object
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Pages.PageUrl exposing (PageUrl, toUrl)
|
|
2
|
+
|
|
3
|
+
{-| Same as a Url in `elm/url`, but slightly more structured. The path portion of the URL is parsed into a [`Path`](Path) type, and
|
|
4
|
+
the query params use the [`QueryParams`](QueryParams) type which allows you to parse just the query params or access them into a Dict.
|
|
5
|
+
|
|
6
|
+
Because `elm-pages` takes care of the main routing for pages in your app, the standard Elm URL parser API isn't suited
|
|
7
|
+
to parsing query params individually, which is why the structure of these types is different.
|
|
8
|
+
|
|
9
|
+
@docs PageUrl, toUrl
|
|
10
|
+
|
|
11
|
+
-}
|
|
12
|
+
|
|
13
|
+
import Path exposing (Path)
|
|
14
|
+
import QueryParams exposing (QueryParams)
|
|
15
|
+
import Url
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
{-| -}
|
|
19
|
+
type alias PageUrl =
|
|
20
|
+
{ protocol : Url.Protocol
|
|
21
|
+
, host : String
|
|
22
|
+
, port_ : Maybe Int
|
|
23
|
+
, path : Path
|
|
24
|
+
, query : Maybe QueryParams
|
|
25
|
+
, fragment : Maybe String
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
{-| -}
|
|
30
|
+
toUrl : PageUrl -> Url.Url
|
|
31
|
+
toUrl url =
|
|
32
|
+
{ protocol = url.protocol
|
|
33
|
+
, host = url.host
|
|
34
|
+
, port_ = url.port_
|
|
35
|
+
, path = url.path |> Path.toRelative
|
|
36
|
+
, query = url.query |> Maybe.map QueryParams.toString
|
|
37
|
+
, fragment = url.fragment
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Pages.ProgramConfig exposing (ProgramConfig)
|
|
2
|
+
|
|
3
|
+
import ApiRoute
|
|
4
|
+
import Browser.Navigation
|
|
5
|
+
import DataSource
|
|
6
|
+
import Head
|
|
7
|
+
import Html exposing (Html)
|
|
8
|
+
import Json.Decode as Decode
|
|
9
|
+
import Json.Encode
|
|
10
|
+
import Pages.Flags
|
|
11
|
+
import Pages.Internal.NotFoundReason exposing (NotFoundReason)
|
|
12
|
+
import Pages.Internal.RoutePattern exposing (RoutePattern)
|
|
13
|
+
import Pages.PageUrl exposing (PageUrl)
|
|
14
|
+
import Pages.SiteConfig exposing (SiteConfig)
|
|
15
|
+
import Path exposing (Path)
|
|
16
|
+
import Url exposing (Url)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
type alias ProgramConfig userMsg userModel route siteData pageData sharedData =
|
|
20
|
+
{ init :
|
|
21
|
+
Pages.Flags.Flags
|
|
22
|
+
-> sharedData
|
|
23
|
+
-> pageData
|
|
24
|
+
-> Maybe Browser.Navigation.Key
|
|
25
|
+
->
|
|
26
|
+
Maybe
|
|
27
|
+
{ path :
|
|
28
|
+
{ path : Path
|
|
29
|
+
, query : Maybe String
|
|
30
|
+
, fragment : Maybe String
|
|
31
|
+
}
|
|
32
|
+
, metadata : route
|
|
33
|
+
, pageUrl : Maybe PageUrl
|
|
34
|
+
}
|
|
35
|
+
-> ( userModel, Cmd userMsg )
|
|
36
|
+
, update : sharedData -> pageData -> Maybe Browser.Navigation.Key -> userMsg -> userModel -> ( userModel, Cmd userMsg )
|
|
37
|
+
, subscriptions : route -> Path -> userModel -> Sub userMsg
|
|
38
|
+
, sharedData : DataSource.DataSource sharedData
|
|
39
|
+
, data : route -> DataSource.DataSource pageData
|
|
40
|
+
, view :
|
|
41
|
+
{ path : Path
|
|
42
|
+
, route : route
|
|
43
|
+
}
|
|
44
|
+
-> Maybe PageUrl
|
|
45
|
+
-> sharedData
|
|
46
|
+
-> pageData
|
|
47
|
+
->
|
|
48
|
+
{ view : userModel -> { title : String, body : Html userMsg }
|
|
49
|
+
, head : List Head.Tag
|
|
50
|
+
}
|
|
51
|
+
, handleRoute : route -> DataSource.DataSource (Maybe NotFoundReason)
|
|
52
|
+
, getStaticRoutes : DataSource.DataSource (List route)
|
|
53
|
+
, urlToRoute : Url -> route
|
|
54
|
+
, routeToPath : route -> List String
|
|
55
|
+
, site : Maybe (SiteConfig siteData)
|
|
56
|
+
, toJsPort : Json.Encode.Value -> Cmd Never
|
|
57
|
+
, fromJsPort : Sub Decode.Value
|
|
58
|
+
, onPageChange :
|
|
59
|
+
{ protocol : Url.Protocol
|
|
60
|
+
, host : String
|
|
61
|
+
, port_ : Maybe Int
|
|
62
|
+
, path : Path
|
|
63
|
+
, query : Maybe String
|
|
64
|
+
, fragment : Maybe String
|
|
65
|
+
, metadata : route
|
|
66
|
+
}
|
|
67
|
+
-> userMsg
|
|
68
|
+
, apiRoutes :
|
|
69
|
+
(Html Never -> String)
|
|
70
|
+
-> List (ApiRoute.ApiRoute ApiRoute.Response)
|
|
71
|
+
, pathPatterns : List RoutePattern
|
|
72
|
+
, basePath : List String
|
|
73
|
+
}
|