@charmland/gem 0.0.0-stage → 0.1.1
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/LICENSE +177 -0
- package/NOTICE +13 -0
- package/README.md +24 -2
- 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/bin/gem-elm.js +3 -0
- package/dist/browser/boot.d.ts +10 -0
- package/dist/browser/boot.js +14 -0
- package/dist/browser/color-scheme.d.ts +9 -0
- package/dist/browser/color-scheme.js +76 -0
- package/dist/browser/ports.d.ts +37 -0
- package/dist/browser/ports.js +90 -0
- package/dist/browser/router.d.ts +5 -0
- package/dist/browser/router.js +35 -0
- package/dist/browser/runtime.d.ts +12 -0
- package/dist/browser/runtime.js +22 -0
- package/dist/browser/tabs.d.ts +9 -0
- package/dist/browser/tabs.js +69 -0
- package/dist/default/theme.css +4664 -0
- package/dist/default/theme.js +13815 -0
- package/dist/node/build.d.ts +16 -0
- package/dist/node/build.js +48 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +21 -0
- package/elm.json +28 -0
- package/package.json +86 -4
- package/src/app/Gem/App.elm +1268 -0
- package/src/app/Gem/CharmSticker.elm +35 -0
- package/src/app/Gem/Components.elm +292 -0
- package/src/app/Gem/Main.elm +17 -0
- package/src/app/Gem/Ports.elm +32 -0
- package/src/app/Gem/Shell.elm +957 -0
- package/src/browser/theme.d.ts +1 -0
- package/src/core/Gem/Node.elm +219 -0
- package/src/core/Gem/Page.elm +560 -0
- package/src/core/Gem/Render.elm +510 -0
- package/src/core/Gem/Slots.elm +11 -0
- package/src/styles/docs.scss +1083 -0
- package/src/styles/fonts.scss +51 -0
- package/src/styles/gem.scss +362 -0
- package/src/styles/theme.scss +8 -0
- package/src/styles/ui/burger.scss +272 -0
- package/src/styles/ui/button.scss +350 -0
- package/src/styles/ui/charmtone.scss +70 -0
- package/src/styles/ui/controls-extra.scss +316 -0
- package/src/styles/ui/controls.scss +110 -0
- package/src/styles/ui/display.scss +359 -0
- package/src/styles/ui/dropdown.scss +341 -0
- package/src/styles/ui/form.scss +314 -0
- package/src/styles/ui/menu.scss +200 -0
- package/src/styles/ui/meter.scss +124 -0
- package/src/styles/ui/modal.scss +545 -0
- package/src/styles/ui/oauth.scss +50 -0
- package/src/styles/ui/page-nav.scss +63 -0
- package/src/styles/ui/reset.scss +111 -0
- package/src/styles/ui/scrollbar.scss +39 -0
- package/src/styles/ui/search.scss +164 -0
- package/src/styles/ui/sidebar.scss +229 -0
- package/src/styles/ui/squircle.scss +60 -0
- package/src/styles/ui/table.scss +97 -0
- package/src/styles/ui/theme.scss +132 -0
- package/src/styles/ui/toast.scss +587 -0
- package/src/styles/ui/toc.scss +128 -0
- package/src/styles/ui/typography.scss +21 -0
- package/src/styles/ui/ui.scss +33 -0
- package/src/ui/Ui/Badge.elm +51 -0
- package/src/ui/Ui/Banner.elm +97 -0
- package/src/ui/Ui/Burger.elm +259 -0
- package/src/ui/Ui/Button.elm +261 -0
- package/src/ui/Ui/Card.elm +32 -0
- package/src/ui/Ui/Cards.elm +15 -0
- package/src/ui/Ui/ChoiceGroup.elm +62 -0
- package/src/ui/Ui/CopyButton.elm +139 -0
- package/src/ui/Ui/Divider.elm +16 -0
- package/src/ui/Ui/Dropdown.elm +600 -0
- package/src/ui/Ui/Empty.elm +41 -0
- package/src/ui/Ui/ErrorBubble.elm +34 -0
- package/src/ui/Ui/Field.elm +45 -0
- package/src/ui/Ui/FormStatus.elm +32 -0
- package/src/ui/Ui/Icon.elm +381 -0
- package/src/ui/Ui/InlineForm.elm +51 -0
- package/src/ui/Ui/Input.elm +113 -0
- package/src/ui/Ui/KeyValue.elm +25 -0
- package/src/ui/Ui/ListRow.elm +67 -0
- package/src/ui/Ui/Loader.elm +32 -0
- package/src/ui/Ui/Logo/Charm.elm +21 -0
- package/src/ui/Ui/Logo/CharmMark.elm +32 -0
- package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
- package/src/ui/Ui/Logo/Discord.elm +26 -0
- package/src/ui/Ui/Logo/GitHub.elm +21 -0
- package/src/ui/Ui/Logo/Google.elm +21 -0
- package/src/ui/Ui/Logo/Hexy.elm +29 -0
- package/src/ui/Ui/Logo/Hyper.elm +42 -0
- package/src/ui/Ui/Logo/Integration.elm +117 -0
- package/src/ui/Ui/Logo/Prism.elm +35 -0
- package/src/ui/Ui/Logos.elm +115 -0
- package/src/ui/Ui/Menu.elm +348 -0
- package/src/ui/Ui/Meter.elm +132 -0
- package/src/ui/Ui/Modal.elm +247 -0
- package/src/ui/Ui/Motion.elm +32 -0
- package/src/ui/Ui/NumberBox.elm +86 -0
- package/src/ui/Ui/OAuthButton.elm +39 -0
- package/src/ui/Ui/PageNav.elm +65 -0
- package/src/ui/Ui/Pager.elm +49 -0
- package/src/ui/Ui/Search.elm +396 -0
- package/src/ui/Ui/SearchBox.elm +78 -0
- package/src/ui/Ui/Section.elm +21 -0
- package/src/ui/Ui/Sidebar.elm +239 -0
- package/src/ui/Ui/Stat.elm +29 -0
- package/src/ui/Ui/Switch.elm +34 -0
- package/src/ui/Ui/Table.elm +89 -0
- package/src/ui/Ui/Tabs.elm +280 -0
- package/src/ui/Ui/ToC.elm +120 -0
- package/src/ui/Ui/Toast.elm +1145 -0
- package/src/ui/Ui/Toolbar.elm +31 -0
- package/src/ui/Ui/TwoStepConfirm.elm +159 -0
- package/src/ui/Ui/Typography.elm +33 -0
|
@@ -0,0 +1,560 @@
|
|
|
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
|
+
|
|
3
|
+
{-| Site, page and navigation decoders. The compiler's JSON lands here and
|
|
4
|
+
nowhere else, so this module is the schema in Elm form.
|
|
5
|
+
-}
|
|
6
|
+
|
|
7
|
+
import Dict exposing (Dict)
|
|
8
|
+
import Gem.Node as Node
|
|
9
|
+
import Json.Decode as D
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
{-| One table-of-contents entry, built from the page's h2-h4 headings.
|
|
13
|
+
-}
|
|
14
|
+
type alias Heading =
|
|
15
|
+
{ depth : Int
|
|
16
|
+
, id : String
|
|
17
|
+
, text : String
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
{-| A rendered page.
|
|
22
|
+
-}
|
|
23
|
+
type alias Page =
|
|
24
|
+
{ route : String
|
|
25
|
+
, slug : String
|
|
26
|
+
, source : String
|
|
27
|
+
, title : String
|
|
28
|
+
, summary : String
|
|
29
|
+
, description : String
|
|
30
|
+
, tags : List String
|
|
31
|
+
, toc : List Heading
|
|
32
|
+
, blocks : List Node.Block
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
{-| Where a page's source markdown is served: the build emits one file per
|
|
37
|
+
route next to the HTML, and dev serves it from the content source.
|
|
38
|
+
-}
|
|
39
|
+
markdownPath : Page -> String
|
|
40
|
+
markdownPath target =
|
|
41
|
+
if target.route == "/" then
|
|
42
|
+
"/index.md"
|
|
43
|
+
|
|
44
|
+
else
|
|
45
|
+
target.route ++ ".md"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
{-| A sidebar row.
|
|
49
|
+
-}
|
|
50
|
+
type NavItem
|
|
51
|
+
= PageItem { route : String, title : String }
|
|
52
|
+
| Category { id : String, label : String, collapsed : Bool, items : List NavItem }
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
{-| One heading's worth of a page, as the search index sees it.
|
|
56
|
+
-}
|
|
57
|
+
type alias Section =
|
|
58
|
+
{ id : String
|
|
59
|
+
, label : String
|
|
60
|
+
, text : String
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
{-| A search index entry: the page, plus its sections.
|
|
65
|
+
-}
|
|
66
|
+
type alias Entry =
|
|
67
|
+
{ route : String
|
|
68
|
+
, title : String
|
|
69
|
+
, summary : String
|
|
70
|
+
, tags : List String
|
|
71
|
+
, text : String
|
|
72
|
+
, sections : List Section
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
{-| One highlighted-token color slot, resolved per theme by the theme itself.
|
|
77
|
+
-}
|
|
78
|
+
type alias Color =
|
|
79
|
+
{ name : String
|
|
80
|
+
, light : Maybe String
|
|
81
|
+
, dark : Maybe String
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
{-| One configurable link: a header action or a footer link.
|
|
86
|
+
-}
|
|
87
|
+
type alias ChromeLink =
|
|
88
|
+
{ label : String
|
|
89
|
+
, href : String
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
{-| One link column in the footer.
|
|
94
|
+
-}
|
|
95
|
+
type alias ChromeColumn =
|
|
96
|
+
{ heading : String
|
|
97
|
+
, links : List ChromeLink
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
{-| What the top bar renders, and in what order.
|
|
102
|
+
-}
|
|
103
|
+
type alias HeaderConfig =
|
|
104
|
+
{ logo : Bool
|
|
105
|
+
, search : Bool
|
|
106
|
+
, theme : Bool
|
|
107
|
+
, docs : Bool
|
|
108
|
+
, actions : List ChromeLink
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
{-| What the footer renders.
|
|
113
|
+
-}
|
|
114
|
+
type alias FooterConfig =
|
|
115
|
+
{ enabled : Bool
|
|
116
|
+
, text : String
|
|
117
|
+
, blurb : String
|
|
118
|
+
, chips : List String
|
|
119
|
+
, columns : List ChromeColumn
|
|
120
|
+
, eof : Bool
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
{-| The page toolbar's optional actions.
|
|
125
|
+
-}
|
|
126
|
+
type alias ToolbarConfig =
|
|
127
|
+
{ copy : Bool
|
|
128
|
+
, openIn : Bool
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
{-| The configurable chrome: top bar, page toolbar and footer.
|
|
133
|
+
-}
|
|
134
|
+
type alias Chrome =
|
|
135
|
+
{ header : HeaderConfig
|
|
136
|
+
, toolbar : ToolbarConfig
|
|
137
|
+
, footer : FooterConfig
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
{-| Site-level metadata: what the head and the top bar need.
|
|
142
|
+
-}
|
|
143
|
+
type alias Meta =
|
|
144
|
+
{ title : String
|
|
145
|
+
, description : String
|
|
146
|
+
, url : String
|
|
147
|
+
, lang : String
|
|
148
|
+
, logo : String
|
|
149
|
+
, logoImage : Maybe String
|
|
150
|
+
, footer : Maybe String
|
|
151
|
+
, editUrl : Maybe String
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
{-| One documentation collection inside the site.
|
|
156
|
+
-}
|
|
157
|
+
type alias Doc =
|
|
158
|
+
{ id : String
|
|
159
|
+
, label : String
|
|
160
|
+
, prefix : String
|
|
161
|
+
, root : String
|
|
162
|
+
, nav : List NavItem
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
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.
|
|
168
|
+
-}
|
|
169
|
+
type alias Site =
|
|
170
|
+
{ meta : Meta
|
|
171
|
+
, pages : Dict String Page
|
|
172
|
+
, docs : List Doc
|
|
173
|
+
, entries : List Entry
|
|
174
|
+
, colors : List Color
|
|
175
|
+
, theme : String
|
|
176
|
+
, themeSystem : Bool
|
|
177
|
+
, chrome : Chrome
|
|
178
|
+
, base : String
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
{-| Decode the whole site document.
|
|
183
|
+
-}
|
|
184
|
+
site : D.Decoder Site
|
|
185
|
+
site =
|
|
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)
|
|
210
|
+
)
|
|
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
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
chrome : D.Decoder Chrome
|
|
360
|
+
chrome =
|
|
361
|
+
D.map3 Chrome
|
|
362
|
+
(D.oneOf
|
|
363
|
+
[ D.field "header" header
|
|
364
|
+
, D.succeed (HeaderConfig True True True True [])
|
|
365
|
+
]
|
|
366
|
+
)
|
|
367
|
+
(D.oneOf
|
|
368
|
+
[ D.field "toolbar" toolbar
|
|
369
|
+
, D.succeed (ToolbarConfig True True)
|
|
370
|
+
]
|
|
371
|
+
)
|
|
372
|
+
(D.oneOf
|
|
373
|
+
[ D.field "footer" footer
|
|
374
|
+
, D.succeed (FooterConfig True "" "" [] [] False)
|
|
375
|
+
]
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
toolbar : D.Decoder ToolbarConfig
|
|
380
|
+
toolbar =
|
|
381
|
+
D.map2 ToolbarConfig
|
|
382
|
+
(D.oneOf [ D.field "copy" D.bool, D.succeed True ])
|
|
383
|
+
(D.oneOf [ D.field "openIn" D.bool, D.succeed True ])
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
header : D.Decoder HeaderConfig
|
|
387
|
+
header =
|
|
388
|
+
D.map5 HeaderConfig
|
|
389
|
+
(D.oneOf [ D.field "logo" D.bool, D.succeed True ])
|
|
390
|
+
(D.oneOf [ D.field "search" D.bool, D.succeed True ])
|
|
391
|
+
(D.oneOf [ D.field "theme" D.bool, D.succeed True ])
|
|
392
|
+
(D.oneOf [ D.field "docs" D.bool, D.succeed True ])
|
|
393
|
+
(D.oneOf [ D.field "actions" (D.list link), D.succeed [] ])
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
footer : D.Decoder FooterConfig
|
|
397
|
+
footer =
|
|
398
|
+
D.map6 FooterConfig
|
|
399
|
+
(D.oneOf [ D.field "enabled" D.bool, D.succeed True ])
|
|
400
|
+
(D.oneOf [ D.field "text" D.string, D.succeed "" ])
|
|
401
|
+
(D.oneOf [ D.field "blurb" D.string, D.succeed "" ])
|
|
402
|
+
(D.oneOf [ D.field "chips" (D.list D.string), D.succeed [] ])
|
|
403
|
+
(D.oneOf
|
|
404
|
+
[ D.field "columns"
|
|
405
|
+
(D.list
|
|
406
|
+
(D.map2 ChromeColumn
|
|
407
|
+
(D.field "heading" D.string)
|
|
408
|
+
(D.oneOf [ D.field "links" (D.list link), D.succeed [] ])
|
|
409
|
+
)
|
|
410
|
+
)
|
|
411
|
+
, D.succeed []
|
|
412
|
+
]
|
|
413
|
+
)
|
|
414
|
+
(D.oneOf [ D.field "eof" D.bool, D.succeed False ])
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
link : D.Decoder ChromeLink
|
|
418
|
+
link =
|
|
419
|
+
D.map2 ChromeLink
|
|
420
|
+
(D.field "label" D.string)
|
|
421
|
+
(D.field "href" D.string)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
{-| Decode one documentation collection.
|
|
425
|
+
-}
|
|
426
|
+
doc : D.Decoder Doc
|
|
427
|
+
doc =
|
|
428
|
+
D.map5 Doc
|
|
429
|
+
(D.field "id" D.string)
|
|
430
|
+
(D.field "label" D.string)
|
|
431
|
+
(D.field "prefix" D.string)
|
|
432
|
+
(D.field "root" D.string)
|
|
433
|
+
(D.field "nav" (D.list nav))
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
{-| The collection a path belongs to: the one whose prefix owns the path.
|
|
437
|
+
The first collection wins ties, so a site with one collection is always it.
|
|
438
|
+
-}
|
|
439
|
+
docFor : Site -> String -> Doc
|
|
440
|
+
docFor site_ path =
|
|
441
|
+
site_.docs
|
|
442
|
+
|> List.sortBy (\item -> 0 - String.length item.prefix)
|
|
443
|
+
|> List.filter
|
|
444
|
+
(\item ->
|
|
445
|
+
item.root == path
|
|
446
|
+
|| item.root == "/"
|
|
447
|
+
|| String.startsWith (item.prefix ++ "/") path
|
|
448
|
+
)
|
|
449
|
+
|> List.head
|
|
450
|
+
|> Maybe.withDefault (firstDoc site_)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
firstDoc : Site -> Doc
|
|
454
|
+
firstDoc site_ =
|
|
455
|
+
site_.docs
|
|
456
|
+
|> List.head
|
|
457
|
+
|> Maybe.withDefault
|
|
458
|
+
{ id = "docs"
|
|
459
|
+
, label = site_.meta.title
|
|
460
|
+
, prefix = ""
|
|
461
|
+
, root = "/"
|
|
462
|
+
, nav = []
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
{-| Decode one page.
|
|
467
|
+
-}
|
|
468
|
+
page : D.Decoder Page
|
|
469
|
+
page =
|
|
470
|
+
D.field "route" D.string
|
|
471
|
+
|> D.andThen
|
|
472
|
+
(\route ->
|
|
473
|
+
D.map8 (Page route)
|
|
474
|
+
(D.field "slug" D.string)
|
|
475
|
+
(D.field "source" D.string)
|
|
476
|
+
(D.field "title" D.string)
|
|
477
|
+
(D.field "summary" D.string)
|
|
478
|
+
(D.field "description" D.string)
|
|
479
|
+
(D.field "tags" (D.list D.string))
|
|
480
|
+
(D.field "toc" (D.list heading))
|
|
481
|
+
(D.field "tree" Node.blocks)
|
|
482
|
+
)
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
{-| Decode one navigation row.
|
|
486
|
+
-}
|
|
487
|
+
nav : D.Decoder NavItem
|
|
488
|
+
nav =
|
|
489
|
+
D.field "kind" D.string
|
|
490
|
+
|> D.andThen
|
|
491
|
+
(\kind ->
|
|
492
|
+
case kind of
|
|
493
|
+
"category" ->
|
|
494
|
+
D.map4
|
|
495
|
+
(\id label collapsed items ->
|
|
496
|
+
Category
|
|
497
|
+
{ id = id
|
|
498
|
+
, label = label
|
|
499
|
+
, collapsed = collapsed
|
|
500
|
+
, items = items
|
|
501
|
+
}
|
|
502
|
+
)
|
|
503
|
+
(D.field "id" D.string)
|
|
504
|
+
(D.field "label" D.string)
|
|
505
|
+
(D.field "collapsed" D.bool)
|
|
506
|
+
(D.field "items" (D.list nav))
|
|
507
|
+
|
|
508
|
+
_ ->
|
|
509
|
+
D.map2
|
|
510
|
+
(\route title -> PageItem { route = route, title = title })
|
|
511
|
+
(D.field "route" D.string)
|
|
512
|
+
(D.field "title" D.string)
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
heading : D.Decoder Heading
|
|
517
|
+
heading =
|
|
518
|
+
D.map3 Heading
|
|
519
|
+
(D.field "depth" D.int)
|
|
520
|
+
(D.field "id" D.string)
|
|
521
|
+
(D.field "text" D.string)
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
color : D.Decoder Color
|
|
525
|
+
color =
|
|
526
|
+
D.map3 Color
|
|
527
|
+
(D.field "name" D.string)
|
|
528
|
+
(D.maybe (D.field "light" D.string))
|
|
529
|
+
(D.maybe (D.field "dark" D.string))
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
entry : D.Decoder Entry
|
|
533
|
+
entry =
|
|
534
|
+
D.map6 Entry
|
|
535
|
+
(D.field "route" D.string)
|
|
536
|
+
(D.field "title" D.string)
|
|
537
|
+
(D.field "summary" D.string)
|
|
538
|
+
(D.field "tags" (D.list D.string))
|
|
539
|
+
(D.field "text" D.string)
|
|
540
|
+
(D.field "sections" (D.list section))
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
section : D.Decoder Section
|
|
544
|
+
section =
|
|
545
|
+
D.map3 Section
|
|
546
|
+
(D.field "id" D.string)
|
|
547
|
+
(D.field "label" D.string)
|
|
548
|
+
(D.field "text" D.string)
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
pagesByRoute : List Page -> Dict String Page
|
|
552
|
+
pagesByRoute pages =
|
|
553
|
+
List.foldl (\item acc -> Dict.insert item.route item acc) Dict.empty pages
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
{-| Look up the page for a normalized route.
|
|
557
|
+
-}
|
|
558
|
+
byRoute : Site -> String -> Maybe Page
|
|
559
|
+
byRoute site_ route =
|
|
560
|
+
Dict.get route site_.pages
|