@@ -36,8 +36,15 @@ removeLeadingSeparator path
3636-- | Convert a relative filepath to a filepath in the destination
3737-- (default: @_site@).
3838toDestination :: FilePath -> Hakyll FilePath
39−toDestination path = do dir <- askHakyll siteDirectory
40− return $ dir </> removeLeadingSeparator path
39+toDestination url = do dir <- askHakyll siteDirectory
40+ enableIndexUrl' <- askHakyll enableIndexUrl
41+ let destination = if enableIndexUrl' && separatorEnd
42+ then dir </> noSeparator </> "index.html"
43+ else dir </> noSeparator
44+ return destination
45+ where
46+ noSeparator = removeLeadingSeparator url
47+ separatorEnd = not (null url) && last url == '/'
4148
4249-- | Convert a relative filepath to a filepath in the cache
4350-- (default: @_cache@).
@@ -48,21 +55,34 @@ toCache path = do dir <- askHakyll cacheDirectory
4855-- | Get the url for a given page. For most extensions, this would be the path
4956-- itself. It's only for rendered extensions (@.markdown@, @.rst@, @.lhs@ this
5057-- function returns a path with a @.html@ extension instead.
51−toUrl :: FilePath -> FilePath
52−toUrl path = if takeExtension path `elem` [ ".markdown"
53− , ".md"
54− , ".mdn"
55− , ".mdwn"
56− , ".mkd"
57− , ".mkdn"
58− , ".mkdwn"
59− , ".rst"
60− , ".text"
61− , ".tex"
62− , ".lhs"
63− ]
64− then flip addExtension ".html" $ dropExtension path
65− else path
58+toUrl :: FilePath -> Hakyll FilePath
59+toUrl path = do enableIndexUrl' <- askHakyll enableIndexUrl
60+ -- If the file does not have a renderable extension, like for
61+ -- example favicon.ico, we don't have to change it at all.
62+ return $ if not hasRenderableExtension
63+ then path
64+ -- If index url's are enabled, we create pick it
65+ -- unless the page is an index already.
66+ else if enableIndexUrl' && not isIndex
67+ then indexUrl
68+ else withSimpleHtmlExtension
69+ where
70+ hasRenderableExtension = takeExtension path `elem` [ ".markdown"
71+ , ".md"
72+ , ".mdn"
73+ , ".mdwn"
74+ , ".mkd"
75+ , ".mkdn"
76+ , ".mkdwn"
77+ , ".rst"
78+ , ".text"
79+ , ".tex"
80+ , ".lhs"
81+ ]
82+ isIndex = (dropExtension $ takeFileName path) == "index"
83+ withSimpleHtmlExtension = flip addExtension ".html" $ dropExtension path
84+ indexUrl = (dropExtension path) ++ "/"
85+
6686
6787-- | Get the relative url to the site root, for a given (absolute) url
6888toRoot :: FilePath -> FilePath