summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2013-04-22 11:16:54 -0700
committerJasper Van der Jeugt <jaspervdj@gmail.com>2013-04-22 11:16:54 -0700
commit79215f71eb501f65d3e74fdda3e592fbcadd9c7e (patch)
tree3e2da560d44af4479af4830c516f62d9d27c933f /src/Hakyll
parent0954e893a019ae357fdbd1baa8f4042f82c79a02 (diff)
parent63a3000f9cab6446ce40cf6d9671123baee6c22b (diff)
downloadhakyll-79215f71eb501f65d3e74fdda3e592fbcadd9c7e.tar.gz
Merge pull request #133 from simukis/scheme-relative
Account for scheme-relative URLs
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Check.hs10
-rw-r--r--src/Hakyll/Web/Html.hs2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/Hakyll/Check.hs b/src/Hakyll/Check.hs
index 48bb655..68ece18 100644
--- a/src/Hakyll/Check.hs
+++ b/src/Hakyll/Check.hs
@@ -198,12 +198,14 @@ checkExternalUrl url = do
else do
isOk <- liftIO $ handle (failure logger) $
Http.withManager $ \mgr -> do
- request <- Http.parseUrl url
+ request <- Http.parseUrl $ urlToCheck url
response <- Http.http (settings request) mgr
let code = Http.statusCode (Http.responseStatus response)
return $ code >= 200 && code < 300
- modify $ S.insert url
+ modify $ if schemeRelative url
+ then S.insert (urlToCheck url) . S.insert url
+ else S.insert url
if isOk then ok url else faulty url
where
-- Add additional request info
@@ -221,6 +223,10 @@ checkExternalUrl url = do
failure logger (SomeException e) = case cast e of
Just UserInterrupt -> throw UserInterrupt
_ -> Logger.error logger (show e) >> return False
+
+ -- Check scheme-relative links
+ schemeRelative = isPrefixOf "//"
+ urlToCheck uri = if schemeRelative uri then "http:" ++ uri else uri
#else
checkExternalUrl _ = return ()
#endif
diff --git a/src/Hakyll/Web/Html.hs b/src/Hakyll/Web/Html.hs
index 90f963e..58b5c43 100644
--- a/src/Hakyll/Web/Html.hs
+++ b/src/Hakyll/Web/Html.hs
@@ -120,7 +120,7 @@ toSiteRoot = emptyException . joinPath . map parent
--------------------------------------------------------------------------------
-- | Check if an URL links to an external HTTP(S) source
isExternal :: String -> Bool
-isExternal url = any (flip isPrefixOf url) ["http://", "https://"]
+isExternal url = any (flip isPrefixOf url) ["http://", "https://", "//"]
--------------------------------------------------------------------------------