Hey RJ!
In order to drop the date from the URL, let's write a small utility:
-- Turns 'foo-bar' into 'bar'.
dropComponent :: String -> String
dropComponent str = case break (== '-') str of
(_, _ : str') -> str'
(str', []) -> str'
This makes writing a drop date function very easy:
-- Turns '2014-06-20-project-name.html' into 'project-name.html'.
dropDate :: String -> String
dropDate = dropComponent . dropComponent . dropComponent
Now we need a way to generate "pretty" urls. If you want to support:
http://0.0.0.0:8000/projects/project-name/
Then a good approach is to generate:
http://0.0.0.0:8000/projects/project-name/index.html
Since this works with most servers (alternatively you can customize your
server, which is probably a neater way to do this, but I'm going to
assume you might not have complete control over the server).
import System.FilePath (dropExtension, takeBaseName, takeDirectory,
(</>))
prettyRoute :: Routes
prettyRoute = customRoute $ \identifier ->
-- Suppose we have:
-- filePath = 'projects/2014-06-20-project-name.html'
--
-- We get:
-- directory = 'projects'
-- baseName = '2014-06-20-project-name.html'
-- simpleName = 'project-name'
let filePath = toFilePath identifier
directory = takeDirectory filePath
baseName = takeBaseName filePath
simpleName = dropExtension (dropDate baseName)
in directory </> simpleName </> "index.html"
This will write your file to:
_site/projects/project-name/index.html
So if you upload, it can be found by the server. However, this causes an
additional problem. Now, the links embedded in your templates will
contain this URL by default, e.g.:
<a href="./project-name/index.html">Project Name</a>
Whereas we actually want something like:
<a href="./project-name/">Project Name</a>
This means you need to rewrite the URLs in your pages. You can use a
simple compiler to do this:
cleanUrls :: String -> Compiler String
cleanUrls = return . withUrls clean
where
clean url = case takeBaseName url of
"index.html" -> takeDirectory url
_ -> url
That should be it. 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/d/optout.