From 8da7d5b653ecd3157be10e6373e47f771df9472f Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 15 Nov 2010 16:00:28 +0100 Subject: One implementation for toDestination and toCache --- src/Text/Hakyll/File.hs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs index 57571e4..167ece7 100644 --- a/src/Text/Hakyll/File.hs +++ b/src/Text/Hakyll/File.hs @@ -40,24 +40,32 @@ removeLeadingSeparator path path' = if "$root" `isPrefixOf` path then drop 5 path else path --- | Convert a relative filepath to a filepath in the destination +-- | Convert a relative URL to a filepath in the destination -- (default: @_site@). toDestination :: FilePath -> Hakyll FilePath toDestination url = do dir <- askHakyll siteDirectory - enableIndexUrl' <- askHakyll enableIndexUrl - let destination = if enableIndexUrl' && separatorEnd - then dir noSeparator "index.html" - else dir noSeparator - return destination - where - noSeparator = removeLeadingSeparator url - separatorEnd = not (null url) && last url == '/' + toFilePath dir url --- | Convert a relative filepath to a filepath in the cache +-- | Convert a relative URL to a filepath in the cache -- (default: @_cache@). toCache :: FilePath -> Hakyll FilePath toCache path = do dir <- askHakyll cacheDirectory - return $ dir removeLeadingSeparator path + toFilePath dir path + +-- | Implementation of toDestination/toCache +-- +toFilePath :: String -- ^ Directory (site or cache) + -> String -- ^ URL + -> Hakyll FilePath -- ^ Resulting file path +toFilePath dir url = do + enableIndexUrl' <- askHakyll enableIndexUrl + let destination = if enableIndexUrl' && separatorEnd + then dir noSeparator "index.html" + else dir noSeparator + return destination + where + noSeparator = removeLeadingSeparator url + separatorEnd = not (null url) && last url == '/' -- | Get the url for a given page. For most extensions, this would be the path -- itself. It's only for rendered extensions (@.markdown@, @.rst@, @.lhs@ this -- cgit v1.2.3