Add a simple unstyled showcase.

This commit is contained in:
Dillon Kearns 2020-01-21 10:40:06 -08:00
parent 62f7310ac5
commit 3240f01875
6 changed files with 147 additions and 32 deletions

View File

@ -0,0 +1,4 @@
---
title: elm-pages sites showcase
type: showcase
---

View File

@ -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

View File

@ -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

View File

@ -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 =

View File

@ -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)

View 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