diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-12-29 12:30:23 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-12-29 12:30:23 +0100 |
commit | 5d4d964fccc53167f25683ff7a0f11cde951ca88 (patch) | |
tree | 914b299f6338754cc42464fcc225a3a459d1e2fc /src | |
parent | e947403d51d11bae0ea3c044a4af7e6f95fe0152 (diff) | |
download | hakyll-5d4d964fccc53167f25683ff7a0f11cde951ca88.tar.gz |
Stub external url checking
Diffstat (limited to 'src')
-rw-r--r-- | src/Hakyll/Check.hs | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/Hakyll/Check.hs b/src/Hakyll/Check.hs index 681318a..3728235 100644 --- a/src/Hakyll/Check.hs +++ b/src/Hakyll/Check.hs @@ -82,34 +82,43 @@ checkFile filePath = do contents <- liftIO $ readFile filePath Logger.header logger $ "Checking " ++ filePath - let tags = TS.parseTags contents - -- Lots of logic here... - urls = filter (not . null) $ - map stripFragments $ - filter (not . isExternal) $ - getUrls tags + let urls = getUrls $ TS.parseTags contents + forM_ urls $ \url -> + if isExternal url + then checkExternalUrl url + else checkInternalUrl filePath url - mapM_ (checkUrl filePath) urls + +-------------------------------------------------------------------------------- +checkInternalUrl :: FilePath -> String -> Checker () +checkInternalUrl base url = case url' of + "" -> tell $ mempty {checkerOk = 1} + _ -> do + logger <- checkerLogger <$> ask + config <- checkerConfig <$> ask + + let dest = destinationDirectory config + dir = takeDirectory base + filePath + | "/" `isPrefixOf` url' = dest ++ url' + | otherwise = dir </> url' + + exists <- checkFileExists filePath + if exists + then tell $ mempty {checkerOk = 1} + else do + tell $ mempty {checkerFaulty = 1} + Logger.error logger $ base ++ ": broken link to " ++ show url + where + url' = stripFragments url -------------------------------------------------------------------------------- -checkUrl :: FilePath -> String -> Checker () -checkUrl base url = do +checkExternalUrl :: String -> Checker () +checkExternalUrl url = do logger <- checkerLogger <$> ask - config <- checkerConfig <$> ask - - let dest = destinationDirectory config - dir = takeDirectory base - filePath - | "/" `isPrefixOf` url = dest ++ url - | otherwise = dir </> url - - exists <- checkFileExists filePath - if exists - then tell $ mempty {checkerOk = 1} - else do - tell $ mempty {checkerFaulty = 1} - Logger.error logger $ base ++ ": broken reference to " ++ show url + Logger.message logger $ "Not checking external url " ++ url + -- TODO: use http-conduit and a cache? -------------------------------------------------------------------------------- |