ablog icon indicating copy to clipboard operation
ablog copied to clipboard

Postlist by tag -> handle zero items

Open plaindocs opened this issue 6 years ago • 6 comments

Hi, and thanks for the work on ablog

Any suggestions on how to handle the zero posts in a postlist situation. I think current behavious is to use all posts, but what I'd like is to be able to show aletrnative content if there are no posts.

plaindocs avatar Mar 21 '18 11:03 plaindocs

Sorry, I am not sure I follow. Do you have an example?

nabobalis avatar Mar 22 '18 18:03 nabobalis

Hi @nabobalis thanks for the response.

If I try to make a list of posts

.. postlist:: 10
   :date: %B %d, %Y
   :format: {title} - {date}
   :list-style: none
   :tags: a-tag-without-post

And I know that there are 0 posts with that tag I'd like to show alternate content. I think current behavior is to return latest posts with any tag.

plaindocs avatar Mar 26 '18 09:03 plaindocs

Ah ok. I understand now.

Unfortunately I don't have an answer on how to do that. If I get some time I will look into adding that as an extra feature to postlist. Ablog and how it works is still quite new to me.

nabobalis avatar Mar 26 '18 09:03 nabobalis

Many thanks :-)

I guess the easiest might be including text in th postlist construct itself. That way you can check inside the code, and not worry about returning the condition?

.. postlist:: 10 :date: %B %d, %Y :format: {title} - {date} :list-style: none :tags: a-tag-without-post :ifempty: More news soon

plaindocs avatar Mar 26 '18 09:03 plaindocs

Yeah, something like that would be my initial idea as well.

nabobalis avatar Mar 26 '18 09:03 nabobalis

Here's another possibility, based on post.py having this logic:

if colls:
  # Some stuff
else:
  posts = list(blog.recent(node.attributes['length'], docname, **node.attributes))

I suspect the way to nicely implement this is something like

...
else:
  if node.has_content:
    node.replace_self(child)
    continue
  else: 
    posts = list(blog.recent(...))

The advantage to this approach is that it lets one define a fairly rich default by doing something like this:

.. postlist::

  This is my first paragraph that shows up in an empty post list.

  And this paragraph also shows up.

rayalan avatar Aug 18 '19 18:08 rayalan