Use elm-rss package.

This commit is contained in:
Dillon Kearns 2020-01-24 21:25:18 -08:00
parent b2840a284e
commit 29daa6816f
4 changed files with 7 additions and 119 deletions

View File

@ -12,6 +12,7 @@
"billstclair/elm-xml-eeue56": "1.0.1",
"dillonkearns/elm-markdown": "1.1.3",
"dillonkearns/elm-oembed": "1.0.0",
"dillonkearns/elm-rss": "1.0.0",
"dmy/elm-imf-date-time": "1.0.1",
"elm/browser": "1.0.2",
"elm/core": "1.0.2",

View File

@ -1,13 +1,9 @@
module Feed exposing (fileToGenerate)
import Dict
import Metadata exposing (Metadata(..))
import Pages
import Pages.PagePath as PagePath exposing (PagePath)
import RssFeed
import Time
import Xml
import Xml.Encode exposing (..)
import Rss
fileToGenerate :
@ -26,8 +22,7 @@ fileToGenerate :
}
fileToGenerate config siteMetadata =
{ path = [ "blog", "feed.xml" ]
, content =
generate config siteMetadata |> Xml.Encode.encode 0
, content = generate config siteMetadata
}
@ -41,9 +36,9 @@ generate :
, frontmatter : Metadata
, body : String
}
-> Xml.Value
-> String
generate { siteTagline, siteUrl } siteMetadata =
RssFeed.generate
Rss.generate
{ title = "elm-pages Blog"
, description = siteTagline
, url = "https://elm-pages.com/blog"
@ -59,7 +54,7 @@ metadataToRssItem :
, frontmatter : Metadata
, body : String
}
-> Maybe RssFeed.Item
-> Maybe Rss.Item
metadataToRssItem page =
case page.frontmatter of
Article article ->
@ -69,7 +64,7 @@ metadataToRssItem page =
, url = PagePath.toString page.path
, categories = []
, author = article.author.name
, pubDate = article.published
, pubDate = Rss.Date article.published
, content = Nothing
}

View File

@ -4,7 +4,6 @@ import Dict
import Metadata exposing (Metadata(..))
import Pages
import Pages.PagePath as PagePath exposing (PagePath)
import RssFeed
import Sitemap
import Time
import Xml

View File

@ -1,107 +0,0 @@
module RssFeed exposing (Item, generate)
{-| Build a feed following the RSS 2.0 format <https://validator.w3.org/feed/docs/rss2.html>.
<http://www.rssboard.org/rss-specification>
-}
import Date exposing (Date)
import Dict
import Imf.DateTime
import Time
import Xml
import Xml.Encode exposing (..)
type alias Item =
{ title : String
, description : String
, url : String
, categories : List String
, author : String
, pubDate : Date
, content : Maybe String
{-
lat optional number The latitude coordinate of the item.
long optional number The longitude coordinate of the item.
custom_elements optional array Put additional elements in the item (node-xml syntax)
enclosure optional object An enclosure object
-}
}
generate :
{ title : String
, description : String
, url : String
, lastBuildTime : Time.Posix
, generator : Maybe String
, items : List Item
, siteUrl : String
}
-> Xml.Value
generate feed =
object
[ ( "rss"
, Dict.fromList
[ ( "xmlns:dc", string "http://purl.org/dc/elements/1.1/" )
, ( "xmlns:content", string "http://purl.org/rss/1.0/modules/content/" )
, ( "xmlns:atom", string "http://www.w3.org/2005/Atom" )
, ( "version", string "2.0" )
]
, object
[ ( "channel"
, Dict.empty
, [ [ keyValue "title" feed.title
, keyValue "description" feed.description
, keyValue "link" feed.url
--<atom:link href="http://dallas.example.com/rss.xml" rel="self" type="application/rss+xml" />
, keyValue "lastBuildDate" <| Imf.DateTime.fromPosix Time.utc feed.lastBuildTime
]
, [ feed.generator |> Maybe.map (keyValue "generator") ] |> List.filterMap identity
, List.map (itemXml feed.siteUrl) feed.items
]
|> List.concat
|> list
)
]
)
]
itemXml : String -> Item -> Xml.Value
itemXml siteUrl item =
object
[ ( "item"
, Dict.empty
, list
([ keyValue "title" item.title
, keyValue "description" item.description
, keyValue "link" (siteUrl ++ item.url)
, keyValue "guid" (siteUrl ++ item.url)
, keyValue "pubDate" (formatDate item.pubDate)
]
++ ([ item.content |> Maybe.map (\content -> keyValue "content" content)
]
|> List.filterMap identity
)
)
)
]
formatDate : Date -> String
formatDate date =
Date.format "EEE, dd MMM yyyy" date
++ " 00:00:00 GMT"
generatorXml : String -> Xml.Value
generatorXml generator =
Xml.Encode.object [ ( "generator", Dict.empty, Xml.Encode.string generator ) ]
keyValue : String -> String -> Xml.Value
keyValue key value =
object [ ( key, Dict.empty, string value ) ]