packages feed

yesod-sitemap 0.3.0 → 1.0.0

raw patch · 2 files changed

+33/−26 lines, 2 filesdep +textdep +xml-conduitdep −hamletdep ~yesod-core

Dependencies added: text, xml-conduit

Dependencies removed: hamlet

Dependency ranges changed: yesod-core

Files

Yesod/Sitemap.hs view
@@ -1,6 +1,5 @@-{-# LANGUAGE QuasiQuotes #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-} --------------------------------------------------------- -- -- Module        : Yesod.Sitemap@@ -27,10 +26,10 @@  import Yesod.Content (RepXml (..), RepPlain (..), toContent, formatW3) import Yesod.Core (Route, GHandler, getUrlRender)-import Yesod.Handler (hamletToContent)-import Text.Hamlet (HtmlUrl, xhamlet) import Data.Time (UTCTime) import Data.Monoid (mappend)+import Text.XML+import Data.Text (Text, pack)  data SitemapChangeFreq = Always                        | Hourly@@ -40,7 +39,7 @@                        | Yearly                        | Never -showFreq :: SitemapChangeFreq -> String+showFreq :: SitemapChangeFreq -> Text showFreq Always  = "always" showFreq Hourly  = "hourly" showFreq Daily   = "daily"@@ -53,27 +52,34 @@     { sitemapLoc :: url     , sitemapLastMod :: UTCTime     , sitemapChangeFreq :: SitemapChangeFreq-    , priority :: Double+    , sitemapPriority :: Double     } -template :: [SitemapUrl url] -> HtmlUrl url-template urls =-#if __GLASGOW_HASKELL__ >= 700-                [xhamlet|-#else-                [$xhamlet|-#endif-<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">-    $forall url <- urls-        <url>-            <loc>@{sitemapLoc url}-            <lastmod>#{formatW3 (sitemapLastMod url)}-            <changefreq>#{showFreq (sitemapChangeFreq url)}-            <priority>#{show (priority url)}-|]+template :: [SitemapUrl url]+         -> (url -> Text)+         -> Document+template urls render =+    Document (Prologue [] Nothing []) (addNS root) []+  where+    addNS (Element (Name ln _ _) as ns) = Element (Name ln (Just namespace) Nothing) as (map addNS' ns)+    addNS' (NodeElement e) = NodeElement (addNS e)+    addNS' n = n+    namespace = "http://www.sitemaps.org/schemas/sitemap/0.9" +    root = Element "urlset" [] $ map go urls++    go SitemapUrl {..} = NodeElement $ Element "url" [] $ map NodeElement+        [ Element "loc" [] [NodeContent $ render sitemapLoc]+        , Element "lastmod" [] [NodeContent $ formatW3 sitemapLastMod]+        , Element "changefreq" [] [NodeContent $ showFreq sitemapChangeFreq]+        , Element "priority" [] [NodeContent $ pack $ show sitemapPriority]+        ]+ sitemap :: [SitemapUrl (Route master)] -> GHandler sub master RepXml-sitemap = fmap RepXml . hamletToContent . template+sitemap urls = do+    render <- getUrlRender+    let doc = template urls render+    return $ RepXml $ toContent $ renderLBS def doc  -- | A basic robots file which just lists the "Sitemap: " line. robots :: Route master -- ^ sitemap url
yesod-sitemap.cabal view
@@ -1,6 +1,6 @@ name:            yesod-sitemap-version:         0.3.0-license:         BSD3+version:         1.0.0+license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com> maintainer:      Michael Snoyman <michael@snoyman.com>@@ -14,9 +14,10 @@  library     build-depends:   base                      >= 4        && < 5-                   , yesod-core                >= 0.10     && < 0.11+                   , yesod-core                >= 1.0      && < 1.1                    , time                      >= 1.1.4-                   , hamlet                    >= 0.10     && < 0.11+                   , xml-conduit               >= 0.7      && < 0.8+                   , text     exposed-modules: Yesod.Sitemap     ghc-options:     -Wall