on master help sign in
One implementation for toDestination and toCache
commit8da7d5b653ecd3157be10e6373e47f771df9472f authorJasper Van der Jeugt <jaspervdj@gmail.com> dateMon 15 Nov 2010, 16:00 (16 years ago) parent1b5a022
1 file changed+19−11
src/Text/Hakyll/File.hs+19−11
src/Text/Hakyll/File.hs+19−11
@@ -40,24 +40,32 @@ removeLeadingSeparator path
4040 path' = if "$root" `isPrefixOf` path then drop 5 path
4141 else path
4242
43−-- | Convert a relative filepath to a filepath in the destination
43+-- | Convert a relative URL to a filepath in the destination
4444-- (default: @_site@).
4545toDestination :: FilePath -> Hakyll FilePath
4646toDestination url = do dir <- askHakyll siteDirectory
47− enableIndexUrl' <- askHakyll enableIndexUrl
48− let destination = if enableIndexUrl' && separatorEnd
49− then dir </> noSeparator </> "index.html"
50− else dir </> noSeparator
51− return destination
52− where
53− noSeparator = removeLeadingSeparator url
54− separatorEnd = not (null url) && last url == '/'
47+ toFilePath dir url
5548
56−-- | Convert a relative filepath to a filepath in the cache
49+-- | Convert a relative URL to a filepath in the cache
5750-- (default: @_cache@).
5851toCache :: FilePath -> Hakyll FilePath
5952toCache path = do dir <- askHakyll cacheDirectory
60− return $ dir </> removeLeadingSeparator path
53+ toFilePath dir path
54+
55+-- | Implementation of toDestination/toCache
56+--
57+toFilePath :: String -- ^ Directory (site or cache)
58+ -> String -- ^ URL
59+ -> Hakyll FilePath -- ^ Resulting file path
60+toFilePath dir url = do
61+ enableIndexUrl' <- askHakyll enableIndexUrl
62+ let destination = if enableIndexUrl' && separatorEnd
63+ then dir </> noSeparator </> "index.html"
64+ else dir </> noSeparator
65+ return destination
66+ where
67+ noSeparator = removeLeadingSeparator url
68+ separatorEnd = not (null url) && last url == '/'
6169
6270-- | Get the url for a given page. For most extensions, this would be the path
6371-- itself. It's only for rendered extensions (@.markdown@, @.rst@, @.lhs@ this