mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-24 06:54:03 +03:00
Add a helper to add global head tags.
This commit is contained in:
parent
1383387e46
commit
e556a6a7be
56
examples/docs/src/RssPlugin.elm
Normal file
56
examples/docs/src/RssPlugin.elm
Normal file
@ -0,0 +1,56 @@
|
||||
module RssPlugin exposing (..)
|
||||
|
||||
import Head
|
||||
import Pages.Builder exposing (Builder)
|
||||
import Pages.Directory as Directory exposing (Directory)
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Rss
|
||||
import Time
|
||||
|
||||
|
||||
generate :
|
||||
Directory pathKey hasIndex
|
||||
->
|
||||
{ siteTagline : String
|
||||
, siteUrl : String
|
||||
, title : String
|
||||
, builtAt : Time.Posix
|
||||
, indexPage : PagePath pathKey
|
||||
}
|
||||
->
|
||||
({ path : PagePath pathKey
|
||||
, frontmatter : metadata
|
||||
, body : String
|
||||
}
|
||||
-> Maybe Rss.Item
|
||||
)
|
||||
-> Builder pathKey userModel userMsg metadata view builderState
|
||||
-> Builder pathKey userModel userMsg metadata view builderState
|
||||
generate baseDirectory options metadataToRssItem builder =
|
||||
let
|
||||
feedFilePath =
|
||||
Directory.basePath baseDirectory ++ [ "feed.xml" ]
|
||||
in
|
||||
builder
|
||||
|> Pages.Builder.withFileGenerator
|
||||
(\siteMetadata ->
|
||||
{ path = feedFilePath
|
||||
, content =
|
||||
Rss.generate
|
||||
{ title = options.title
|
||||
, description = options.siteTagline
|
||||
|
||||
-- TODO make sure you don't add an extra "/"
|
||||
, url = options.siteUrl ++ "/" ++ PagePath.toString options.indexPage
|
||||
, lastBuildTime = options.builtAt
|
||||
, generator = Just "elm-pages"
|
||||
, items = siteMetadata |> List.filterMap metadataToRssItem
|
||||
, siteUrl = options.siteUrl
|
||||
}
|
||||
}
|
||||
|> Ok
|
||||
|> List.singleton
|
||||
|> StaticHttp.succeed
|
||||
)
|
||||
|> Pages.Builder.addGlobalHeadTags [ Head.rssLink (feedFilePath |> String.join "/") ]
|
@ -116,6 +116,25 @@ withPageChangeMsg onPageChangeMsg (Builder builder) =
|
||||
Builder { builder | onPageChange = Just onPageChangeMsg }
|
||||
|
||||
|
||||
addGlobalHeadTags :
|
||||
List (Head.Tag pathKey)
|
||||
-> Builder pathKey userModel userMsg metadata view builderState
|
||||
-> Builder pathKey userModel userMsg metadata view builderState
|
||||
addGlobalHeadTags globalHeadTags (Builder config) =
|
||||
Builder
|
||||
{ config
|
||||
| view =
|
||||
\arg1 arg2 ->
|
||||
config.view arg1 arg2
|
||||
|> StaticHttp.map
|
||||
(\fns ->
|
||||
{ view = fns.view
|
||||
, head = globalHeadTags ++ fns.head
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
withFileGenerator :
|
||||
(List { path : PagePath pathKey, frontmatter : metadata, body : String }
|
||||
->
|
||||
|
@ -2,6 +2,7 @@ module Pages.Directory exposing
|
||||
( Directory
|
||||
, includes
|
||||
, indexPath, WithIndex, WithoutIndex
|
||||
, basePathToString, basePath
|
||||
, withIndex, withoutIndex
|
||||
)
|
||||
|
||||
@ -19,6 +20,11 @@ to the directory (if it is a `Directory pathKey WithIndex`).
|
||||
@docs indexPath, WithIndex, WithoutIndex
|
||||
|
||||
|
||||
## Getting a `Directory`'s base path
|
||||
|
||||
@docs basePathToString, basePath
|
||||
|
||||
|
||||
## Functions for use by generated code
|
||||
|
||||
@docs withIndex, withoutIndex
|
||||
@ -120,6 +126,20 @@ indexPath (Directory key allPagePaths directoryPath) =
|
||||
PagePath.build key directoryPath
|
||||
|
||||
|
||||
{-| TODO
|
||||
-}
|
||||
basePathToString : Directory key hasIndex -> String
|
||||
basePathToString (Directory key allPagePaths directoryPath) =
|
||||
toString directoryPath
|
||||
|
||||
|
||||
{-| TODO
|
||||
-}
|
||||
basePath : Directory key hasIndex -> List String
|
||||
basePath (Directory key allPagePaths directoryPath) =
|
||||
directoryPath
|
||||
|
||||
|
||||
toString : List String -> String
|
||||
toString rawPath =
|
||||
"/"
|
||||
|
Loading…
Reference in New Issue
Block a user