Update the example RSS plugin and wire it into example site.

This commit is contained in:
Dillon Kearns 2020-03-09 16:28:41 -07:00
parent e556a6a7be
commit 74b7cb90d0
2 changed files with 59 additions and 14 deletions

View File

@ -24,6 +24,7 @@ import MarkdownRenderer
import Metadata exposing (Metadata)
import MySitemap
import Pages exposing (images, pages)
import Pages.Builder
import Pages.Directory as Directory exposing (Directory)
import Pages.Document
import Pages.ImagePath as ImagePath exposing (ImagePath)
@ -33,6 +34,8 @@ import Pages.PagePath as PagePath exposing (PagePath)
import Pages.Platform exposing (Page)
import Pages.StaticHttp as StaticHttp
import Palette
import Rss
import RssPlugin
import Secrets
import Showcase
@ -59,18 +62,59 @@ type alias View =
main : Pages.Platform.Program Model Msg Metadata View
main =
Pages.Platform.application
Pages.Builder.init
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
, documents = [ markdownDocument ]
, manifest = manifest
, canonicalSiteUrl = canonicalSiteUrl
, generateFiles = generateFiles
, onPageChange = Just OnPageChange
, internals = Pages.internals
}
|> Pages.Builder.withFileGenerator generateFiles
|> Pages.Builder.withPageChangeMsg OnPageChange
|> RssPlugin.generate
{ siteTagline = siteTagline
, siteUrl : String
, title = tit
,
, builtAt = Pages.builtAt
, indexPage : PagePath pathKey
}
metadataToRssItem
|> Pages.Builder.toApplication
metadataToRssItem :
{ path : PagePath Pages.PathKey
, frontmatter : Metadata
, body : String
}
-> Maybe Rss.Item
metadataToRssItem page =
case page.frontmatter of
Metadata.Article article ->
if article.draft then
Nothing
else
Just
{ title = article.title
, description = article.description
, url = PagePath.toString page.path
, categories = []
, author = article.author.name
, pubDate = Rss.Date article.published
, content = Nothing
}
_ ->
Nothing
--|> Pages.Builder.withSubscriptions (\_ -> Sub.batch [])
generateFiles :

View File

@ -10,14 +10,12 @@ import Time
generate :
Directory pathKey hasIndex
->
{ siteTagline : String
, siteUrl : String
, title : String
, builtAt : Time.Posix
, indexPage : PagePath pathKey
}
{ siteTagline : String
, siteUrl : String
, title : String
, builtAt : Time.Posix
, indexPage : PagePath pathKey
}
->
({ path : PagePath pathKey
, frontmatter : metadata
@ -27,10 +25,13 @@ generate :
)
-> Builder pathKey userModel userMsg metadata view builderState
-> Builder pathKey userModel userMsg metadata view builderState
generate baseDirectory options metadataToRssItem builder =
generate options metadataToRssItem builder =
let
feedFilePath =
Directory.basePath baseDirectory ++ [ "feed.xml" ]
--Directory.basePath baseDirectory ++ [ "feed.xml" ]
options.indexPage
|> PagePath.toString
|> String.split "/"
in
builder
|> Pages.Builder.withFileGenerator