@@ -49,8 +49,12 @@ defaultListing pieces (Folder contents) = do
49 , "a { text-decoration: none }"
49 , "a { text-decoration: none }"
51 H.body $ do
51 H.body $ do
52+ let hasTrailingSlash =
53+ case map fromPiece $ reverse $ pieces of
52− H.h1 $ showFolder' $ filter (not . T.null . fromPiece) pieces
56+ H.h1 $ showFolder' hasTrailingSlash $ filter (not . T.null . fromPiece) pieces
53− renderDirectoryContentsTable haskellSrc folderSrc fps''
57+ renderDirectoryContentsTable (map fromPiece pieces) haskellSrc folderSrc fps''
55 image x = T.unpack $ T.concat [(relativeDirFromPieces pieces), ".hidden/", x, ".png"]
59 image x = T.unpack $ T.concat [(relativeDirFromPieces pieces), ".hidden/", x, ".png"]
56 folderSrc = image "folder"
60 folderSrc = image "folder"
@@ -59,17 +63,20 @@ defaultListing pieces (Folder contents) = do
59 showName x = x
63 showName x = x
61 -- Add a link to the root of the tree
65 -- Add a link to the root of the tree
62− showFolder' :: Pieces -> H.Html
66+ showFolder' :: Bool -> Pieces -> H.Html
63− showFolder' pieces = showFolder (unsafeToPiece "root" : pieces)
67+ showFolder' hasTrailingSlash pieces = showFolder hasTrailingSlash (unsafeToPiece "root" : pieces)
65− showFolder :: Pieces -> H.Html
69+ showFolder :: Bool -> Pieces -> H.Html
66− showFolder [] = "/" -- won't happen
70+ showFolder _ [] = "/" -- won't happen
67− showFolder [x] = H.toHtml $ showName $ fromPiece x
71+ showFolder _ [x] = H.toHtml $ showName $ fromPiece x
68− showFolder (x:xs) = do
72+ showFolder hasTrailingSlash (x:xs) = do
73+ let len = length xs - (if hasTrailingSlash then 0 else 1)
69− let href = concat $ replicate (length xs) "../" :: String
76+ | otherwise = concat $ replicate len "../" :: String
70 H.a ! A.href (H.toValue href) $ H.toHtml $ showName $ fromPiece x
77 H.a ! A.href (H.toValue href) $ H.toHtml $ showName $ fromPiece x
71 " / " :: H.Html
78 " / " :: H.Html
72− showFolder xs
79+ showFolder hasTrailingSlash xs
74-- | a function to generate an HTML table showing the contents of a directory on the disk
81-- | a function to generate an HTML table showing the contents of a directory on the disk
@@ -79,11 +86,12 @@ defaultListing pieces (Folder contents) = do
79-- a new page template to wrap around this HTML.
86-- a new page template to wrap around this HTML.
81-- see also: 'getMetaData', 'renderDirectoryContents'
88-- see also: 'getMetaData', 'renderDirectoryContents'
82−renderDirectoryContentsTable :: String
89+renderDirectoryContentsTable :: [T.Text] -- ^ requested path info
84 -> [Either FolderName File]
92 -> [Either FolderName File]
86−renderDirectoryContentsTable haskellSrc folderSrc fps =
94+renderDirectoryContentsTable pathInfo' haskellSrc folderSrc fps =
87 H.table $ do H.thead $ do H.th ! (A.class_ "first") $ H.img ! (A.src $ H.toValue haskellSrc)
95 H.table $ do H.thead $ do H.th ! (A.class_ "first") $ H.img ! (A.src $ H.toValue haskellSrc)
88 H.th "Name"
96 H.th "Name"
89 H.th "Modified"
97 H.th "Modified"
@@ -110,7 +118,13 @@ renderDirectoryContentsTable haskellSrc folderSrc fps =
110 (fromPiece -> "") -> unsafeToPiece ".."
118 (fromPiece -> "") -> unsafeToPiece ".."
112 let isFile = either (const False) (const True) md
120 let isFile = either (const False) (const True) md
121+ href = addCurrentDir $ fromPiece name
123+ case reverse pathInfo' of
124+ "":_ -> x -- has a trailing slash
125+ [] -> x -- at the root
126+ currentDir:_ -> T.concat [currentDir, "/", x]
113− H.td (H.a ! A.href (H.toValue $ fromPiece name `T.append` if isFile then "" else "/") $ H.toHtml $ fromPiece name)
127+ H.td (H.a ! A.href (H.toValue href) $ H.toHtml $ fromPiece name)
114 H.td ! A.class_ "date" $ H.toHtml $
128 H.td ! A.class_ "date" $ H.toHtml $
115 case md of
129 case md of
116 Right File { fileGetModified = Just t } ->
130 Right File { fileGetModified = Just t } ->