@charmland/gem 0.0.0-stage → 0.1.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/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 +13652 -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 +1275 -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 +964 -0
- package/src/browser/theme.d.ts +1 -0
- package/src/core/Gem/Node.elm +219 -0
- package/src/core/Gem/Page.elm +409 -0
- package/src/core/Gem/Render.elm +472 -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
module Gem.Node exposing
|
|
2
|
+
( Block(..)
|
|
3
|
+
, Inline(..)
|
|
4
|
+
, Props
|
|
5
|
+
, Token
|
|
6
|
+
, block
|
|
7
|
+
, blocks
|
|
8
|
+
, inline
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
{-| The page node tree.
|
|
12
|
+
|
|
13
|
+
This is the other half of the framework's contract: the compiler writes these
|
|
14
|
+
shapes as JSON, this module decodes them. Nothing here is HTML, which is the
|
|
15
|
+
whole point — Elm cannot inject HTML, so code highlighting, embeds and
|
|
16
|
+
components all have to arrive as structure.
|
|
17
|
+
|
|
18
|
+
Component nodes (`comp`) carry a tag, a flat set of string props and already
|
|
19
|
+
parsed children, so a theme can render them without knowing what they mean.
|
|
20
|
+
|
|
21
|
+
@docs Block, Inline, Props, Token, block, blocks, inline
|
|
22
|
+
|
|
23
|
+
-}
|
|
24
|
+
|
|
25
|
+
import Dict exposing (Dict)
|
|
26
|
+
import Json.Decode as D
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
{-| Attribute values from a component tag. Flat strings on purpose: the tag
|
|
30
|
+
marks up prose, not application state.
|
|
31
|
+
-}
|
|
32
|
+
type alias Props =
|
|
33
|
+
Dict String String
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
{-| One syntax-highlighted run of text. `color` is a CSS color or a
|
|
37
|
+
`var(--shiki-token-*)` reference, so a single compile serves every theme.
|
|
38
|
+
-}
|
|
39
|
+
type alias Token =
|
|
40
|
+
{ text : String
|
|
41
|
+
, color : Maybe String
|
|
42
|
+
, italic : Bool
|
|
43
|
+
, bold : Bool
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
{-| A block-level node.
|
|
48
|
+
-}
|
|
49
|
+
type Block
|
|
50
|
+
= Heading Int String (List Inline)
|
|
51
|
+
| Paragraph (List Inline)
|
|
52
|
+
| CodeBlock { lang : Maybe String, title : Maybe String, lines : List (List Token) }
|
|
53
|
+
| ListBlock { ordered : Bool, start : Int, items : List (List Block) }
|
|
54
|
+
| Quote (List Block)
|
|
55
|
+
| Table { head : List (List Inline), rows : List (List (List Inline)) }
|
|
56
|
+
| Rule
|
|
57
|
+
| Raw String
|
|
58
|
+
| BlockComponent String Props (List Block)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
{-| An inline node.
|
|
62
|
+
-}
|
|
63
|
+
type Inline
|
|
64
|
+
= Text String
|
|
65
|
+
| InlineCode String
|
|
66
|
+
| Strong (List Inline)
|
|
67
|
+
| Em (List Inline)
|
|
68
|
+
| Del (List Inline)
|
|
69
|
+
| Link { href : String, title : Maybe String, external : Bool } (List Inline)
|
|
70
|
+
| Image { src : String, alt : String, title : Maybe String }
|
|
71
|
+
| LineBreak
|
|
72
|
+
| InlineComponent String Props (List Inline)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
{-| Decode a list of block nodes.
|
|
76
|
+
-}
|
|
77
|
+
blocks : D.Decoder (List Block)
|
|
78
|
+
blocks =
|
|
79
|
+
D.list block
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
{-| Decode one block node.
|
|
83
|
+
-}
|
|
84
|
+
block : D.Decoder Block
|
|
85
|
+
block =
|
|
86
|
+
D.field "t" D.string
|
|
87
|
+
|> D.andThen
|
|
88
|
+
(\kind ->
|
|
89
|
+
case kind of
|
|
90
|
+
"heading" ->
|
|
91
|
+
D.map3 Heading
|
|
92
|
+
(D.field "depth" D.int)
|
|
93
|
+
(D.field "id" D.string)
|
|
94
|
+
(D.field "nodes" (D.list inline))
|
|
95
|
+
|
|
96
|
+
"paragraph" ->
|
|
97
|
+
D.map Paragraph (D.field "nodes" (D.list inline))
|
|
98
|
+
|
|
99
|
+
"code" ->
|
|
100
|
+
D.map3
|
|
101
|
+
(\lang title lines ->
|
|
102
|
+
CodeBlock { lang = lang, title = title, lines = lines }
|
|
103
|
+
)
|
|
104
|
+
(D.maybe (D.field "lang" D.string))
|
|
105
|
+
(D.maybe (D.field "title" D.string))
|
|
106
|
+
(D.field "lines" (D.list (D.list token)))
|
|
107
|
+
|
|
108
|
+
"list" ->
|
|
109
|
+
D.map3
|
|
110
|
+
(\ordered start items ->
|
|
111
|
+
ListBlock { ordered = ordered, start = start, items = items }
|
|
112
|
+
)
|
|
113
|
+
(D.field "ordered" D.bool)
|
|
114
|
+
(D.oneOf [ D.field "start" D.int, D.succeed 1 ])
|
|
115
|
+
(D.field "items" (D.list (D.list block)))
|
|
116
|
+
|
|
117
|
+
"quote" ->
|
|
118
|
+
D.map Quote (D.field "nodes" (D.list block))
|
|
119
|
+
|
|
120
|
+
"table" ->
|
|
121
|
+
D.map2
|
|
122
|
+
(\head rows -> Table { head = head, rows = rows })
|
|
123
|
+
(D.field "head" (D.list (D.list inline)))
|
|
124
|
+
(D.field "rows" (D.list (D.list (D.list inline))))
|
|
125
|
+
|
|
126
|
+
"hr" ->
|
|
127
|
+
D.succeed Rule
|
|
128
|
+
|
|
129
|
+
"raw" ->
|
|
130
|
+
D.map Raw (D.field "text" D.string)
|
|
131
|
+
|
|
132
|
+
"comp" ->
|
|
133
|
+
D.map3 BlockComponent
|
|
134
|
+
(D.field "tag" D.string)
|
|
135
|
+
(D.field "props" props)
|
|
136
|
+
(D.field "nodes" (D.list block))
|
|
137
|
+
|
|
138
|
+
_ ->
|
|
139
|
+
D.succeed (Raw "")
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
{-| Decode one inline node.
|
|
144
|
+
-}
|
|
145
|
+
inline : D.Decoder Inline
|
|
146
|
+
inline =
|
|
147
|
+
D.field "t" D.string
|
|
148
|
+
|> D.andThen
|
|
149
|
+
(\kind ->
|
|
150
|
+
case kind of
|
|
151
|
+
"text" ->
|
|
152
|
+
D.map Text (D.field "text" D.string)
|
|
153
|
+
|
|
154
|
+
"code" ->
|
|
155
|
+
D.map InlineCode (D.field "text" D.string)
|
|
156
|
+
|
|
157
|
+
"strong" ->
|
|
158
|
+
D.map Strong (D.field "nodes" (D.list inline))
|
|
159
|
+
|
|
160
|
+
"em" ->
|
|
161
|
+
D.map Em (D.field "nodes" (D.list inline))
|
|
162
|
+
|
|
163
|
+
"del" ->
|
|
164
|
+
D.map Del (D.field "nodes" (D.list inline))
|
|
165
|
+
|
|
166
|
+
"link" ->
|
|
167
|
+
D.map3
|
|
168
|
+
(\href title nodes ->
|
|
169
|
+
Link
|
|
170
|
+
{ href = href
|
|
171
|
+
, title = title
|
|
172
|
+
, external = isExternal href
|
|
173
|
+
}
|
|
174
|
+
nodes
|
|
175
|
+
)
|
|
176
|
+
(D.field "href" D.string)
|
|
177
|
+
(D.maybe (D.field "title" D.string))
|
|
178
|
+
(D.field "nodes" (D.list inline))
|
|
179
|
+
|
|
180
|
+
"img" ->
|
|
181
|
+
D.map3
|
|
182
|
+
(\src alt title -> Image { src = src, alt = alt, title = title })
|
|
183
|
+
(D.field "src" D.string)
|
|
184
|
+
(D.field "alt" D.string)
|
|
185
|
+
(D.maybe (D.field "title" D.string))
|
|
186
|
+
|
|
187
|
+
"br" ->
|
|
188
|
+
D.succeed LineBreak
|
|
189
|
+
|
|
190
|
+
"comp" ->
|
|
191
|
+
D.map3 InlineComponent
|
|
192
|
+
(D.field "tag" D.string)
|
|
193
|
+
(D.field "props" props)
|
|
194
|
+
(D.field "nodes" (D.list inline))
|
|
195
|
+
|
|
196
|
+
_ ->
|
|
197
|
+
D.succeed (Text "")
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
props : D.Decoder Props
|
|
202
|
+
props =
|
|
203
|
+
D.dict D.string
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
token : D.Decoder Token
|
|
207
|
+
token =
|
|
208
|
+
D.map4 Token
|
|
209
|
+
(D.field "text" D.string)
|
|
210
|
+
(D.maybe (D.field "color" D.string))
|
|
211
|
+
(D.oneOf [ D.field "italic" D.bool, D.succeed False ])
|
|
212
|
+
(D.oneOf [ D.field "bold" D.bool, D.succeed False ])
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
isExternal : String -> Bool
|
|
216
|
+
isExternal href =
|
|
217
|
+
String.startsWith "http://" href
|
|
218
|
+
|| String.startsWith "https://" href
|
|
219
|
+
|| String.startsWith "mailto:" href
|
|
@@ -0,0 +1,409 @@
|
|
|
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)
|
|
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.
|
|
167
|
+
-}
|
|
168
|
+
type alias Site =
|
|
169
|
+
{ meta : Meta
|
|
170
|
+
, pages : Dict String Page
|
|
171
|
+
, docs : List Doc
|
|
172
|
+
, entries : List Entry
|
|
173
|
+
, colors : List Color
|
|
174
|
+
, theme : String
|
|
175
|
+
, themeSystem : Bool
|
|
176
|
+
, chrome : Chrome
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
{-| Decode the whole site document.
|
|
181
|
+
-}
|
|
182
|
+
site : D.Decoder Site
|
|
183
|
+
site =
|
|
184
|
+
D.map8 Site
|
|
185
|
+
(D.map8 Meta
|
|
186
|
+
(D.at [ "site", "title" ] D.string)
|
|
187
|
+
(D.at [ "site", "description" ] D.string)
|
|
188
|
+
(D.at [ "site", "url" ] D.string)
|
|
189
|
+
(D.at [ "site", "lang" ] D.string)
|
|
190
|
+
(D.at [ "site", "logo" ] D.string)
|
|
191
|
+
(D.oneOf [ D.at [ "site", "logoImage" ] (D.nullable D.string), D.succeed Nothing ])
|
|
192
|
+
(D.at [ "site", "footer" ] (D.nullable D.string))
|
|
193
|
+
(D.oneOf [ D.at [ "site", "editUrl" ] (D.nullable D.string), D.succeed Nothing ])
|
|
194
|
+
)
|
|
195
|
+
(D.field "pages" (D.list page) |> D.map pagesByRoute)
|
|
196
|
+
(D.field "docs" (D.list doc))
|
|
197
|
+
(D.field "search" (D.list entry))
|
|
198
|
+
(D.field "colors" (D.list color))
|
|
199
|
+
(D.oneOf
|
|
200
|
+
[ D.at [ "theme", "mode" ] D.string
|
|
201
|
+
, D.succeed "dark"
|
|
202
|
+
]
|
|
203
|
+
)
|
|
204
|
+
(D.oneOf [ D.at [ "theme", "system" ] D.bool, D.succeed False ])
|
|
205
|
+
(D.at [ "chrome" ] chrome)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
chrome : D.Decoder Chrome
|
|
209
|
+
chrome =
|
|
210
|
+
D.map3 Chrome
|
|
211
|
+
(D.oneOf
|
|
212
|
+
[ D.field "header" header
|
|
213
|
+
, D.succeed (HeaderConfig True True True True [])
|
|
214
|
+
]
|
|
215
|
+
)
|
|
216
|
+
(D.oneOf
|
|
217
|
+
[ D.field "toolbar" toolbar
|
|
218
|
+
, D.succeed (ToolbarConfig True True)
|
|
219
|
+
]
|
|
220
|
+
)
|
|
221
|
+
(D.oneOf
|
|
222
|
+
[ D.field "footer" footer
|
|
223
|
+
, D.succeed (FooterConfig True "" "" [] [] False)
|
|
224
|
+
]
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
toolbar : D.Decoder ToolbarConfig
|
|
229
|
+
toolbar =
|
|
230
|
+
D.map2 ToolbarConfig
|
|
231
|
+
(D.oneOf [ D.field "copy" D.bool, D.succeed True ])
|
|
232
|
+
(D.oneOf [ D.field "openIn" D.bool, D.succeed True ])
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
header : D.Decoder HeaderConfig
|
|
236
|
+
header =
|
|
237
|
+
D.map5 HeaderConfig
|
|
238
|
+
(D.oneOf [ D.field "logo" D.bool, D.succeed True ])
|
|
239
|
+
(D.oneOf [ D.field "search" D.bool, D.succeed True ])
|
|
240
|
+
(D.oneOf [ D.field "theme" D.bool, D.succeed True ])
|
|
241
|
+
(D.oneOf [ D.field "docs" D.bool, D.succeed True ])
|
|
242
|
+
(D.oneOf [ D.field "actions" (D.list link), D.succeed [] ])
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
footer : D.Decoder FooterConfig
|
|
246
|
+
footer =
|
|
247
|
+
D.map6 FooterConfig
|
|
248
|
+
(D.oneOf [ D.field "enabled" D.bool, D.succeed True ])
|
|
249
|
+
(D.oneOf [ D.field "text" D.string, D.succeed "" ])
|
|
250
|
+
(D.oneOf [ D.field "blurb" D.string, D.succeed "" ])
|
|
251
|
+
(D.oneOf [ D.field "chips" (D.list D.string), D.succeed [] ])
|
|
252
|
+
(D.oneOf
|
|
253
|
+
[ D.field "columns"
|
|
254
|
+
(D.list
|
|
255
|
+
(D.map2 ChromeColumn
|
|
256
|
+
(D.field "heading" D.string)
|
|
257
|
+
(D.oneOf [ D.field "links" (D.list link), D.succeed [] ])
|
|
258
|
+
)
|
|
259
|
+
)
|
|
260
|
+
, D.succeed []
|
|
261
|
+
]
|
|
262
|
+
)
|
|
263
|
+
(D.oneOf [ D.field "eof" D.bool, D.succeed False ])
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
link : D.Decoder ChromeLink
|
|
267
|
+
link =
|
|
268
|
+
D.map2 ChromeLink
|
|
269
|
+
(D.field "label" D.string)
|
|
270
|
+
(D.field "href" D.string)
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
{-| Decode one documentation collection.
|
|
274
|
+
-}
|
|
275
|
+
doc : D.Decoder Doc
|
|
276
|
+
doc =
|
|
277
|
+
D.map5 Doc
|
|
278
|
+
(D.field "id" D.string)
|
|
279
|
+
(D.field "label" D.string)
|
|
280
|
+
(D.field "prefix" D.string)
|
|
281
|
+
(D.field "root" D.string)
|
|
282
|
+
(D.field "nav" (D.list nav))
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
{-| The collection a path belongs to: the one whose prefix owns the path.
|
|
286
|
+
The first collection wins ties, so a site with one collection is always it.
|
|
287
|
+
-}
|
|
288
|
+
docFor : Site -> String -> Doc
|
|
289
|
+
docFor site_ path =
|
|
290
|
+
site_.docs
|
|
291
|
+
|> List.sortBy (\item -> 0 - String.length item.prefix)
|
|
292
|
+
|> List.filter
|
|
293
|
+
(\item ->
|
|
294
|
+
item.root == path
|
|
295
|
+
|| item.root == "/"
|
|
296
|
+
|| String.startsWith (item.prefix ++ "/") path
|
|
297
|
+
)
|
|
298
|
+
|> List.head
|
|
299
|
+
|> Maybe.withDefault (firstDoc site_)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
firstDoc : Site -> Doc
|
|
303
|
+
firstDoc site_ =
|
|
304
|
+
site_.docs
|
|
305
|
+
|> List.head
|
|
306
|
+
|> Maybe.withDefault
|
|
307
|
+
{ id = "docs"
|
|
308
|
+
, label = site_.meta.title
|
|
309
|
+
, prefix = ""
|
|
310
|
+
, root = "/"
|
|
311
|
+
, nav = []
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
{-| Decode one page.
|
|
316
|
+
-}
|
|
317
|
+
page : D.Decoder Page
|
|
318
|
+
page =
|
|
319
|
+
D.field "route" D.string
|
|
320
|
+
|> D.andThen
|
|
321
|
+
(\route ->
|
|
322
|
+
D.map8 (Page route)
|
|
323
|
+
(D.field "slug" D.string)
|
|
324
|
+
(D.field "source" D.string)
|
|
325
|
+
(D.field "title" D.string)
|
|
326
|
+
(D.field "summary" D.string)
|
|
327
|
+
(D.field "description" D.string)
|
|
328
|
+
(D.field "tags" (D.list D.string))
|
|
329
|
+
(D.field "toc" (D.list heading))
|
|
330
|
+
(D.field "tree" Node.blocks)
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
{-| Decode one navigation row.
|
|
335
|
+
-}
|
|
336
|
+
nav : D.Decoder NavItem
|
|
337
|
+
nav =
|
|
338
|
+
D.field "kind" D.string
|
|
339
|
+
|> D.andThen
|
|
340
|
+
(\kind ->
|
|
341
|
+
case kind of
|
|
342
|
+
"category" ->
|
|
343
|
+
D.map4
|
|
344
|
+
(\id label collapsed items ->
|
|
345
|
+
Category
|
|
346
|
+
{ id = id
|
|
347
|
+
, label = label
|
|
348
|
+
, collapsed = collapsed
|
|
349
|
+
, items = items
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
(D.field "id" D.string)
|
|
353
|
+
(D.field "label" D.string)
|
|
354
|
+
(D.field "collapsed" D.bool)
|
|
355
|
+
(D.field "items" (D.list nav))
|
|
356
|
+
|
|
357
|
+
_ ->
|
|
358
|
+
D.map2
|
|
359
|
+
(\route title -> PageItem { route = route, title = title })
|
|
360
|
+
(D.field "route" D.string)
|
|
361
|
+
(D.field "title" D.string)
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
heading : D.Decoder Heading
|
|
366
|
+
heading =
|
|
367
|
+
D.map3 Heading
|
|
368
|
+
(D.field "depth" D.int)
|
|
369
|
+
(D.field "id" D.string)
|
|
370
|
+
(D.field "text" D.string)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
color : D.Decoder Color
|
|
374
|
+
color =
|
|
375
|
+
D.map3 Color
|
|
376
|
+
(D.field "name" D.string)
|
|
377
|
+
(D.maybe (D.field "light" D.string))
|
|
378
|
+
(D.maybe (D.field "dark" D.string))
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
entry : D.Decoder Entry
|
|
382
|
+
entry =
|
|
383
|
+
D.map6 Entry
|
|
384
|
+
(D.field "route" D.string)
|
|
385
|
+
(D.field "title" D.string)
|
|
386
|
+
(D.field "summary" D.string)
|
|
387
|
+
(D.field "tags" (D.list D.string))
|
|
388
|
+
(D.field "text" D.string)
|
|
389
|
+
(D.field "sections" (D.list section))
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
section : D.Decoder Section
|
|
393
|
+
section =
|
|
394
|
+
D.map3 Section
|
|
395
|
+
(D.field "id" D.string)
|
|
396
|
+
(D.field "label" D.string)
|
|
397
|
+
(D.field "text" D.string)
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
pagesByRoute : List Page -> Dict String Page
|
|
401
|
+
pagesByRoute pages =
|
|
402
|
+
List.foldl (\item acc -> Dict.insert item.route item acc) Dict.empty pages
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
{-| Look up the page for a normalized route.
|
|
406
|
+
-}
|
|
407
|
+
byRoute : Site -> String -> Maybe Page
|
|
408
|
+
byRoute site_ route =
|
|
409
|
+
Dict.get route site_.pages
|