@@ -7,8 +7,9 @@ module Hakyll.Web.Redirect
77 ) where
88
99import Control.Applicative ((<$>))
10−import Control.Monad (forM_)
10+import Control.Monad (forM_, when)
1111import Data.Binary (Binary (..))
12+import Data.List (nub)
1213import Hakyll.Core.Compiler
1314import Hakyll.Core.Identifier
1415import Hakyll.Core.Routes
@@ -55,6 +56,10 @@ import Hakyll.Core.Writable (Writable (..))
5556-- See also <https://groups.google.com/d/msg/hakyll/sWc6zxfh-uM/fUpZPsFNDgAJ>.
5657createRedirects :: [(Identifier, String)] -> Rules ()
5758createRedirects 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."
5863 forM_ redirects $ \(ident, to) ->
5964 create [ident] $ do
6065 route idRoute
@@ -81,6 +86,7 @@ instance Writable Redirect where
8186redirectToHtml :: Redirect -> String
8287redirectToHtml (Redirect working) =
8388 "<!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\">" ++
8490 "<meta http-equiv=\"refresh\" content=\"0; url=" ++ working ++
8591 "\"><link rel=\"canonical\" href=\"" ++ working ++
8692 "\"><title>Permanent Redirect</title></head><body><p>The page has moved to: <a href=\"" ++ working ++