3

I'm making a website with Hakyll. I successfully created a RSS feed showing showing for each post the teaser section delimited by <!--more-->.

My problem is that this teaser section is shown in the full (templated) pages of these posts. And I would like only that is after <!--more--> and not before.

---
title: My Post
author: JeanJouX
date: 2016-09-06
tags: Haskell
---

The teaser of my post to be shown in the RSS feed. Not in the full page.

<!--more-->

The rest of the post to be shown in the full page of my website

Is it possible to do that with Hakyll?

kiamlaluno
  • 24,790
  • 16
  • 70
  • 85
JeanJouX
  • 2,347
  • 1
  • 22
  • 34
  • You can also store the teaser as metadata. Since Hakyll switched to YAML, multi-line strings should be supported. – Jan Tojnar Sep 27 '16 at 20:34

2 Answers2

4

I don't believe there is a method to do that built into Hakyll.

As I see it you have two options:

  • write a pass that strips the teaser from the document before rendering it on its own page

  • keep the teaser in the actual page, but use CSS to hide it

The first option is probably better, but requires mussing about with string manipulation and Hakyll compilers. If you want a place to start, take a look at the implementation of teaserFieldWithSeparator which uses the needlePrefix function from Hakyll.Core.Util.String to extract the teaser from the document body. You'll have to do the opposite: extract everything but the teaser.

If you do take this approach, you could contribute it back into Hakyll, saving the effort for people who want to do the same thing in the future.

The other option is hackier but easier. You can wrap all your teasers in a div with some CSS class:

<div class="teaser">
Some text.
</div>
<!--more-->

Then, in your page template, add a CSS rule that hides the teaser paragraph:

.teaser {
  display : none;
}

The text is still in the page's HTML so this is not an ideal solution, but you can make it work without needing to write any Hakyll code.

Tikhon Jelvis
  • 64,915
  • 16
  • 168
  • 210
0

Maybe it could be easier if you just put this teaser text in a separate metadata field? Like

---
title: My Post
author: JeanJouX
date: 2016-09-06
tags: Haskell
description: The teaser of my post to be shown in the RSS feed. Not in the full page.
---

The rest of the post to be shown in the full page of my website

Then you don't need to make that teaserField any more. You already have all you need in $description$, which you can use in rss, in html meta tags, anywhere.

Dahan
  • 163
  • 1
  • 10