@@ -7,8 +7,9 @@ module Hakyll.Web.Redirect
9import Control.Applicative ((<$>))
9import Control.Applicative ((<$>))
10−import Control.Monad (forM_)
10+import Control.Monad (forM_, when)
11import Data.Binary (Binary (..))
11import Data.Binary (Binary (..))
12+import Data.List (nub)
12import Hakyll.Core.Compiler
13import Hakyll.Core.Compiler
13import Hakyll.Core.Identifier
14import Hakyll.Core.Identifier
14import Hakyll.Core.Routes
15import Hakyll.Core.Routes
@@ -55,6 +56,10 @@ import Hakyll.Core.Writable (Writable (..))
55-- See also <https://groups.google.com/d/msg/hakyll/sWc6zxfh-uM/fUpZPsFNDgAJ>.
56-- See also <https://groups.google.com/d/msg/hakyll/sWc6zxfh-uM/fUpZPsFNDgAJ>.
56createRedirects :: [(Identifier, String)] -> Rules ()
57createRedirects :: [(Identifier, String)] -> Rules ()
57createRedirects redirects =
58createRedirects redirects =
59+ do -- redirects are many-to-fewer; keys must be unique, and must point somewhere else:
60+ let keys = map fst redirects
61+ when (length keys /= length (nub keys)) $ error "Overlapping 301 redirects; check your mapping for redundant keys"
62+ when (or $ map (\(r,t) -> toFilePath r == t) redirects) $ error "Self-redirect detected: at least one redirect's target points to itself."
58 forM_ redirects $ \(ident, to) ->
63 forM_ redirects $ \(ident, to) ->
59 create [ident] $ do
64 create [ident] $ do
60 route idRoute
65 route idRoute
@@ -81,6 +86,7 @@ instance Writable Redirect where
81redirectToHtml :: Redirect -> String
86redirectToHtml :: Redirect -> String
82redirectToHtml (Redirect working) =
87redirectToHtml (Redirect working) =
83 "<!DOCTYPE html><html><head><meta charset=\"utf-8\"/><meta name=\"generator\" content=\"hakyll\"/>" ++
88 "<!DOCTYPE html><html><head><meta charset=\"utf-8\"/><meta name=\"generator\" content=\"hakyll\"/>" ++
89+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">" ++
84 "<meta http-equiv=\"refresh\" content=\"0; url=" ++ working ++
90 "<meta http-equiv=\"refresh\" content=\"0; url=" ++ working ++
85 "\"><link rel=\"canonical\" href=\"" ++ working ++
91 "\"><link rel=\"canonical\" href=\"" ++ working ++
86 "\"><title>Permanent Redirect</title></head><body><p>The page has moved to: <a href=\"" ++ working ++
92 "\"><title>Permanent Redirect</title></head><body><p>The page has moved to: <a href=\"" ++ working ++