mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-30 23:06:10 +03:00
Add a simple unstyled showcase.
This commit is contained in:
parent
62f7310ac5
commit
3240f01875
4
examples/docs/content/showcase/index.md
Normal file
4
examples/docs/content/showcase/index.md
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
title: elm-pages sites showcase
|
||||
type: showcase
|
||||
---
|
@ -4,8 +4,8 @@ import Element exposing (Element)
|
||||
import Element.Border as Border
|
||||
import Element.Font
|
||||
import Metadata exposing (Metadata)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Palette
|
||||
|
||||
|
||||
@ -25,19 +25,10 @@ view currentPage posts =
|
||||
|> List.filterMap
|
||||
(\( path, metadata ) ->
|
||||
case metadata of
|
||||
Metadata.Page meta ->
|
||||
Nothing
|
||||
|
||||
Metadata.Article meta ->
|
||||
Nothing
|
||||
|
||||
Metadata.Author _ ->
|
||||
Nothing
|
||||
|
||||
Metadata.Doc meta ->
|
||||
Just ( currentPage == path, path, meta )
|
||||
|
||||
Metadata.BlogIndex ->
|
||||
_ ->
|
||||
Nothing
|
||||
)
|
||||
|> List.map postSummary
|
||||
|
@ -20,15 +20,6 @@ view posts =
|
||||
|> List.filterMap
|
||||
(\( path, metadata ) ->
|
||||
case metadata of
|
||||
Metadata.Page meta ->
|
||||
Nothing
|
||||
|
||||
Metadata.Doc meta ->
|
||||
Nothing
|
||||
|
||||
Metadata.Author _ ->
|
||||
Nothing
|
||||
|
||||
Metadata.Article meta ->
|
||||
if meta.draft then
|
||||
Nothing
|
||||
@ -36,7 +27,7 @@ view posts =
|
||||
else
|
||||
Just ( path, meta )
|
||||
|
||||
Metadata.BlogIndex ->
|
||||
_ ->
|
||||
Nothing
|
||||
)
|
||||
|> List.sortBy
|
||||
|
@ -30,6 +30,7 @@ import Pages.Platform exposing (Page)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Palette
|
||||
import Secrets
|
||||
import Showcase
|
||||
|
||||
|
||||
manifest : Manifest.Config Pages.PathKey
|
||||
@ -113,17 +114,40 @@ view :
|
||||
, head : List (Head.Tag Pages.PathKey)
|
||||
}
|
||||
view siteMetadata page =
|
||||
StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
||||
(D.field "stargazers_count" D.int)
|
||||
|> StaticHttp.map
|
||||
(\stars ->
|
||||
{ view =
|
||||
\model viewForPage ->
|
||||
pageView stars model siteMetadata page viewForPage
|
||||
|> wrapBody
|
||||
, head = head page.frontmatter
|
||||
}
|
||||
)
|
||||
case page.frontmatter of
|
||||
Metadata.Showcase ->
|
||||
StaticHttp.map2
|
||||
(\stars showcaseData ->
|
||||
{ view =
|
||||
\model viewForPage ->
|
||||
{ title = "elm-pages blog"
|
||||
, body =
|
||||
Element.column [ Element.width Element.fill ]
|
||||
[ header stars page.path
|
||||
, Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view showcaseData ]
|
||||
]
|
||||
}
|
||||
|> wrapBody
|
||||
, head = head page.frontmatter
|
||||
}
|
||||
)
|
||||
(StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
||||
(D.field "stargazers_count" D.int)
|
||||
)
|
||||
Showcase.staticRequest
|
||||
|
||||
_ ->
|
||||
StaticHttp.get (Secrets.succeed "https://api.github.com/repos/dillonkearns/elm-pages")
|
||||
(D.field "stargazers_count" D.int)
|
||||
|> StaticHttp.map
|
||||
(\stars ->
|
||||
{ view =
|
||||
\model viewForPage ->
|
||||
pageView stars model siteMetadata page viewForPage
|
||||
|> wrapBody
|
||||
, head = head page.frontmatter
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -278,6 +302,16 @@ pageView stars model siteMetadata page viewForPage =
|
||||
]
|
||||
}
|
||||
|
||||
Metadata.Showcase ->
|
||||
{ title = "elm-pages blog"
|
||||
, body =
|
||||
Element.column [ Element.width Element.fill ]
|
||||
[ header stars page.path
|
||||
|
||||
--, Element.column [ Element.padding 20, Element.centerX ] [ Showcase.view siteMetadata ]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
wrapBody record =
|
||||
{ body =
|
||||
@ -339,6 +373,7 @@ header stars currentPath =
|
||||
[ elmDocsLink
|
||||
, githubRepoLink stars
|
||||
, highlightableLink currentPath pages.docs.directory "Docs"
|
||||
, highlightableLink currentPath pages.showcase.directory "Showcase"
|
||||
, highlightableLink currentPath pages.blog.directory "Blog"
|
||||
]
|
||||
]
|
||||
@ -482,6 +517,22 @@ head metadata =
|
||||
}
|
||||
|> Seo.website
|
||||
|
||||
Metadata.Showcase ->
|
||||
Seo.summaryLarge
|
||||
{ canonicalUrlOverride = Nothing
|
||||
, siteName = "elm-pages"
|
||||
, image =
|
||||
{ url = images.iconPng
|
||||
, alt = "elm-pages logo"
|
||||
, dimensions = Nothing
|
||||
, mimeType = Nothing
|
||||
}
|
||||
, description = siteTagline
|
||||
, locale = Nothing
|
||||
, title = "elm-pages sites showcase"
|
||||
}
|
||||
|> Seo.website
|
||||
|
||||
|
||||
canonicalSiteUrl : String
|
||||
canonicalSiteUrl =
|
||||
|
@ -17,6 +17,7 @@ type Metadata
|
||||
| Doc DocMetadata
|
||||
| Author Data.Author.Author
|
||||
| BlogIndex
|
||||
| Showcase
|
||||
|
||||
|
||||
type alias ArticleMetadata =
|
||||
@ -54,6 +55,9 @@ decoder =
|
||||
"blog-index" ->
|
||||
Decode.succeed BlogIndex
|
||||
|
||||
"showcase" ->
|
||||
Decode.succeed Showcase
|
||||
|
||||
"author" ->
|
||||
Decode.map3 Data.Author.Author
|
||||
(Decode.field "name" Decode.string)
|
||||
|
74
examples/docs/src/Showcase.elm
Normal file
74
examples/docs/src/Showcase.elm
Normal file
@ -0,0 +1,74 @@
|
||||
module Showcase exposing (..)
|
||||
|
||||
import Element
|
||||
import Json.Decode.Exploration as Decode
|
||||
import Pages.Secrets as Secrets
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
|
||||
|
||||
view : List Entry -> Element.Element msg
|
||||
view entries =
|
||||
Element.column
|
||||
[ Element.spacing 30
|
||||
]
|
||||
(List.map entryView entries)
|
||||
|
||||
|
||||
entryView : Entry -> Element.Element msg
|
||||
entryView entry =
|
||||
Element.column [ Element.spacing 10 ]
|
||||
[ Element.text entry.displayName
|
||||
, Element.newTabLink []
|
||||
{ url = entry.liveUrl
|
||||
, label = Element.text entry.liveUrl
|
||||
}
|
||||
, Element.paragraph []
|
||||
[ Element.text "By "
|
||||
, Element.newTabLink []
|
||||
{ url = entry.authorUrl
|
||||
, label = Element.text entry.authorName
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
type alias Entry =
|
||||
{ displayName : String
|
||||
, liveUrl : String
|
||||
, authorName : String
|
||||
, authorUrl : String
|
||||
, categories : List String
|
||||
}
|
||||
|
||||
|
||||
decoder : Decode.Decoder (List Entry)
|
||||
decoder =
|
||||
Decode.field "records" <|
|
||||
Decode.list entryDecoder
|
||||
|
||||
|
||||
entryDecoder : Decode.Decoder Entry
|
||||
entryDecoder =
|
||||
Decode.field "fields" <|
|
||||
Decode.map5 Entry
|
||||
(Decode.field "Site Display Name" Decode.string)
|
||||
(Decode.field "Live URL" Decode.string)
|
||||
(Decode.field "Author" Decode.string)
|
||||
(Decode.field "Author URL" Decode.string)
|
||||
(Decode.field "Categories" (Decode.list Decode.string))
|
||||
|
||||
|
||||
staticRequest : StaticHttp.Request (List Entry)
|
||||
staticRequest =
|
||||
StaticHttp.request
|
||||
(Secrets.succeed
|
||||
(\airtableToken ->
|
||||
{ url = "https://api.airtable.com/v0/appDykQzbkQJAidjt/elm-pages%20showcase?maxRecords=3&view=Grid%202"
|
||||
, method = "GET"
|
||||
, headers = [ ( "Authorization", "Bearer " ++ airtableToken ), ( "view", "viwayJBsr63qRd7q3" ) ]
|
||||
, body = StaticHttp.emptyBody
|
||||
}
|
||||
)
|
||||
|> Secrets.with "AIRTABLE_TOKEN"
|
||||
)
|
||||
decoder
|
Loading…
Reference in New Issue
Block a user