Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow full-text blog post contents #34

Closed
alanhogan opened this issue May 4, 2011 · 4 comments
Closed

Allow full-text blog post contents #34

alanhogan opened this issue May 4, 2011 · 4 comments

Comments

@alanhogan
Copy link

In listing.js, in the loop {% for res in resource.node.walk_resources_sorted_by_time() %}, I can successfully display the full file contents ({{ res.source.read_all() }}) but it’s unclear how to actually just get the text (without the metadata). It’s clear that you have a way to parse this out (__read_resource__ in MetaPlugin) and it’s obviously used in the single page/resource context, but I’m at a loss for how to use it in the blog/listing context.

@alanhogan
Copy link
Author

For example, atom.j2 does this:

            {% refer to res.url as article -%}
            # ...
            {{ article.post|markdown|typogrify }}

But I’m not clear on what refer actually does or what .post is or why naïvely attempting to copy this code does not work in my listing.j2.

@navilan
Copy link
Member

navilan commented May 10, 2011

Hi,

The refer tag is used in conjunction with the mark tag.

So, in your content files you can mark portions of the content using the mark tag. When you refer to that file using the refer tag, the namespace will contain the rendered content for each of the mark tags as variables.

For example, you can see that the entire blog post is marked out here with a post marking. :
https://github.com/hyde/hyde/blob/master/hyde/layouts/basic/layout/blog.j2#L59-61

Also, see excerpts marked out separately in content:
https://github.com/hyde/hyde/blob/master/hyde/layouts/basic/content/blog/angry-post.html#L17-25

What this lets us do is to use either the entire post or just the excerpt in our atom feed:
https://github.com/hyde/hyde/blob/master/hyde/layouts/basic/layout/atom.j2#L37-45

These two files generate the feed with full-content or just excerpts:

  1. Full content: https://github.com/hyde/hyde/blob/master/hyde/layouts/basic/content/blog/atom.xml
  2. Excerpts: https://github.com/hyde/hyde/blob/master/hyde/layouts/basic/content/blog/excerpts.xml

HTH

@navilan navilan closed this as completed May 10, 2011
@alanhogan
Copy link
Author

Yes, very helpful. This is now my listing.j2:

{% extends "with-sidebar.j2" %}

{% block main %}
  {% from "post.j2" import blog_post with context %}
  {% from "macros.j2" import render_excerpt with context %}
  {% for res in resource.node.walk_resources_sorted_by_time() %}
    {% refer to res.url as article -%}       
    {% call blog_post(res) -%}         
      {{ article.post|markdown|typogrify }}
    {%- endcall %}
  {% endfor %}
{% endblock %}

The refer can’t go within the call but other than that it was fairly straightforward. I’m using a blog_post macro to create the container around each individual blog post.

The key thing to understand is that the refer to construct is really taking an argument (file) to parse and then assigning it to a variable, with the properties of various marked sections and the entire content (I assumed based off default_block) itself. Thanks for taking the time to explain.

@navilan
Copy link
Member

navilan commented May 11, 2011

No problem :) Glad it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants