You'll have to excuse me for the simplicity of this problem, I'm very
new to both hakyll/haskell.
In the homepage of a site I'm currently working on I'm trying to
create a list of the most recent posts and use mootools.js accordion
to display the post once <h2 class="contentheader"> is clicked. It
works but within the post it replicates the body of the main page
(menu, header, etc..) around the post instead of just the body of the
post itself (if that makes sense).
-- from default.html
<div id="maincol">
$body$
</div>
Perhaps if I could rename the body of the post by using something like
(setFieldA "newsBody" $ arr pageBody) but I don't know haskell well
enough and don't know where to put it.
The problem is that you feed the posts to news_item.html. Using $body$
there will include the final representation of your post, that is,
including your site template.
What you want to do is change your posts compiler a little to something like:
match "posts/*" $ do
route $ ...
compile $ pageCompiler
... -- Other actions...
>>> arr (copyBodyToField "content"
-- Apply templates...
>>> applyTemplateCompiler ...
This way, the $content$ contains the post body *before* the templates
are applied, and you can use $content$ instead of $body$ in
news_item.html.
Hope this helps,
Cheers,
Jasper
On Sat, Apr 28, 2012 at 8:27 PM, Veritatem Ignotam
<veritatem.igno...@gmail.com> wrote:
> You'll have to excuse me for the simplicity of this problem, I'm very
> new to both hakyll/haskell.
> In the homepage of a site I'm currently working on I'm trying to
> create a list of the most recent posts and use mootools.js accordion
> to display the post once <h2 class="contentheader"> is clicked. It
> works but within the post it replicates the body of the main page
> (menu, header, etc..) around the post instead of just the body of the
> post itself (if that makes sense).
> Perhaps if I could rename the body of the post by using something like
> (setFieldA "newsBody" $ arr pageBody) but I don't know haskell well
> enough and don't know where to put it.
Thanks Jasper. I thought it had to be something like that.
I'm still not sure exactly where to put it. I tried putting it in my
newsCompiler but no joy.
How exactly does
>>> setFieldPageList (newest 5)
"templates/news_item.html" "news"
(newsDirs `mappend` inGroup Nothing)
work? Does it grab already rendered pages or does it recompile them?
If it recompiles them, with which compiler?
Here's the whole code. It's mostly Benedict Eastaugh's (thanks!) code
from extralogical.net as it was almost exactly what I needed.
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
module Main where
-- | Set defaults for a few keys. Print the string again if not
handled.
missingHandler :: String -> String
missingHandler k = case k of
"pageClass" -> "default"
_ -> "$" ++ k ++ "$"
-- | Take a page like @\"/about/notebooks.md\"@ and route it to
-- @\"/about/notebooks\"@, i.e. turn a filename into a drectory.
--
routePage :: Routes
routePage = customRoute fileToDirectory
-- | Drop the date and set the file extension to ".html" when routing
news.
--
routeNews :: Routes
routeNews = routeNewsExt ".html"
-- | Drop the date and set the file extension to ".raw" when routing
the raw
-- versions of news.
--
routeNewsRaw :: Routes
routeNewsRaw = routeNewsExt ".txt"
-- | Article routing with a specific file extension.
--
routeNewsExt :: String -> Routes
routeNewsExt ext = customRoute
$ flip replaceExtension ext
. flip replaceDirectory "news"
. dropDate
-- | Turn an @Identifier@ into a @FilePath@, dropping the date prefix
(e.g.
-- @\"2011-04-07-\"@) along the way.
dropDate :: Identifier a -> FilePath
dropDate ident = let file = toFilePath ident
in replaceFileName file (drop 11 $ takeFileName
file)
-- | Turn a filename reference into a directory with an index file.
--
fileToDirectory :: Identifier a -> FilePath
fileToDirectory = flip combine "index.html" . dropExtension .
toFilePath
-- | Date formatting.
--
formatDate :: Page a -> Page a
formatDate = renderDateField "published" "%B %e, %Y" "Date unknown"
-- | Publication and last modified date rendering.
--
publicationDates :: Page a -> Page a
publicationDates page = setField "publicationDates" datesString page
where
datesString = intercalate ". "
$ filter ((> 0) . length) [published, updated]
published = formatTime' "%B %e, %Y" $ getPublicationDate page
updated = formatTime' "Last updated %B %e, %Y" $
getUpdatedDate page
formatTime' :: String -> Maybe UTCTime -> String
formatTime' _ Nothing = ""
formatTime' format (Just t) = formatTime defaultTimeLocale format t
getPublicationDate :: Page a -> Maybe UTCTime
getPublicationDate page = parseTime defaultTimeLocale "%Y-%m-%d"
dateString
where
dateString = intercalate "-" $ take 3
$ splitAll "-" $ takeFileName (getField "path" page)
> The problem is that you feed the posts to news_item.html. Using $body$
> there will include the final representation of your post, that is,
> including your site template.
> What you want to do is change your posts compiler a little to something like:
> match "posts/*" $ do
> route $ ...
> compile $ pageCompiler
> ... -- Other actions...
> >>> arr (copyBodyToField "content"
> -- Apply templates...
<veritatem.igno...@gmail.com> wrote:
> Thanks Jasper. I thought it had to be something like that.
> I'm still not sure exactly where to put it. I tried putting it in my
> newsCompiler but no joy.
> How exactly does
>>>> setFieldPageList (newest 5)
> "templates/news_item.html" "news"
> (newsDirs `mappend` inGroup Nothing)
> work? Does it grab already rendered pages or does it recompile them?
> If it recompiles them, with which compiler?
> Here's the whole code. It's mostly Benedict Eastaugh's (thanks!) code
> from extralogical.net as it was almost exactly what I needed.
> {-# LANGUAGE OverloadedStrings #-}
> {-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
> module Main where
> -- | Set defaults for a few keys. Print the string again if not
> handled.
> missingHandler :: String -> String
> missingHandler k = case k of
> "pageClass" -> "default"
> _ -> "$" ++ k ++ "$"
> -- | Take a page like @\"/about/notebooks.md\"@ and route it to
> -- @\"/about/notebooks\"@, i.e. turn a filename into a drectory.
> --
> routePage :: Routes
> routePage = customRoute fileToDirectory
> -- | Drop the date and set the file extension to ".html" when routing
> news.
> --
> routeNews :: Routes
> routeNews = routeNewsExt ".html"
> -- | Drop the date and set the file extension to ".raw" when routing
> the raw
> -- versions of news.
> --
> routeNewsRaw :: Routes
> routeNewsRaw = routeNewsExt ".txt"
> -- | Turn an @Identifier@ into a @FilePath@, dropping the date prefix
> (e.g.
> -- @\"2011-04-07-\"@) along the way.
> dropDate :: Identifier a -> FilePath
> dropDate ident = let file = toFilePath ident
> in replaceFileName file (drop 11 $ takeFileName
> file)
> -- | Turn a filename reference into a directory with an index file.
> --
> fileToDirectory :: Identifier a -> FilePath
> fileToDirectory = flip combine "index.html" . dropExtension .
> toFilePath
> -- | Date formatting.
> --
> formatDate :: Page a -> Page a
> formatDate = renderDateField "published" "%B %e, %Y" "Date unknown"
> -- | Publication and last modified date rendering.
> --
> publicationDates :: Page a -> Page a
> publicationDates page = setField "publicationDates" datesString page
> where
> datesString = intercalate ". "
> $ filter ((> 0) . length) [published, updated]
> published = formatTime' "%B %e, %Y" $ getPublicationDate page
> updated = formatTime' "Last updated %B %e, %Y" $
> getUpdatedDate page
> formatTime' :: String -> Maybe UTCTime -> String
> formatTime' _ Nothing = ""
> formatTime' format (Just t) = formatTime defaultTimeLocale format t
I have one final question. I already tried your last suggestion but
renamed 'content' to 'news_content' and it wasn't working. Are there
limits to string used?
VI
On May 1, 3:27 pm, Jasper Van der Jeugt <m...@jaspervdj.be> wrote:
> On Tue, May 1, 2012 at 8:18 PM, Veritatem Ignotam
> <veritatem.igno...@gmail.com> wrote:
> > Thanks Jasper. I thought it had to be something like that.
> > I'm still not sure exactly where to put it. I tried putting it in my
> > newsCompiler but no joy.
> > How exactly does
> >>>> setFieldPageList (newest 5)
> > "templates/news_item.html" "news"
> > (newsDirs `mappend` inGroup Nothing)
> > work? Does it grab already rendered pages or does it recompile them?
> > If it recompiles them, with which compiler?
> > Here's the whole code. It's mostly Benedict Eastaugh's (thanks!) code
> > from extralogical.net as it was almost exactly what I needed.
> > {-# LANGUAGE OverloadedStrings #-}
> > {-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
> > module Main where
> > -- | Set defaults for a few keys. Print the string again if not
> > handled.
> > missingHandler :: String -> String
> > missingHandler k = case k of
> > "pageClass" -> "default"
> > _ -> "$" ++ k ++ "$"
> > -- | Take a page like @\"/about/notebooks.md\"@ and route it to
> > -- @\"/about/notebooks\"@, i.e. turn a filename into a drectory.
> > --
> > routePage :: Routes
> > routePage = customRoute fileToDirectory
> > -- | Drop the date and set the file extension to ".html" when routing
> > news.
> > --
> > routeNews :: Routes
> > routeNews = routeNewsExt ".html"
> > -- | Drop the date and set the file extension to ".raw" when routing
> > the raw
> > -- versions of news.
> > --
> > routeNewsRaw :: Routes
> > routeNewsRaw = routeNewsExt ".txt"
<veritatem.igno...@gmail.com> wrote:
> Thanks again. That worked.
> I have one final question. I already tried your last suggestion but
> renamed 'content' to 'news_content' and it wasn't working. Are there
> limits to string used?
> VI
> On May 1, 3:27 pm, Jasper Van der Jeugt <m...@jaspervdj.be> wrote:
>> Something like this should work, I think:
>> On Tue, May 1, 2012 at 8:18 PM, Veritatem Ignotam
>> <veritatem.igno...@gmail.com> wrote:
>> > Thanks Jasper. I thought it had to be something like that.
>> > I'm still not sure exactly where to put it. I tried putting it in my
>> > newsCompiler but no joy.
>> > How exactly does
>> >>>> setFieldPageList (newest 5)
>> > "templates/news_item.html" "news"
>> > (newsDirs `mappend` inGroup Nothing)
>> > work? Does it grab already rendered pages or does it recompile them?
>> > If it recompiles them, with which compiler?
>> > Here's the whole code. It's mostly Benedict Eastaugh's (thanks!) code
>> > from extralogical.net as it was almost exactly what I needed.
>> > {-# LANGUAGE OverloadedStrings #-}
>> > {-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
>> > module Main where
>> > -- | Set defaults for a few keys. Print the string again if not
>> > handled.
>> > missingHandler :: String -> String
>> > missingHandler k = case k of
>> > "pageClass" -> "default"
>> > _ -> "$" ++ k ++ "$"
>> > -- | Take a page like @\"/about/notebooks.md\"@ and route it to
>> > -- @\"/about/notebooks\"@, i.e. turn a filename into a drectory.
>> > --
>> > routePage :: Routes
>> > routePage = customRoute fileToDirectory
>> > -- | Drop the date and set the file extension to ".html" when routing
>> > news.
>> > --
>> > routeNews :: Routes
>> > routeNews = routeNewsExt ".html"
>> > -- | Drop the date and set the file extension to ".raw" when routing
>> > the raw
>> > -- versions of news.
>> > --
>> > routeNewsRaw :: Routes
>> > routeNewsRaw = routeNewsExt ".txt"
> Yes, they should be alphanumeric. So newsContent should work.
> Cheers,
> Jasper
> On Tue, May 1, 2012 at 10:45 PM, Veritatem Ignotam
> <veritatem.igno...@gmail.com> wrote:
> > Thanks again. That worked.
> > I have one final question. I already tried your last suggestion but
> > renamed 'content' to 'news_content' and it wasn't working. Are there
> > limits to string used?
> > VI
> > On May 1, 3:27 pm, Jasper Van der Jeugt <m...@jaspervdj.be> wrote:
> >> Something like this should work, I think:
> >> On Tue, May 1, 2012 at 8:18 PM, Veritatem Ignotam
> >> <veritatem.igno...@gmail.com> wrote:
> >> > Thanks Jasper. I thought it had to be something like that.
> >> > I'm still not sure exactly where to put it. I tried putting it in my
> >> > newsCompiler but no joy.
> >> > How exactly does
> >> >>>> setFieldPageList (newest 5)
> >> > "templates/news_item.html" "news"
> >> > (newsDirs `mappend` inGroup Nothing)
> >> > work? Does it grab already rendered pages or does it recompile them?
> >> > If it recompiles them, with which compiler?
> >> > Here's the whole code. It's mostly Benedict Eastaugh's (thanks!) code
> >> > from extralogical.net as it was almost exactly what I needed.
> >> > {-# LANGUAGE OverloadedStrings #-}
> >> > {-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
> >> > module Main where
> >> > -- | Set defaults for a few keys. Print the string again if not
> >> > handled.
> >> > missingHandler :: String -> String
> >> > missingHandler k = case k of
> >> > "pageClass" -> "default"
> >> > _ -> "$" ++ k ++ "$"
> >> > -- | Take a page like @\"/about/notebooks.md\"@ and route it to
> >> > -- @\"/about/notebooks\"@, i.e. turn a filename into a drectory.
> >> > --
> >> > routePage :: Routes
> >> > routePage = customRoute fileToDirectory
> >> > -- | Drop the date and set the file extension to ".html" when routing
> >> > news.
> >> > --
> >> > routeNews :: Routes
> >> > routeNews = routeNewsExt ".html"
> >> > -- | Drop the date and set the file extension to ".raw" when routing
> >> > the raw
> >> > -- versions of news.
> >> > --
> >> > routeNewsRaw :: Routes
> >> > routeNewsRaw = routeNewsExt ".txt"