Replacing all "/index.html" identifiers with "/" for urls

179 views
Skip to first unread message

Bram Neijt

unread,
Feb 1, 2013, 4:20:52 PM2/1/13
to hak...@googlegroups.com
I use a directory for every blog post like the example, but I would like to replace the urls which point to "something/index.html" to point to just plain "something/" as the index.html is implied by my webserver configuration.

I'm currently working with Hakyll 4 (source [1])

Greets,

Bram

Jasper Van der Jeugt

unread,
Feb 1, 2013, 4:42:18 PM2/1/13
to hak...@googlegroups.com
You can write something like this:

import Data.List (isSuffixOf)
import Hakyll

cleanIndexUrls :: Item String -> Compiler (Item String)
cleanIndexUrls = return . fmap (withUrls clean)
where
idx = "index.html"
clean url
| idx `isSuffixOf` url = take (length url - length idx) url
| otherwise = url

And use it pretty much in the same way as `relativizeUrls`.

Hope this helps,
Peace,
Jasper
> --
> You received this message because you are subscribed to the Google Groups
> "hakyll" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hakyll+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Bram Neijt

unread,
Feb 1, 2013, 5:01:00 PM2/1/13
to hak...@googlegroups.com
Cool! I tried working with relativizeUrls but got lost somewhere, your code works really well.

Thank you!

Bram

DarkFox

unread,
Apr 8, 2013, 3:50:29 AM4/8/13
to hak...@googlegroups.com
System Filepath has splitFileName, very nice for this.

import Control.Applicative ((<$>))
import Data.List           (isInfixOf)
import System.FilePath     (splitFileName)
import Hakyll

{- ... -}

removeIndexHtml :: Item String -> Compiler (Item String)
removeIndexHtml = return . (withUrls removeIndexStr <$>)
  where removeIndexStr :: String -> String
        removeIndexStr u = case splitFileName u of
            (d, "index.html") | isLocal d -> d
            _                             -> u
        isLocal :: String -> Bool
        isLocal = not . (isInfixOf "://")

--

Cheers,
DarkFox
Reply all
Reply to author
Forward
0 new messages