mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-05 12:57:33 +03:00
Add sitemap.
This commit is contained in:
parent
40e89ccec2
commit
43f494a84d
@ -20,6 +20,7 @@ import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Exploration as D
|
||||
import MarkdownRenderer
|
||||
import Metadata exposing (Metadata)
|
||||
import MySitemap
|
||||
import Pages exposing (images, pages)
|
||||
import Pages.Directory as Directory exposing (Directory)
|
||||
import Pages.Document
|
||||
@ -81,6 +82,7 @@ generateFiles :
|
||||
}
|
||||
generateFiles siteMetadata =
|
||||
[ Feed.fileToGenerate { siteTagline = siteTagline, siteUrl = canonicalSiteUrl } siteMetadata
|
||||
, MySitemap.build { siteUrl = canonicalSiteUrl } siteMetadata
|
||||
]
|
||||
|
||||
|
||||
|
37
examples/docs/src/MySitemap.elm
Normal file
37
examples/docs/src/MySitemap.elm
Normal file
@ -0,0 +1,37 @@
|
||||
module MySitemap exposing (..)
|
||||
|
||||
import Dict
|
||||
import Metadata exposing (Metadata(..))
|
||||
import Pages
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import RssFeed
|
||||
import Sitemap
|
||||
import Time
|
||||
import Xml
|
||||
import Xml.Encode exposing (..)
|
||||
|
||||
|
||||
build :
|
||||
{ siteUrl : String
|
||||
}
|
||||
->
|
||||
List
|
||||
{ path : PagePath Pages.PathKey
|
||||
, frontmatter : Metadata
|
||||
}
|
||||
->
|
||||
{ path : List String
|
||||
, content : String
|
||||
}
|
||||
build config siteMetadata =
|
||||
{ path = [ "sitemap.xml" ]
|
||||
, content =
|
||||
Sitemap.build config
|
||||
(siteMetadata
|
||||
|> List.map
|
||||
(\page ->
|
||||
page.path
|
||||
|> PagePath.toString
|
||||
)
|
||||
)
|
||||
}
|
43
examples/docs/src/Sitemap.elm
Normal file
43
examples/docs/src/Sitemap.elm
Normal file
@ -0,0 +1,43 @@
|
||||
module Sitemap exposing (build)
|
||||
|
||||
import Date exposing (Date)
|
||||
import Dict
|
||||
import Imf.DateTime
|
||||
import Time
|
||||
import Xml
|
||||
import Xml.Encode exposing (..)
|
||||
|
||||
|
||||
build :
|
||||
{ siteUrl : String
|
||||
}
|
||||
-> List String
|
||||
-> String
|
||||
build { siteUrl } urls =
|
||||
object
|
||||
[ ( "urlset"
|
||||
, Dict.fromList
|
||||
[ ( "xmlns", string "http://www.sitemaps.org/schemas/sitemap/0.9" )
|
||||
]
|
||||
, urls
|
||||
|> List.map (urlXml siteUrl)
|
||||
|> list
|
||||
)
|
||||
]
|
||||
|> encode 0
|
||||
|
||||
|
||||
urlXml siteUrl url =
|
||||
object
|
||||
[ ( "url"
|
||||
, Dict.empty
|
||||
, list
|
||||
[ keyValue "loc" <| string (siteUrl ++ url)
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
keyValue : String -> Xml.Value -> Xml.Value
|
||||
keyValue key value =
|
||||
object [ ( key, Dict.empty, value ) ]
|
Loading…
Reference in New Issue
Block a user