summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2017-07-05 10:21:02 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2017-07-05 10:21:02 +0200
commit83a95b3eb41745d3a6f7cb6fcb7ba6c1e1657a84 (patch)
tree8a1b8bb9c6dab78277883338373dedaaeaa81160 /lib
parent3fcd4b77c0a283946f60c66f82aa0e1c44139c10 (diff)
downloadhakyll-83a95b3eb41745d3a6f7cb6fcb7ba6c1e1657a84.tar.gz
Better errors for redirects
Diffstat (limited to 'lib')
-rw-r--r--lib/Hakyll/Web/Redirect.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Hakyll/Web/Redirect.hs b/lib/Hakyll/Web/Redirect.hs
index 283d8bf..d34f0b4 100644
--- a/lib/Hakyll/Web/Redirect.hs
+++ b/lib/Hakyll/Web/Redirect.hs
@@ -9,7 +9,7 @@ module Hakyll.Web.Redirect
import Control.Applicative ((<$>))
import Control.Monad (forM_, when)
import Data.Binary (Binary (..))
-import Data.List (nub)
+import Data.List (sort, group)
import Hakyll.Core.Compiler
import Hakyll.Core.Identifier
import Hakyll.Core.Routes
@@ -57,9 +57,16 @@ import Hakyll.Core.Writable (Writable (..))
createRedirects :: [(Identifier, String)] -> Rules ()
createRedirects redirects =
do -- redirects are many-to-fewer; keys must be unique, and must point somewhere else:
- let keys = map fst redirects
- when (length keys /= length (nub keys)) $ error "Overlapping 301 redirects; check your mapping for redundant keys"
- when (or $ map (\(r,t) -> toFilePath r == t) redirects) $ error "Self-redirect detected: at least one redirect's target points to itself."
+ let gkeys = group $ sort $ map fst redirects
+ forM_ gkeys $ \gkey -> case gkey of
+ (k : _ : _) -> fail $
+ "Duplicate 301 redirects; " ++ show k ++ " is ambiguous."
+ _ -> return ()
+
+ forM_ redirects $ \(r, t) ->
+ when (toFilePath r == t) $ fail $
+ "Self-redirect detected: " ++ show r ++ " points to itself."
+
forM_ redirects $ \(ident, to) ->
create [ident] $ do
route idRoute