Repository: getnikola/nikola

Issue:
Post-list plugin shouldn't list the post where the post-list directive is declared
Post: `posts/xyz.rst` with tags: `version control`, `mercurial`

At the end, I declare:

```rst
.. post-list::
    :tags: version control, mercurial
```

The problem is that the post `xyz.rst` is listed at the post-list. This is redundant.

I have an idea how to fix this, but I need some feedback about the changes I'd make.
I know the post path being compiled is stored at `self.state.document.settings._nikola_source_path`.
I could pass this piece of information to `_do_post_list` via the `filename` parameter and then remove the post from the `timeline`. However, I'm not sure about the impact in `self_post`. Would it still be necessary if the post is removed?

Any suggestions?



Post-list plugin shouldn't list the post where the post-list directive is declared
Post: `posts/xyz.rst` with tags: `version control`, `mercurial`

At the end, I declare:

```rst
.. post-list::
    :tags: version control, mercurial
```

The problem is that the post `xyz.rst` is listed at the post-list. This is redundant.

I have an idea how to fix this, but I need some feedback about the changes I'd make.
I know the post path being compiled is stored at `self.state.document.settings._nikola_source_path`.
I could pass this piece of information to `_do_post_list` via the `filename` parameter and then remove the post from the `timeline`. However, I'm not sure about the impact in `self_post`. Would it still be necessary if the post is removed?

Any suggestions?





Discussion:
It's probably easier to just try it and see if it works :-)
Ok!
> I know the post path being compiled is stored at `self.state.document.settings._nikola_source_path`.

You cannot depend on that if shortcodes are used.
Is there another way to get this information?
Shortcodes have a filename parameter
It's probably easier to just try it and see if it works :-)
Ok!
> I know the post path being compiled is stored at `self.state.document.settings._nikola_source_path`.

You cannot depend on that if shortcodes are used.
Is there another way to get this information?
Shortcodes have a filename parameter

Resolving patch:
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -178,9 +178,10 @@ def run(self):
         template = self.options.get('template', 'post_list_directive.tmpl')
         sort = self.options.get('sort')
         date = self.options.get('date')
+        filename = self.state.document.settings._nikola_source_path
 
         output, deps = _do_post_list(start, stop, reverse, tags, require_all_tags, categories, sections, slugs, post_type, type,
-                                     all, lang, template, sort, state=self.state, site=self.site, date=date)
+                                     all, lang, template, sort, state=self.state, site=self.site, date=date, filename=filename)
         self.state.document.settings.record_dependencies.add("####MAGIC####TIMELINE")
         for d in deps:
             self.state.document.settings.record_dependencies.add(d)
@@ -246,6 +247,9 @@ def _do_post_list(start=None, stop=None, reverse=False, tags=None, require_all_t
     # else: # post
     #    timeline = [p for p in site.timeline if p.use_in_feeds]
 
+    # self_post should be removed from timeline because this is redundant
+    timeline = [p for p in timeline if p.source_path != filename]
+
     if categories:
         timeline = [p for p in timeline if p.meta('category', lang=lang).lower() in categories]
 


Test patch: