@charmland/gem 0.1.0 → 0.2.0
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/dist/browser/boot.d.ts +1 -1
- package/dist/browser/boot.js +1 -1
- package/dist/browser/lightbox.d.ts +8 -0
- package/dist/browser/lightbox.js +282 -0
- package/dist/browser/ports.js +13 -13
- package/dist/browser/router.d.ts +8 -3
- package/dist/browser/router.js +34 -6
- package/dist/browser/runtime.d.ts +2 -0
- package/dist/browser/runtime.js +4 -1
- package/dist/default/theme.css +123 -45
- package/dist/default/theme.js +901 -740
- package/package.json +2 -4
- package/src/app/Gem/App.elm +35 -50
- package/src/app/Gem/Shell.elm +64 -52
- package/src/core/Gem/Page.elm +174 -23
- package/src/core/Gem/Render.elm +71 -33
- package/src/styles/docs.scss +24 -12
- package/src/styles/fonts.scss +24 -22
- package/src/styles/gem.scss +74 -7
- package/src/styles/ui/burger.scss +6 -1
- package/src/styles/ui/controls-extra.scss +8 -13
- package/src/styles/ui/controls.scss +1 -1
- package/assets/fonts/Hypography-Italic.woff2 +0 -0
- package/assets/fonts/Hypography-Regular.woff2 +0 -0
- package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charmland/gem",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Gem's Elm sources, default application, browser runtime, UI kit, stylesheet and fonts.",
|
|
5
5
|
"keywords": ["gem", "elm", "documentation", "theme", "ui"],
|
|
6
6
|
"homepage": "https://github.com/charmbracelet/gem/tree/main/packages/gem",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"./source/ui/*": "./src/ui/*",
|
|
53
53
|
"./source/styles/*": "./src/styles/*",
|
|
54
54
|
"./source/elm.json": "./elm.json",
|
|
55
|
-
"./fonts/*": "./assets/fonts/*",
|
|
56
55
|
"./package.json": "./package.json"
|
|
57
56
|
},
|
|
58
57
|
"files": [
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"src/app",
|
|
64
63
|
"src/ui",
|
|
65
64
|
"src/styles",
|
|
66
|
-
"assets/fonts",
|
|
67
65
|
"elm.json",
|
|
68
66
|
"LICENSE",
|
|
69
67
|
"NOTICE"
|
|
@@ -77,7 +75,7 @@
|
|
|
77
75
|
"prepack": "bun run build"
|
|
78
76
|
},
|
|
79
77
|
"dependencies": {
|
|
80
|
-
"@charmland/gem-compiler": "0.
|
|
78
|
+
"@charmland/gem-compiler": "0.2.0"
|
|
81
79
|
},
|
|
82
80
|
"devDependencies": {
|
|
83
81
|
"@types/node": "^26.6.5",
|
package/src/app/Gem/App.elm
CHANGED
|
@@ -85,7 +85,6 @@ type Msg
|
|
|
85
85
|
| TocToggled
|
|
86
86
|
| AnchorsMeasured Measurements
|
|
87
87
|
| SearchShortcut
|
|
88
|
-
| ScrolledTo (Result Dom.Error ())
|
|
89
88
|
| Noop
|
|
90
89
|
|
|
91
90
|
|
|
@@ -107,10 +106,10 @@ init slots flags url key =
|
|
|
107
106
|
Ok site ->
|
|
108
107
|
let
|
|
109
108
|
page =
|
|
110
|
-
Page.byRoute site (
|
|
109
|
+
Page.byRoute site (Page.routeOf site url.path)
|
|
111
110
|
|
|
112
111
|
doc =
|
|
113
|
-
Page.docFor site (
|
|
112
|
+
Page.docFor site (Page.routeOf site url.path)
|
|
114
113
|
|
|
115
114
|
model =
|
|
116
115
|
{ site = site
|
|
@@ -148,8 +147,7 @@ init slots flags url key =
|
|
|
148
147
|
in
|
|
149
148
|
( model
|
|
150
149
|
, Cmd.batch
|
|
151
|
-
[
|
|
152
|
-
, measureAnchors (pageAnchors page)
|
|
150
|
+
[ measureAnchors (pageAnchors page)
|
|
153
151
|
, setMeta model
|
|
154
152
|
]
|
|
155
153
|
)
|
|
@@ -202,10 +200,10 @@ update msg model =
|
|
|
202
200
|
ChangedUrl url ->
|
|
203
201
|
let
|
|
204
202
|
page =
|
|
205
|
-
Page.byRoute model.site (
|
|
203
|
+
Page.byRoute model.site (Page.routeOf model.site url.path)
|
|
206
204
|
|
|
207
205
|
doc =
|
|
208
|
-
Page.docFor model.site (
|
|
206
|
+
Page.docFor model.site (Page.routeOf model.site url.path)
|
|
209
207
|
|
|
210
208
|
next =
|
|
211
209
|
{ model
|
|
@@ -242,8 +240,7 @@ update msg model =
|
|
|
242
240
|
in
|
|
243
241
|
( next
|
|
244
242
|
, Cmd.batch
|
|
245
|
-
[
|
|
246
|
-
, measureAnchors (pageAnchors page)
|
|
243
|
+
[ measureAnchors (pageAnchors page)
|
|
247
244
|
, setMeta next
|
|
248
245
|
]
|
|
249
246
|
)
|
|
@@ -262,7 +259,7 @@ update msg model =
|
|
|
262
259
|
case inner of
|
|
263
260
|
Ui.Search.Select route ->
|
|
264
261
|
( { model | search = search, query = "", searchOpen = False }
|
|
265
|
-
, Nav.pushUrl model.key route
|
|
262
|
+
, Nav.pushUrl model.key (Page.href model.site route)
|
|
266
263
|
)
|
|
267
264
|
|
|
268
265
|
_ ->
|
|
@@ -446,7 +443,7 @@ update msg model =
|
|
|
446
443
|
Just page ->
|
|
447
444
|
( { model | pageCopied = True }
|
|
448
445
|
, Cmd.batch
|
|
449
|
-
[ Ports.copyMarkdown (Page.
|
|
446
|
+
[ Ports.copyMarkdown (Page.markdownHref model.site page)
|
|
450
447
|
, Process.sleep 1200
|
|
451
448
|
|> Task.perform (\_ -> PageCopyReset)
|
|
452
449
|
]
|
|
@@ -504,22 +501,29 @@ update msg model =
|
|
|
504
501
|
else
|
|
505
502
|
( model, Cmd.none )
|
|
506
503
|
|
|
507
|
-
ScrolledTo _ ->
|
|
508
|
-
( model, Cmd.none )
|
|
509
|
-
|
|
510
504
|
Noop ->
|
|
511
505
|
( model, Cmd.none )
|
|
512
506
|
|
|
513
507
|
|
|
514
508
|
subscriptions : Model -> Sub Msg
|
|
515
509
|
subscriptions model =
|
|
510
|
+
let
|
|
511
|
+
header =
|
|
512
|
+
model.site.chrome.header
|
|
513
|
+
|
|
514
|
+
shell =
|
|
515
|
+
model.error == Nothing
|
|
516
|
+
|
|
517
|
+
docsSwitcher =
|
|
518
|
+
shell && header.docs && List.length model.site.docs > 1
|
|
519
|
+
in
|
|
516
520
|
Sub.batch
|
|
517
521
|
[ Sub.map SearchMsg (Ui.Search.subscriptions model.search)
|
|
518
522
|
, Sub.map BurgerMsg (Ui.Burger.subscriptions model.burger)
|
|
519
|
-
, Sub.map DocsTabsMsg (Ui.Tabs.subscriptions
|
|
520
|
-
, Sub.map MenuDocsTabsMsg (Ui.Tabs.subscriptions model.burger.open model.menuDocsTabs)
|
|
521
|
-
, Sub.map ThemeTabsMsg (Ui.Tabs.subscriptions
|
|
522
|
-
, Sub.map MenuTabsMsg (Ui.Tabs.subscriptions model.burger.open model.menuTabs)
|
|
523
|
+
, Sub.map DocsTabsMsg (Ui.Tabs.subscriptions docsSwitcher model.docsTabs)
|
|
524
|
+
, Sub.map MenuDocsTabsMsg (Ui.Tabs.subscriptions (model.burger.open && docsSwitcher) model.menuDocsTabs)
|
|
525
|
+
, Sub.map ThemeTabsMsg (Ui.Tabs.subscriptions (shell && header.theme) model.themeTabs)
|
|
526
|
+
, Sub.map MenuTabsMsg (Ui.Tabs.subscriptions (model.burger.open && shell && header.theme) model.menuTabs)
|
|
523
527
|
, Ui.Dropdown.subscriptions "ai-dropdown" model.aiOpen AiToggled
|
|
524
528
|
, Ports.onScroll Scrolled
|
|
525
529
|
, Browser.Events.onKeyDown searchShortcutKey
|
|
@@ -699,7 +703,7 @@ pageUrl : Model -> String
|
|
|
699
703
|
pageUrl model =
|
|
700
704
|
case model.page of
|
|
701
705
|
Just page ->
|
|
702
|
-
origin model ++ Page.
|
|
706
|
+
origin model ++ Page.markdownHref model.site page
|
|
703
707
|
|
|
704
708
|
Nothing ->
|
|
705
709
|
origin model
|
|
@@ -840,13 +844,17 @@ setMeta model =
|
|
|
840
844
|
|> Maybe.map (\item -> String.join ", " item.tags)
|
|
841
845
|
|> Maybe.withDefault ""
|
|
842
846
|
, url =
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
847
|
+
Page.href model.site
|
|
848
|
+
(page
|
|
849
|
+
|> Maybe.map .route
|
|
850
|
+
|> Maybe.withDefault "/"
|
|
851
|
+
)
|
|
846
852
|
, image =
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
853
|
+
Page.href model.site
|
|
854
|
+
(page
|
|
855
|
+
|> Maybe.map ogPath
|
|
856
|
+
|> Maybe.withDefault "/og/index.png"
|
|
857
|
+
)
|
|
850
858
|
}
|
|
851
859
|
|
|
852
860
|
|
|
@@ -915,7 +923,7 @@ docNavigation model before after =
|
|
|
915
923
|
of
|
|
916
924
|
Just doc ->
|
|
917
925
|
if doc.id /= model.doc.id then
|
|
918
|
-
Nav.pushUrl model.key doc.root
|
|
926
|
+
Nav.pushUrl model.key (Page.href model.site doc.root)
|
|
919
927
|
|
|
920
928
|
else
|
|
921
929
|
Cmd.none
|
|
@@ -1218,30 +1226,6 @@ closeBurger burger =
|
|
|
1218
1226
|
burger
|
|
1219
1227
|
|
|
1220
1228
|
|
|
1221
|
-
normalize : String -> String
|
|
1222
|
-
normalize path =
|
|
1223
|
-
if String.length path > 1 && String.endsWith "/" path then
|
|
1224
|
-
String.dropRight 1 path
|
|
1225
|
-
|
|
1226
|
-
else if path == "" then
|
|
1227
|
-
"/"
|
|
1228
|
-
|
|
1229
|
-
else
|
|
1230
|
-
path
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
scrollTo : Url -> Cmd Msg
|
|
1234
|
-
scrollTo url =
|
|
1235
|
-
case url.fragment of
|
|
1236
|
-
Just id ->
|
|
1237
|
-
Dom.getElement id
|
|
1238
|
-
|> Task.andThen (\element -> Dom.setViewport 0 element.element.y)
|
|
1239
|
-
|> Task.attempt ScrolledTo
|
|
1240
|
-
|
|
1241
|
-
Nothing ->
|
|
1242
|
-
Dom.setViewport 0 0 |> Task.attempt ScrolledTo
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
1229
|
emptySite : Site
|
|
1246
1230
|
emptySite =
|
|
1247
1231
|
{ meta =
|
|
@@ -1272,4 +1256,5 @@ emptySite =
|
|
|
1272
1256
|
, toolbar = { copy = True, openIn = True }
|
|
1273
1257
|
, footer = { enabled = False, text = "Gem", blurb = "", chips = [], columns = [], eof = False }
|
|
1274
1258
|
}
|
|
1259
|
+
, base = "/"
|
|
1275
1260
|
}
|
package/src/app/Gem/Shell.elm
CHANGED
|
@@ -191,14 +191,14 @@ header config =
|
|
|
191
191
|
]
|
|
192
192
|
]
|
|
193
193
|
([ if chrome.logo then
|
|
194
|
-
Html.a [ A.class "docs-header-title", A.href config.doc.root ]
|
|
195
|
-
[ logoView config
|
|
194
|
+
Html.a [ A.class "docs-header-title", A.href (Page.href config.site config.doc.root) ]
|
|
195
|
+
[ logoView config ]
|
|
196
196
|
|
|
197
197
|
else
|
|
198
198
|
Html.text ""
|
|
199
199
|
]
|
|
200
200
|
++ [ Html.div [ A.class "docs-header-end" ]
|
|
201
|
-
(List.map headerAction chrome.actions
|
|
201
|
+
(List.map (headerAction config) chrome.actions
|
|
202
202
|
++ [ if chrome.search then
|
|
203
203
|
searchToggle config
|
|
204
204
|
|
|
@@ -242,8 +242,8 @@ searchToggle config =
|
|
|
242
242
|
[ Ui.Icon.view Ui.Icon.Search ]
|
|
243
243
|
|
|
244
244
|
|
|
245
|
-
headerAction : { label : String, href : String } -> Html msg
|
|
246
|
-
headerAction action =
|
|
245
|
+
headerAction : Config msg -> { label : String, href : String } -> Html msg
|
|
246
|
+
headerAction config action =
|
|
247
247
|
Ui.Button.viewLink
|
|
248
248
|
{ label = action.label
|
|
249
249
|
, variant = Ui.Button.Secondary
|
|
@@ -253,18 +253,37 @@ headerAction action =
|
|
|
253
253
|
, icon = Nothing
|
|
254
254
|
, attributes = [ A.class "docs-header-action" ]
|
|
255
255
|
}
|
|
256
|
-
action.href
|
|
256
|
+
(Page.href config.site action.href)
|
|
257
257
|
|
|
258
258
|
|
|
259
|
-
{-| A site brand: its configured logo image
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
{-| A site brand: its configured logo image, its configured logo text, or
|
|
260
|
+
both. The image and the wordmark are the same nodes in the bar and the
|
|
261
|
+
drawer; each context sizes them.
|
|
262
262
|
-}
|
|
263
|
-
logoView :
|
|
264
|
-
logoView
|
|
263
|
+
logoView : Config msg -> Html msg
|
|
264
|
+
logoView config =
|
|
265
|
+
let
|
|
266
|
+
logo =
|
|
267
|
+
config.site.meta.logo
|
|
268
|
+
|
|
269
|
+
label =
|
|
270
|
+
if String.isEmpty logo then
|
|
271
|
+
config.site.meta.title
|
|
272
|
+
|
|
273
|
+
else
|
|
274
|
+
logo
|
|
275
|
+
|
|
276
|
+
wordmark =
|
|
277
|
+
if String.isEmpty logo then
|
|
278
|
+
[]
|
|
279
|
+
|
|
280
|
+
else
|
|
281
|
+
[ Html.span [ A.class "site-brand-text" ] [ Html.text logo ] ]
|
|
282
|
+
in
|
|
265
283
|
case config.site.meta.logoImage of
|
|
266
284
|
Just src ->
|
|
267
|
-
Html.
|
|
285
|
+
Html.span [ A.class "site-brand" ]
|
|
286
|
+
(Html.node "img" [ A.class "site-logo", A.src (Page.href config.site src), A.alt label ] [] :: wordmark)
|
|
268
287
|
|
|
269
288
|
Nothing ->
|
|
270
289
|
Html.text label
|
|
@@ -289,7 +308,7 @@ footerView config =
|
|
|
289
308
|
, Html.ul []
|
|
290
309
|
(List.map
|
|
291
310
|
(\link ->
|
|
292
|
-
Html.li [] [ Html.a [ A.href link.href ] [ Html.text link.label ] ]
|
|
311
|
+
Html.li [] [ Html.a [ A.href (Page.href config.site link.href) ] [ Html.text link.label ] ]
|
|
293
312
|
)
|
|
294
313
|
view_.links
|
|
295
314
|
)
|
|
@@ -448,8 +467,8 @@ navItem : Config msg -> String -> String -> Ui.Sidebar.Item msg
|
|
|
448
467
|
navItem config label route =
|
|
449
468
|
{ label = label
|
|
450
469
|
, icon = Nothing
|
|
451
|
-
, target = Ui.Sidebar.Href route
|
|
452
|
-
, active = isActive config
|
|
470
|
+
, target = Ui.Sidebar.Href (Page.href config.site route)
|
|
471
|
+
, active = isActive config route
|
|
453
472
|
}
|
|
454
473
|
|
|
455
474
|
|
|
@@ -462,7 +481,7 @@ pageView config =
|
|
|
462
481
|
[ Ui.Toolbar.view { title = "Not found", actions = [], attributes = [] }
|
|
463
482
|
, Html.p [ A.class "md-p" ]
|
|
464
483
|
[ Html.text "There is no page at this address. "
|
|
465
|
-
, Html.a [ A.class "md-link", A.href config.doc.root ] [ Html.text "Back to the introduction" ]
|
|
484
|
+
, Html.a [ A.class "md-link", A.href (Page.href config.site config.doc.root) ] [ Html.text "Back to the introduction" ]
|
|
466
485
|
, Html.text "."
|
|
467
486
|
]
|
|
468
487
|
]
|
|
@@ -482,7 +501,7 @@ pageView config =
|
|
|
482
501
|
++ lede page
|
|
483
502
|
++ [ pageActions config ]
|
|
484
503
|
++ [ Html.div [ A.class "md" ]
|
|
485
|
-
(Render.
|
|
504
|
+
(Render.blocksWithHref (Page.href config.site) config.slots config.codeView page.blocks)
|
|
486
505
|
]
|
|
487
506
|
++ [ pageTail config page ]
|
|
488
507
|
++ [ pager config page ]
|
|
@@ -598,27 +617,37 @@ eofBand config page =
|
|
|
598
617
|
]
|
|
599
618
|
|
|
600
619
|
|
|
601
|
-
{-| The page's markdown URL: absolute when the site declares an origin
|
|
602
|
-
|
|
620
|
+
{-| The page's markdown URL: absolute when the site declares an origin
|
|
621
|
+
(origin only — any path, query or fragment in `site.url` is ignored, matching
|
|
622
|
+
the build), and relative so it still works in dev and under a base when it
|
|
623
|
+
doesn't.
|
|
603
624
|
-}
|
|
604
625
|
pageMarkdownUrl : Config msg -> Page -> String
|
|
605
626
|
pageMarkdownUrl config page =
|
|
606
627
|
let
|
|
628
|
+
markdown =
|
|
629
|
+
Page.markdownHref config.site page
|
|
630
|
+
|
|
607
631
|
raw =
|
|
608
632
|
String.trim config.site.meta.url
|
|
609
633
|
|
|
610
|
-
|
|
611
|
-
if String.
|
|
612
|
-
|
|
634
|
+
candidate =
|
|
635
|
+
if String.contains "://" raw then
|
|
636
|
+
raw
|
|
613
637
|
|
|
614
638
|
else
|
|
615
|
-
raw
|
|
639
|
+
"https://" ++ raw
|
|
616
640
|
in
|
|
617
|
-
if String.isEmpty
|
|
618
|
-
|
|
641
|
+
if String.isEmpty raw then
|
|
642
|
+
markdown
|
|
619
643
|
|
|
620
644
|
else
|
|
621
|
-
|
|
645
|
+
case Url.fromString candidate of
|
|
646
|
+
Just parsed ->
|
|
647
|
+
Url.toString { parsed | path = "", query = Nothing, fragment = Nothing } ++ markdown
|
|
648
|
+
|
|
649
|
+
Nothing ->
|
|
650
|
+
markdown
|
|
622
651
|
|
|
623
652
|
|
|
624
653
|
tocView : Config msg -> Page -> Html msg
|
|
@@ -842,17 +871,17 @@ pager config page =
|
|
|
842
871
|
|
|
843
872
|
else
|
|
844
873
|
Ui.PageNav.view
|
|
845
|
-
{ previous = Maybe.map pageNavItem previous
|
|
846
|
-
, next = Maybe.map pageNavItem next
|
|
874
|
+
{ previous = Maybe.map (pageNavItem config) previous
|
|
875
|
+
, next = Maybe.map (pageNavItem config) next
|
|
847
876
|
, attributes = []
|
|
848
877
|
}
|
|
849
878
|
|
|
850
879
|
|
|
851
|
-
pageNavItem : Page.Entry -> Ui.PageNav.Item
|
|
852
|
-
pageNavItem entry =
|
|
880
|
+
pageNavItem : Config msg -> Page.Entry -> Ui.PageNav.Item
|
|
881
|
+
pageNavItem config entry =
|
|
853
882
|
{ title = entry.title
|
|
854
883
|
, description = entry.summary
|
|
855
|
-
, href = entry.route
|
|
884
|
+
, href = Page.href config.site entry.route
|
|
856
885
|
}
|
|
857
886
|
|
|
858
887
|
|
|
@@ -883,26 +912,9 @@ itemAt index items =
|
|
|
883
912
|
items |> List.drop index |> List.head
|
|
884
913
|
|
|
885
914
|
|
|
886
|
-
isActive :
|
|
887
|
-
isActive
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
normalize : String -> String
|
|
892
|
-
normalize path =
|
|
893
|
-
let
|
|
894
|
-
trimmed =
|
|
895
|
-
if String.length path > 1 && String.endsWith "/" path then
|
|
896
|
-
String.dropRight 1 path
|
|
897
|
-
|
|
898
|
-
else
|
|
899
|
-
path
|
|
900
|
-
in
|
|
901
|
-
if trimmed == "" then
|
|
902
|
-
"/"
|
|
903
|
-
|
|
904
|
-
else
|
|
905
|
-
trimmed
|
|
915
|
+
isActive : Config msg -> String -> Bool
|
|
916
|
+
isActive config route =
|
|
917
|
+
Page.routeOf config.site config.url.path == route
|
|
906
918
|
|
|
907
919
|
|
|
908
920
|
drawer : Config msg -> Html msg
|
|
@@ -910,7 +922,7 @@ drawer config =
|
|
|
910
922
|
Ui.Burger.view
|
|
911
923
|
{ label = "Menu"
|
|
912
924
|
, logo =
|
|
913
|
-
Just (Html.span [ A.class "burger-wordmark" ] [ logoView config
|
|
925
|
+
Just (Html.span [ A.class "burger-wordmark" ] [ logoView config ])
|
|
914
926
|
, header =
|
|
915
927
|
Just
|
|
916
928
|
(Html.div [ A.class "burger-panel" ]
|
package/src/core/Gem/Page.elm
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module Gem.Page exposing (Chrome, ChromeLink, ChromeColumn, Color, Doc, Entry, FooterConfig, HeaderConfig, Heading, Meta, NavItem(..), Page, Section, Site, ToolbarConfig, byRoute, doc, docFor, markdownPath, nav, page, site)
|
|
1
|
+
module Gem.Page exposing (Chrome, ChromeLink, ChromeColumn, Color, Doc, Entry, FooterConfig, HeaderConfig, Heading, Meta, NavItem(..), Page, Section, Site, ToolbarConfig, byRoute, doc, docFor, href, markdownHref, markdownPath, nav, page, routeOf, site)
|
|
2
2
|
|
|
3
3
|
{-| Site, page and navigation decoders. The compiler's JSON lands here and
|
|
4
4
|
nowhere else, so this module is the schema in Elm form.
|
|
@@ -163,7 +163,8 @@ type alias Doc =
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
|
|
166
|
-
{-| Everything the shell needs, decoded once at boot.
|
|
166
|
+
{-| Everything the shell needs, decoded once at boot. `base` is the deployment
|
|
167
|
+
mount path (`"/"` or `"/sub/"`); route IDs and the filesystem stay base-free.
|
|
167
168
|
-}
|
|
168
169
|
type alias Site =
|
|
169
170
|
{ meta : Meta
|
|
@@ -174,6 +175,7 @@ type alias Site =
|
|
|
174
175
|
, theme : String
|
|
175
176
|
, themeSystem : Bool
|
|
176
177
|
, chrome : Chrome
|
|
178
|
+
, base : String
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
|
|
@@ -181,28 +183,177 @@ type alias Site =
|
|
|
181
183
|
-}
|
|
182
184
|
site : D.Decoder Site
|
|
183
185
|
site =
|
|
184
|
-
D.
|
|
185
|
-
(
|
|
186
|
-
|
|
187
|
-
(D.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
186
|
+
D.map2
|
|
187
|
+
(\build baseRaw -> build (normalizeBase baseRaw))
|
|
188
|
+
(D.map8 Site
|
|
189
|
+
(D.map8 Meta
|
|
190
|
+
(D.at [ "site", "title" ] D.string)
|
|
191
|
+
(D.at [ "site", "description" ] D.string)
|
|
192
|
+
(D.at [ "site", "url" ] D.string)
|
|
193
|
+
(D.at [ "site", "lang" ] D.string)
|
|
194
|
+
(D.at [ "site", "logo" ] D.string)
|
|
195
|
+
(D.oneOf [ D.at [ "site", "logoImage" ] (D.nullable D.string), D.succeed Nothing ])
|
|
196
|
+
(D.at [ "site", "footer" ] (D.nullable D.string))
|
|
197
|
+
(D.oneOf [ D.at [ "site", "editUrl" ] (D.nullable D.string), D.succeed Nothing ])
|
|
198
|
+
)
|
|
199
|
+
(D.field "pages" (D.list page) |> D.map pagesByRoute)
|
|
200
|
+
(D.field "docs" (D.list doc))
|
|
201
|
+
(D.field "search" (D.list entry))
|
|
202
|
+
(D.field "colors" (D.list color))
|
|
203
|
+
(D.oneOf
|
|
204
|
+
[ D.at [ "theme", "mode" ] D.string
|
|
205
|
+
, D.succeed "dark"
|
|
206
|
+
]
|
|
207
|
+
)
|
|
208
|
+
(D.oneOf [ D.at [ "theme", "system" ] D.bool, D.succeed False ])
|
|
209
|
+
(D.at [ "chrome" ] chrome)
|
|
203
210
|
)
|
|
204
|
-
(D.oneOf [ D.
|
|
205
|
-
|
|
211
|
+
(D.oneOf [ D.field "base" D.string, D.succeed "/" ])
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
{-| A base path normalized to `"/"` or `"/sub/"`, matching the compiler's
|
|
215
|
+
`normalizeBase`: an absolute `http(s)` URL collapses to its pathname, a query or
|
|
216
|
+
fragment is dropped, and repeated, leading and trailing slashes collapse.
|
|
217
|
+
-}
|
|
218
|
+
normalizeBase : String -> String
|
|
219
|
+
normalizeBase raw =
|
|
220
|
+
let
|
|
221
|
+
trimmed =
|
|
222
|
+
String.trim raw
|
|
223
|
+
in
|
|
224
|
+
if String.isEmpty trimmed || trimmed == "/" then
|
|
225
|
+
"/"
|
|
226
|
+
|
|
227
|
+
else
|
|
228
|
+
let
|
|
229
|
+
pathOnly =
|
|
230
|
+
if isHttpUrl trimmed then
|
|
231
|
+
urlPath trimmed
|
|
232
|
+
|
|
233
|
+
else
|
|
234
|
+
trimmed
|
|
235
|
+
|
|
236
|
+
clean =
|
|
237
|
+
before "#" (before "?" pathOnly)
|
|
238
|
+
|
|
239
|
+
segments =
|
|
240
|
+
clean
|
|
241
|
+
|> String.split "/"
|
|
242
|
+
|> List.filter (\segment -> not (String.isEmpty segment))
|
|
243
|
+
in
|
|
244
|
+
if List.isEmpty segments then
|
|
245
|
+
"/"
|
|
246
|
+
|
|
247
|
+
else
|
|
248
|
+
"/" ++ String.join "/" segments ++ "/"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
{-| Whether a string is an absolute `http(s)` URL. A protocol-relative
|
|
252
|
+
`//host/path` is deliberately not treated as one, matching the compiler.
|
|
253
|
+
-}
|
|
254
|
+
isHttpUrl : String -> Bool
|
|
255
|
+
isHttpUrl value =
|
|
256
|
+
let
|
|
257
|
+
lower =
|
|
258
|
+
String.toLower value
|
|
259
|
+
in
|
|
260
|
+
String.startsWith "http://" lower || String.startsWith "https://" lower
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
{-| The path portion of an absolute URL, from the first slash after the
|
|
264
|
+
authority; `"https://cdn.example/sub/x"` becomes `"/sub/x"`.
|
|
265
|
+
-}
|
|
266
|
+
urlPath : String -> String
|
|
267
|
+
urlPath url =
|
|
268
|
+
let
|
|
269
|
+
afterScheme =
|
|
270
|
+
String.split "://" url |> List.drop 1 |> String.join "://"
|
|
271
|
+
|
|
272
|
+
pathParts =
|
|
273
|
+
String.split "/" afterScheme |> List.drop 1
|
|
274
|
+
in
|
|
275
|
+
"/" ++ String.join "/" pathParts
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
{-| The part of a string before the first marker, so `before "?"` drops a query.
|
|
279
|
+
-}
|
|
280
|
+
before : String -> String -> String
|
|
281
|
+
before marker text =
|
|
282
|
+
text
|
|
283
|
+
|> String.split marker
|
|
284
|
+
|> List.head
|
|
285
|
+
|> Maybe.withDefault ""
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
{-| The route a browser path belongs to: strip the deployment base, then
|
|
289
|
+
normalize. `"/deploy/guides/install"` becomes `"/guides/install"`; the base
|
|
290
|
+
root becomes `"/"`; a path outside the base is returned unchanged.
|
|
291
|
+
-}
|
|
292
|
+
routeOf : Site -> String -> String
|
|
293
|
+
routeOf site_ path =
|
|
294
|
+
let
|
|
295
|
+
basePath =
|
|
296
|
+
site_.base
|
|
297
|
+
|
|
298
|
+
withoutBase =
|
|
299
|
+
if basePath == "/" then
|
|
300
|
+
path
|
|
301
|
+
|
|
302
|
+
else if String.startsWith basePath path then
|
|
303
|
+
"/" ++ String.dropLeft (String.length basePath) path
|
|
304
|
+
|
|
305
|
+
else if path ++ "/" == basePath then
|
|
306
|
+
"/"
|
|
307
|
+
|
|
308
|
+
else
|
|
309
|
+
path
|
|
310
|
+
in
|
|
311
|
+
normalizeRoute withoutBase
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
{-| Prefix an internal, root-absolute URL with the deployment base. Inputs are
|
|
315
|
+
base-free route IDs, markdown paths or OG paths, so `/docs/guides` under base
|
|
316
|
+
`/docs/` becomes `/docs/docs/guides`. External schemes, protocol-relative URLs
|
|
317
|
+
(`//host/...`), fragments and relative paths pass through unchanged. The `//`
|
|
318
|
+
exclusion is the only idempotence guard; callers must not pass a value that
|
|
319
|
+
already contains the base.
|
|
320
|
+
-}
|
|
321
|
+
href : Site -> String -> String
|
|
322
|
+
href site_ value =
|
|
323
|
+
let
|
|
324
|
+
basePath =
|
|
325
|
+
site_.base
|
|
326
|
+
in
|
|
327
|
+
if basePath == "/" || not (isRootAbsolute value) then
|
|
328
|
+
value
|
|
329
|
+
|
|
330
|
+
else
|
|
331
|
+
String.dropRight 1 basePath ++ value
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
{-| A page's markdown twin URL under the deployment base. The file itself is
|
|
335
|
+
base-free on disk (`markdownPath`); this is its deployed address.
|
|
336
|
+
-}
|
|
337
|
+
markdownHref : Site -> Page -> String
|
|
338
|
+
markdownHref site_ target =
|
|
339
|
+
href site_ (markdownPath target)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
isRootAbsolute : String -> Bool
|
|
343
|
+
isRootAbsolute value =
|
|
344
|
+
String.startsWith "/" value && not (String.startsWith "//" value)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
normalizeRoute : String -> String
|
|
348
|
+
normalizeRoute path =
|
|
349
|
+
if path == "" then
|
|
350
|
+
"/"
|
|
351
|
+
|
|
352
|
+
else if String.length path > 1 && String.endsWith "/" path then
|
|
353
|
+
String.dropRight 1 path
|
|
354
|
+
|
|
355
|
+
else
|
|
356
|
+
path
|
|
206
357
|
|
|
207
358
|
|
|
208
359
|
chrome : D.Decoder Chrome
|