mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-01 16:36:19 +03:00
Add some codecs.
This commit is contained in:
parent
2fe09bb0eb
commit
432587ba05
@ -9,6 +9,7 @@
|
|||||||
"elm-version": "0.19.1",
|
"elm-version": "0.19.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"direct": {
|
"direct": {
|
||||||
|
"MartinSStewart/elm-serialize": "1.2.5",
|
||||||
"avh4/elm-color": "1.0.0",
|
"avh4/elm-color": "1.0.0",
|
||||||
"danyx23/elm-mimetype": "4.0.1",
|
"danyx23/elm-mimetype": "4.0.1",
|
||||||
"dillonkearns/elm-bcp47-language-tag": "1.0.1",
|
"dillonkearns/elm-bcp47-language-tag": "1.0.1",
|
||||||
@ -36,7 +37,9 @@
|
|||||||
"zwilias/json-decode-exploration": "6.0.0"
|
"zwilias/json-decode-exploration": "6.0.0"
|
||||||
},
|
},
|
||||||
"indirect": {
|
"indirect": {
|
||||||
|
"bburdette/toop": "1.0.1",
|
||||||
"billstclair/elm-xml-eeue56": "2.0.0",
|
"billstclair/elm-xml-eeue56": "2.0.0",
|
||||||
|
"danfishgold/base64-bytes": "1.1.0",
|
||||||
"dmy/elm-imf-date-time": "1.0.1",
|
"dmy/elm-imf-date-time": "1.0.1",
|
||||||
"elm/bytes": "1.0.8",
|
"elm/bytes": "1.0.8",
|
||||||
"elm/file": "1.0.5",
|
"elm/file": "1.0.5",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module DocsSection exposing (Section, all)
|
module DocsSection exposing (Section, all, codec)
|
||||||
|
|
||||||
|
import Codec exposing (Codec)
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.Glob as Glob
|
import DataSource.Glob as Glob
|
||||||
|
|
||||||
@ -11,6 +12,16 @@ type alias Section =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
codec : Codec (List Section)
|
||||||
|
codec =
|
||||||
|
Codec.object Section
|
||||||
|
|> Codec.field "filePath" .filePath Codec.string
|
||||||
|
|> Codec.field "order" .order Codec.int
|
||||||
|
|> Codec.field "slug" .slug Codec.string
|
||||||
|
|> Codec.buildObject
|
||||||
|
|> Codec.list
|
||||||
|
|
||||||
|
|
||||||
all : DataSource (List Section)
|
all : DataSource (List Section)
|
||||||
all =
|
all =
|
||||||
Glob.succeed Section
|
Glob.succeed Section
|
||||||
|
@ -3,6 +3,7 @@ module NextPrevious exposing (..)
|
|||||||
import Css
|
import Css
|
||||||
import Html.Styled exposing (..)
|
import Html.Styled exposing (..)
|
||||||
import Html.Styled.Attributes as Attr exposing (css)
|
import Html.Styled.Attributes as Attr exposing (css)
|
||||||
|
import Serialize as S
|
||||||
import Svg.Styled exposing (path, svg)
|
import Svg.Styled exposing (path, svg)
|
||||||
import Svg.Styled.Attributes as SvgAttr
|
import Svg.Styled.Attributes as SvgAttr
|
||||||
import Tailwind.Utilities as Tw
|
import Tailwind.Utilities as Tw
|
||||||
@ -12,6 +13,14 @@ type alias Item =
|
|||||||
{ title : String, url : String }
|
{ title : String, url : String }
|
||||||
|
|
||||||
|
|
||||||
|
serialize : S.Codec Never { title : String, url : String }
|
||||||
|
serialize =
|
||||||
|
S.record Item
|
||||||
|
|> S.field .title S.string
|
||||||
|
|> S.field .url S.string
|
||||||
|
|> S.finishRecord
|
||||||
|
|
||||||
|
|
||||||
view : ( Maybe Item, Maybe Item ) -> Html msg
|
view : ( Maybe Item, Maybe Item ) -> Html msg
|
||||||
view ( maybeLeft, maybeRight ) =
|
view ( maybeLeft, maybeRight ) =
|
||||||
div
|
div
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module TableOfContents exposing (..)
|
module TableOfContents exposing (..)
|
||||||
|
|
||||||
|
import Codec exposing (Codec)
|
||||||
import Css
|
import Css
|
||||||
import DataSource exposing (DataSource)
|
import DataSource exposing (DataSource)
|
||||||
import DataSource.File
|
import DataSource.File
|
||||||
@ -9,6 +10,7 @@ import List.Extra
|
|||||||
import Markdown.Block as Block exposing (Block, Inline)
|
import Markdown.Block as Block exposing (Block, Inline)
|
||||||
import Markdown.Parser
|
import Markdown.Parser
|
||||||
import OptimizedDecoder
|
import OptimizedDecoder
|
||||||
|
import Serialize as S
|
||||||
import Tailwind.Breakpoints as Bp
|
import Tailwind.Breakpoints as Bp
|
||||||
import Tailwind.Utilities as Tw
|
import Tailwind.Utilities as Tw
|
||||||
|
|
||||||
@ -32,6 +34,56 @@ dataSource docFiles =
|
|||||||
|> DataSource.map List.reverse
|
|> DataSource.map List.reverse
|
||||||
|
|
||||||
|
|
||||||
|
codec : Codec (TableOfContents Data)
|
||||||
|
codec =
|
||||||
|
Codec.list entryCodec
|
||||||
|
|
||||||
|
|
||||||
|
entryCodec : Codec (Entry Data)
|
||||||
|
entryCodec =
|
||||||
|
Codec.custom
|
||||||
|
(\vEntry value ->
|
||||||
|
case value of
|
||||||
|
Entry data list ->
|
||||||
|
vEntry data list
|
||||||
|
)
|
||||||
|
|> Codec.variant2 "Entry" Entry dataCodec (Codec.list (Codec.lazy (\() -> entryCodec)))
|
||||||
|
|> Codec.buildCustom
|
||||||
|
|
||||||
|
|
||||||
|
dataCodec : Codec Data
|
||||||
|
dataCodec =
|
||||||
|
Codec.object Data
|
||||||
|
|> Codec.field "anchorId" .anchorId Codec.string
|
||||||
|
|> Codec.field "name" .name Codec.string
|
||||||
|
|> Codec.field "level" .level Codec.int
|
||||||
|
|> Codec.buildObject
|
||||||
|
|
||||||
|
|
||||||
|
serialize : S.Codec e (TableOfContents Data)
|
||||||
|
serialize =
|
||||||
|
S.list serializeEntry
|
||||||
|
|
||||||
|
|
||||||
|
serializeEntry =
|
||||||
|
S.customType
|
||||||
|
(\vEntry value ->
|
||||||
|
case value of
|
||||||
|
Entry data list ->
|
||||||
|
vEntry data list
|
||||||
|
)
|
||||||
|
|> S.variant2 Entry serializeData (S.list (S.lazy (\() -> serializeEntry)))
|
||||||
|
|> S.finishCustomType
|
||||||
|
|
||||||
|
|
||||||
|
serializeData =
|
||||||
|
S.record Data
|
||||||
|
|> S.field .anchorId S.string
|
||||||
|
|> S.field .name S.string
|
||||||
|
|> S.field .level S.int
|
||||||
|
|> S.finishRecord
|
||||||
|
|
||||||
|
|
||||||
headingsDecoder : String -> String -> DataSource (Entry Data)
|
headingsDecoder : String -> String -> DataSource (Entry Data)
|
||||||
headingsDecoder slug rawBody =
|
headingsDecoder slug rawBody =
|
||||||
rawBody
|
rawBody
|
||||||
|
Loading…
Reference in New Issue
Block a user