blob: a0702d8455873ec43ab940d5d830a2bab7e08389 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-- | Miscellaneous URL manipulation functions.
--
module Hakyll.Web.Util.Url
( toUrl
, toSiteRoot
) where
import System.FilePath (splitPath, takeDirectory, joinPath)
-- | Convert a filepath to an URL starting from the site root
--
-- Example:
--
-- > toUrl "foo/bar.html"
--
-- Result:
--
-- > "/foo/bar.html"
--
toUrl :: FilePath -> String
toUrl ('/' : xs) = '/' : xs
toUrl url = '/' : url
-- | Get the relative url to the site root, for a given (absolute) url
--
toSiteRoot :: String -> String
toSiteRoot = emptyException . joinPath . map parent
. splitPath . takeDirectory . dropLeadingSlash
where
parent = const ".."
emptyException [] = "."
emptyException x = x
dropLeadingSlash = dropWhile (== '/')
|