From b62172719740f169b6a962a7535650a727c476a7 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 25 Dec 2010 23:20:03 +0200 Subject: [PATCH 1/7] first commit --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 00000000..e69de29b From 5991e01e5bcb62bcd8fc69c47a536dc0d85f5c51 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 25 Dec 2010 23:22:19 +0200 Subject: [PATCH 2/7] Code import --- LICENSE | 25 +++++++++++++ Setup.lhs | 7 ++++ Yesod/Helpers/Sitemap.hs | 81 ++++++++++++++++++++++++++++++++++++++++ yesod-sitemap.cabal | 24 ++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 LICENSE create mode 100755 Setup.lhs create mode 100644 Yesod/Helpers/Sitemap.hs create mode 100644 yesod-sitemap.cabal diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8643e5d8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +The following license covers this documentation, and the source code, except +where otherwise indicated. + +Copyright 2010, Michael Snoyman. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Setup.lhs b/Setup.lhs new file mode 100755 index 00000000..06e2708f --- /dev/null +++ b/Setup.lhs @@ -0,0 +1,7 @@ +#!/usr/bin/env runhaskell + +> module Main where +> import Distribution.Simple + +> main :: IO () +> main = defaultMain diff --git a/Yesod/Helpers/Sitemap.hs b/Yesod/Helpers/Sitemap.hs new file mode 100644 index 00000000..6d79e834 --- /dev/null +++ b/Yesod/Helpers/Sitemap.hs @@ -0,0 +1,81 @@ +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE CPP #-} +--------------------------------------------------------- +-- +-- Module : Yesod.Helpers.Sitemap +-- Copyright : Michael Snoyman +-- License : BSD3 +-- +-- Maintainer : Michael Snoyman +-- Stability : Stable +-- Portability : portable +-- +-- Generating Google sitemap files. +-- +--------------------------------------------------------- + +-- | Generates XML sitemap files. +-- +-- See . +module Yesod.Helpers.Sitemap + ( sitemap + , robots + , SitemapUrl (..) + , SitemapChangeFreq (..) + ) where + +import Yesod.Content (RepXml (..), RepPlain (..), toContent, formatW3) +import Yesod.Handler (Route, GHandler, getUrlRender) +import Yesod.Widget (hamletToContent) +import Text.Hamlet (Hamlet, xhamlet) +import Data.Time (UTCTime) + +data SitemapChangeFreq = Always + | Hourly + | Daily + | Weekly + | Monthly + | Yearly + | Never + +showFreq :: SitemapChangeFreq -> String +showFreq Always = "always" +showFreq Hourly = "hourly" +showFreq Daily = "daily" +showFreq Weekly = "weekly" +showFreq Monthly = "monthly" +showFreq Yearly = "yearly" +showFreq Never = "never" + +data SitemapUrl url = SitemapUrl + { sitemapLoc :: url + , sitemapLastMod :: UTCTime + , sitemapChangeFreq :: SitemapChangeFreq + , priority :: Double + } + +template :: [SitemapUrl url] -> Hamlet url +template urls = +#if __GLASGOW_HASKELL__ >= 700 + [xhamlet| +#else + [$xhamlet| +#endif +%urlset!xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" + $forall urls url + %url + %loc @sitemapLoc.url@ + %lastmod $formatW3.sitemapLastMod.url$ + %changefreq $showFreq.sitemapChangeFreq.url$ + %priority $show.priority.url$ +|] + +sitemap :: [SitemapUrl (Route master)] -> GHandler sub master RepXml +sitemap = fmap RepXml . hamletToContent . template + +-- | A basic robots file which just lists the "Sitemap: " line. +robots :: Route master -- ^ sitemap url + -> GHandler sub master RepPlain +robots smurl = do + render <- getUrlRender + return $ RepPlain $ toContent $ "Sitemap: " ++ render smurl diff --git a/yesod-sitemap.cabal b/yesod-sitemap.cabal new file mode 100644 index 00000000..d9a8b9e7 --- /dev/null +++ b/yesod-sitemap.cabal @@ -0,0 +1,24 @@ +name: yesod-sitemap +version: 0.7.0 +license: BSD3 +license-file: LICENSE +author: Michael Snoyman +maintainer: Michael Snoyman +synopsis: Generate XML sitemaps. +category: Web, Yesod +stability: Stable +cabal-version: >= 1.6 +build-type: Simple +homepage: http://docs.yesodweb.com/ + +library + build-depends: base >= 4 && < 5 + , yesod-core >= 0.7 && < 0.8 + , time >= 1.1.4 && < 1.3 + , hamlet >= 0.7 && < 0.8 + exposed-modules: Yesod.Helpers.Sitemap + ghc-options: -Wall + +source-repository head + type: git + location: git://github.com/snoyberg/yesod-sitemap.git From 9d25af66bb288eff37c9ab78a70fbe27c9c1faf9 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 19 Jan 2011 23:51:50 +0200 Subject: [PATCH 3/7] Drop version to 0.0.0 --- yesod-sitemap.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-sitemap.cabal b/yesod-sitemap.cabal index d9a8b9e7..bf1eb791 100644 --- a/yesod-sitemap.cabal +++ b/yesod-sitemap.cabal @@ -1,5 +1,5 @@ name: yesod-sitemap -version: 0.7.0 +version: 0.0.0 license: BSD3 license-file: LICENSE author: Michael Snoyman From 2eac2738c988fa256b08a8e52fea9f236c8a61dc Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sat, 5 Feb 2011 20:24:58 +0200 Subject: [PATCH 4/7] Hamlet 0.7 --- Yesod/Helpers/Sitemap.hs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Yesod/Helpers/Sitemap.hs b/Yesod/Helpers/Sitemap.hs index 6d79e834..05debf5f 100644 --- a/Yesod/Helpers/Sitemap.hs +++ b/Yesod/Helpers/Sitemap.hs @@ -26,7 +26,7 @@ module Yesod.Helpers.Sitemap import Yesod.Content (RepXml (..), RepPlain (..), toContent, formatW3) import Yesod.Handler (Route, GHandler, getUrlRender) -import Yesod.Widget (hamletToContent) +import Yesod.Handler (hamletToContent) import Text.Hamlet (Hamlet, xhamlet) import Data.Time (UTCTime) @@ -61,13 +61,14 @@ template urls = #else [$xhamlet| #endif -%urlset!xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" - $forall urls url - %url - %loc @sitemapLoc.url@ - %lastmod $formatW3.sitemapLastMod.url$ - %changefreq $showFreq.sitemapChangeFreq.url$ - %priority $show.priority.url$ +
+ + $forall url <- urls + + @{sitemapLoc url} + #{formatW3 (sitemapLastMod url)} + #{showFreq (sitemapChangeFreq url)} + #{show (priority url)} |] sitemap :: [SitemapUrl (Route master)] -> GHandler sub master RepXml From ef3c128ccfa7258d0d8b345dc1af8c91aa7dc7b8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 21 Feb 2011 08:07:25 +0200 Subject: [PATCH 5/7] Bug report by Katsutoshi Itoh --- Yesod/Helpers/Sitemap.hs | 1 - yesod-sitemap.cabal | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Yesod/Helpers/Sitemap.hs b/Yesod/Helpers/Sitemap.hs index 05debf5f..60562bc7 100644 --- a/Yesod/Helpers/Sitemap.hs +++ b/Yesod/Helpers/Sitemap.hs @@ -61,7 +61,6 @@ template urls = #else [$xhamlet| #endif -
$forall url <- urls diff --git a/yesod-sitemap.cabal b/yesod-sitemap.cabal index bf1eb791..8ca91b64 100644 --- a/yesod-sitemap.cabal +++ b/yesod-sitemap.cabal @@ -1,5 +1,5 @@ name: yesod-sitemap -version: 0.0.0 +version: 0.0.0.1 license: BSD3 license-file: LICENSE author: Michael Snoyman From 237d7902f799cfa010c5a1721fb4348011a84053 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 10 Apr 2011 21:42:27 +0300 Subject: [PATCH 6/7] Yesod 0.8 --- yesod-sitemap.cabal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yesod-sitemap.cabal b/yesod-sitemap.cabal index 8ca91b64..f126ac4c 100644 --- a/yesod-sitemap.cabal +++ b/yesod-sitemap.cabal @@ -1,5 +1,5 @@ name: yesod-sitemap -version: 0.0.0.1 +version: 0.1.0 license: BSD3 license-file: LICENSE author: Michael Snoyman @@ -13,9 +13,9 @@ homepage: http://docs.yesodweb.com/ library build-depends: base >= 4 && < 5 - , yesod-core >= 0.7 && < 0.8 + , yesod-core >= 0.8 && < 0.9 , time >= 1.1.4 && < 1.3 - , hamlet >= 0.7 && < 0.8 + , hamlet >= 0.8 && < 0.9 exposed-modules: Yesod.Helpers.Sitemap ghc-options: -Wall From 5e9b8ba1f4bb8d24ab1699b7465892b7b6025fd3 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 10 Apr 2011 21:51:45 +0300 Subject: [PATCH 7/7] Fix building --- Yesod/Helpers/Sitemap.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Yesod/Helpers/Sitemap.hs b/Yesod/Helpers/Sitemap.hs index 60562bc7..4429225c 100644 --- a/Yesod/Helpers/Sitemap.hs +++ b/Yesod/Helpers/Sitemap.hs @@ -1,5 +1,6 @@ {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} --------------------------------------------------------- -- -- Module : Yesod.Helpers.Sitemap @@ -29,6 +30,7 @@ import Yesod.Handler (Route, GHandler, getUrlRender) import Yesod.Handler (hamletToContent) import Text.Hamlet (Hamlet, xhamlet) import Data.Time (UTCTime) +import Data.Monoid (mappend) data SitemapChangeFreq = Always | Hourly @@ -78,4 +80,4 @@ robots :: Route master -- ^ sitemap url -> GHandler sub master RepPlain robots smurl = do render <- getUrlRender - return $ RepPlain $ toContent $ "Sitemap: " ++ render smurl + return $ RepPlain $ toContent $ "Sitemap: " `mappend` render smurl