jekyll / jekyll-archives

:books: Archive pages for your Jekyll tags and categories.
https://jekyll.github.io/jekyll-archives/
MIT License
436 stars 99 forks source link

post.content markdown not rendered #28

Open gdhnz opened 9 years ago

gdhnz commented 9 years ago

I'm displaying full posts in my archives but the post is displaying the raw markdown and not being rendered.

gdhnz commented 9 years ago

Using {{ content }} also doesn't show the content at all.

parkr commented 9 years ago

Ah, I see. Generators are called before the render process is complete. That said, this should work nevertheless. Can you post a link to your site? What does your archive template look like? What version of Jekyll are you using?

gdhnz commented 9 years ago

I haven't got the site live yet as there's still a lot of other things I need to first.

Here's the archive layout I'm using with the Jekyll 2.5.2.

---
layout: default
---

<h2 class="archive-title">Archives: {{ page.title | date: '%B %Y' }}</h2>
{% for post in page.posts %}
<article> 
    <header class="entry-header">
        <h2 class="entry-title">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
        </h2>
        <time class="published" datetime="{{ post.date }}" pubdate="">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date_to_string }}</a>
        </time>
    </header>

    <div class="entry-content">
        {{ content }}
    </div>
</article>
{% endfor %}

Using {{ content }} instead of {{ page.content }} doesn't return anything.

parkr commented 9 years ago

Yeah it has to be post.content instead of content or page.content.

gdhnz commented 9 years ago

and we're back to my original statement. When I use post.content, none of the markdown or liquid tags are rendered.

parkr commented 9 years ago

and we're back to my original statement. When I use post.content, none of the markdown or liquid tags are rendered.

What does that mean? Plain text? Or a code block? Can you paste a screenshot?

gdhnz commented 9 years ago

Here's the screenshot.

screen shot 2014-12-19 at 1 01 49 pm

alfredxing commented 9 years ago

Is this not the case for any post/page listing? post.content contains the raw input, not the processed output.

gdhnz commented 9 years ago

Here's the snippet for my index.html file that displays everything correctly.

<div class="listing">
    {% for post in paginator.posts %}
    <article> 
        <header class="entry-header">
            <h2 class="entry-title">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
            </h2>
            <time class="published" datetime="{{ post.date }}" pubdate="">
            <a href="{{ post.url | prepend: site.baseurl }}">{{ post.date | date: '%B %d, %Y' }}</a>
            </time>
        </header>
        <div class="entry-content">
            {{ post.content }}
        </div>
    </article>
    {% endfor %}
</div>
davepeck commented 9 years ago

I'm running into this bug too -- {{post.content}} in an archive page loop does not process through markdown -- so you end up getting the raw markdown text instead of intended HTML.

parkr commented 9 years ago

I'm running into this bug too -- {{post.content}} in an archive page loop does not process through markdown -- so you end up getting the raw markdown text instead of intended HTML.

Generators are run before the render step. https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb#L51-L58

davepeck commented 9 years ago

Understood, thanks!

I'm wondering where the solution lies. It feels like the current behavior is undesirable. Is this something that needs to be filed against Jekyll itself -- an improvement for Generators for future consideration? Or is there a way to improve jekyll-archives here? Thanks.

parkr commented 9 years ago

The solution is to allow Jekyll to do the rendering itself. The jekyll-paginate process does this by appending a Page to site.pages and letting Jekyll do its thing. From a cursory glance at the source code here, the render process is taken care of here, which would yield this error. /cc @alfredxing

alfredxing commented 9 years ago

@parkr Nice catch! I'll see about fixing that up and just adding it as a Page.

matthewmcvickar commented 9 years ago

I’m not sure if I’m misunderstanding the status of this issue, but is there a workaround for this currently, or does the jekyll-archives plugin need to be fixed?

alfredxing commented 9 years ago

@matthewmcvickar Sorry for the wait; I've been quite busy recently with school. I'll get around to this as soon as I have some time!

alfredxing commented 9 years ago

Just looked into this again, and now I remember why I didn't append the archives to site.pages: if this was done, anyone iterating over site.pages (in the nav, for example) would see archive pages as well... @parkr Any suggestions?

parkr commented 9 years ago

The only way to enforce this would be to render every item...

alfredxing commented 9 years ago

You mean render every page as necessary?

DylanVann commented 9 years ago

The markdownify filter might be useful for this.

{{post.content | markdownify}} or {{ content | markdownify}}, whatever fits.

gdhnz commented 9 years ago

While using markdownify does appear to render the markdown, it doesn't render {% highlight bash %}

sumdog commented 9 years ago

I had this same issue. I have an _include file for all my posts. For the archive layout, I just did the following:

{% for post in page.posts %}
  {% include post.html item=post markdown=true %}
{% endfor %}

and within my post include:

  {% if include.markdown %}
    {{ include.item.content | markdownify }}
  {% else %}  
    {{ include.item.content }}
  {% endif %}

Since generators are run before renders, this might be the only solution (unless you do the markdown step in the generation in jekyll-archives itself... haven't looked at the code to see how possible that is)

gdhnz commented 9 years ago

While the previous suggestion of an include works for markdown, it still doesn't render {% highlight bash %} blocks.

Is there a similar method like markdownify that does render code highlights? hilightify?

{{post.content | markdownify | hilightify }}
MaximeKjaer commented 9 years ago

Not to my knowledge. I've been able to get rid of the problem by downgrading from jekyll-3.0.0.pre.beta8 to jekyll-2.5.3 for the time being... (though that means going back to dealing with issue #2607 which was fixed in the beta :disappointed_relieved:).

nbolten commented 9 years ago

This still happens with jekyll-2.5.3 and jekyll-archives 2.0.0. @MaximeKjaer, what is your setup where you can get post.content rendered from a jekyll-archives layout?

AaronLayton commented 9 years ago

I have been getting the same issue as this. It was strange because some of the .content was coming through after the markdown had been applied... and then stopped on a few others...

My solution was

{% for post in site.categories.solutions reversed %}
    {{ post.content | markdownify }}
{% endfor %}
insipx commented 8 years ago

Getting the same issue with this when using {{post.excerpt}}

{{post.exceprt | markdownify}} works, but doesn't render highlight blocks {% highlight ruby %}

is there any fix for this?

MaximeKjaer commented 8 years ago

@nbolten I'm having some real trouble replicating this. It happened without jekyll-archive (I somehow overlooked that this was a jekyll/jekyll-archives, and not jekyll/jekyll issue page, so I don't know if my initial comment still is relevant -- sorry!).

I'll try to look into it some more, and will post if I find anything of interest.

TheoWinterhalter commented 8 years ago

This problem also happens with collections. I guess this means you should really provide a way to render the content of an element like markdownify (which by the way doesn't render tables and such things provided by redcarpet if you specify it in _config.yml).

Thanks!

EDIT: Maybe this is a different issue though. Collections documents supposedly have an output property which does exactly what we want, but for me, it does nothing. http://jekyllrb.com/docs/collections/#documents

nexocentric commented 8 years ago

I am having the same problem running on Debian Jessie using the following gems.

bigdecimal (1.2.6) bundler-unload (1.0.2) executable-hooks (1.3.2) gem-wrappers (1.2.7) io-console (0.4.3) json (1.8.1) minitest (5.4.3) power_assert (0.2.2) psych (2.0.8) rake (10.4.2) rdoc (4.2.0) rubygems-bundler (1.4.4) rvm (1.11.3.9) test-unit (3.0.8)

I believe I'm running Jekyll version 3, but I don't know how to get the current version of Jekyll that I'm using.

The solution that worked for me was: {{ page.content | markdownify }}

I was using Kramdown for my markdown.

nexocentric commented 8 years ago

@DylanVann If content written in markdown needs to be run through a filter to be displayed properly, shouldn't that be added to the documents? Or is this thread actually not a question, but a bug?

metachris commented 8 years ago

Any feedback on this issue?

{{ post.content | markdownify }} works as a workaround for the markdown, but syntax is not highlighted.

Seeing this on jekyll 3.1.1

fabacab commented 8 years ago

Just a note to say I ran into this today, too. {{ page.content | markdownify }} works for me, too, though, so all things considered, pretty minor.

OscarPellicer commented 8 years ago

I was having this problem, where a post preview would (only in some pages) show unrendered liquid code from some includes I had

<div class="panel-body remove-jekyll-js"> {{ post.content | strip_html | truncatewords:43 }} </div>

Since I wasn't able to find a solution I included this quick and dirty fix at the end of every page, until I find something better:

<script> 
        $( ".remove-jekyll-js" ).each(function() {
            var post= $( this ).html();
            $( this ).html(post.replace(/\{\%.*?\%}/, "").replace(/\{\%.*?\.\.\./, "..."));
        });
</script>

This uses jquery and js to get rid of {% whatever %} and {% whatever ... Maybe someone finds it useful in the meanwhile.

breakingespanol commented 8 years ago

I'm having this issue as well, however, part of the page is rendering but not all. Specifically, the unordered list is not rendering.

repo: where: http://breakingespanol.com/about/ my page layout:

--- layout: default --- <article class="page"> <h1>{{ page.title }}</h1> <div class="entry"> {{ content }} </div> `

markdown-error

KendallPark commented 8 years ago

Interestingly, my gh-pages site depends on page.content being the raw markdown of the page. Now it seems that gh-pages has "fixed" this, subsequently breaking my site, which requires raw markdown for Remark.js. Is there a way to get the raw, unprocessed markdown?

ghost commented 8 years ago

@KendallPark I don't think your problem is related to jekyll-archives however a solution for you is to add a generator plugin that adds a variable containing the raw markdown. Use this variable in place of page.content. However you'll have to build your site locally before pushing to Github Pages.

groundh0g commented 8 years ago

Sorry if this is off-topic, but I ran across a similar issue with a very simple fix.

My code to aggregate a list of book summaries looked like this:

{% for file in site.pages %}
    {% if file.path contains "books/" and file.path contains "/summary.md" %}
        {{ file.content }}
    {% endif %}
{% endfor %}

The content wasn't formatted. So I tried the markdownify solution and it became unformatted, raw HTML. That made me think it was being treated like a code block (indented by more than 4 spaces).

The following fixed it for me. (Note the unindented {{ file.content }} statement.)

{% for file in site.pages %}
    {% if file.path contains "books/" and file.path contains "/summary.md" %}
{{ file.content }}
    {% endif %}
{% endfor %}
groundh0g commented 8 years ago

@breakingespanol, when you wrap markdown in a <div/>, you'll see that behavior. Does the markdownify filter not fix it?

(eg. <div class='entry'>{{ content | markdownify }}</div>)

2m commented 7 years ago

Got bitten by this in https://github.com/akka/blog

Worked around with:

{% assign curlyend = '}' %}
{{ p.content | markdownify | strip_html | replace: "{% include JB/setup %", "" | replace: curlyend, "" | truncatewords: 30 }}
alfredxing commented 7 years ago

@2m Are you using jekyll-archives? I looked at your repo and it looks like you're using Jekyll Bootstrap, but I couldn't find Archives in your _config.yml anywhere.

2m commented 7 years ago

Hm. You might be right. I am not that experienced in jekyll. If you say that you could not find jekyll-archives in the project, then I am not using it. Sorry for the noise here. The problem described here looked similar enough to the one I was having, therefore I assumed my blog was using jekyll-archives for displaying post archive.

ashmaroli commented 5 years ago

Hello everyone!! Is this still an issue while using Jekyll 3.7 / Jekyll 3.8 ? If yes, would you be able to provide a link to a minimal test repository that I can just clone and use..?

wez commented 5 years ago

I think this issue and https://github.com/jekyll/jekyll/issues/6209 have some similarities in how they manifest. I'm using GH pages with no explicit configuration of jekyll-archives so perhaps this issue is not the best one to remain open to track this. I pushed https://github.com/wez/wezterm/commit/b0f2edd7114f8d66c5e1ab765c8f61b9ca4f9e0f which captures the state of the weirdness in case someone would like to dig in and resolve things. I have a workaround that I'm "OK" to stick with for now.

trivedihiralm commented 5 months ago

Running into similar issue. markdownify did help with rendering the page correctly but my .md file has an HTML included in it. {% include links.html %}

The links.html doesn't get rendered correctly for a few when the HTML files are getting generated. Any tips on how to solve this?