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

Pages are not processed recursively #14

Open
paternal opened this issue Aug 2, 2018 · 8 comments
Open

Pages are not processed recursively #14

paternal opened this issue Aug 2, 2018 · 8 comments
Labels

Comments

@paternal
Copy link
Contributor

paternal commented Aug 2, 2018

The README says that in the config file, parent = / is allowed. However, if I set so (I would like my tags to be located at http://example.com/tag instead of http://example.com/blog/tag):

  • URLs {{ ('/@tag/' ~ t.lower())|url }} produce the error (KeyError: '/@tag/foo/') (and page does not build, and tag pages are not created);
  • with URLs {{ ('/blog@tag/' ~ t.lower())|url }}, tag pages are not created either, but blog posts are created, although tag URLs are http://example.com/blog@tag/foo, which are dead link.

How can I make lektor-tags work with parent = /?

@nixjdm
Copy link
Member

nixjdm commented Sep 14, 2018

To do this you need to set these:

parent = /
url_path = {{ this.parent.url_path }}{{ tag }}

and then reference that tag pages as just {{ ('/' ~ t.lower())|url }}, or I think {{ ('/@/' ~ t.lower())|url }} if you have pagination on your root page. I haven't tested that last bit though.

This will allow you to tag all children of the root page, and have tag pages generated as their siblings.
The parent is indirectly defining the pages that can be tagged, and the url_path is defining where the tags' pages go.

A caution: I'm not sure what will happen if names conflict, but it is surely something to watch out for. The default url_path inserts a tag/ with {{ this.parent.url_path }}tag/{{ tag }} partly to bypass that problem.

@nixjdm
Copy link
Member

nixjdm commented Sep 14, 2018

@paternal
Copy link
Contributor Author

In the example you gave, the links are correctly produced (although I would prefer /tag/tag1 and /tag/tag2 rather than /tag1 and /tag2, but I think I can change that with the url_path config option (maybe my original question was unclear)), but some of the pages tag1.html and tag2.html are not created, so the links (to the tag pages) are dead.

Pages tag1.html and tag2.html are not created (those are the tags of the root page), while page tag.html is created (which is the tag of the subpage). Why one is created, while the other are not?

Tested using Lektor 3.1.2.

@paternal
Copy link
Contributor Author

And I have to dig a little further (I will keep you updated), but on my website, using the same configuration as your example, not a single tag page is created (and no error is displayed or raised).

paternal pushed a commit to paternal/lektor-tags-mwe that referenced this issue Jun 28, 2022
@paternal
Copy link
Contributor Author

Four years later… Did I procrastinate?

With your advice, no tag page is generated…

I set up a repository with a very simple lektor website : https://github.com/paternal/lektor-tags-mwe

  • lektor quickstart + default configuration of lektor tags: paternal/lektor-tags-mwe@8441cfd: Everything works: the tag pages are generated as /blog/tag/tag1, /blog/tag/tag2

    $ lektor clean --yes && lektor build
    Started clean
    […]
    Finished clean in 0.28 sec
    Started build
    U index.html
    U projects/index.html
    U about/index.html
    U blog/index.html
    U blog/tag/tag2/index.html
    U blog/tag/tag1/index.html
    U blog/tag/tag3/index.html
    U static/style.css
    U blog/first-post/index.html
    U blog/blog1/index.html
    U blog/blog2/index.html
    U blog/blog3/index.html
    U blog/blog1/contents.lr~
    U blog/blog2/contents.lr~
    U blog/blog3/contents.lr~
    Finished build in 0.15 sec
    Started prune
    Finished prune in 0.00 sec
  • I implement your advice: paternal/lektor-tags-mwe@d41b1c6: Tag pages are no longer created; links are broken.

    $ lektor clean --yes && lektor build
    Started clean
    […]
    Finished clean in 0.27 sec
    Started build
    U index.html
    U projects/index.html
    U about/index.html
    U blog/index.html
    U static/style.css
    U blog/first-post/index.html
    U blog/blog1/index.html
    U blog/blog2/index.html
    U blog/blog3/index.html
    U blog/blog1/contents.lr~
    U blog/blog2/contents.lr~
    U blog/blog3/contents.lr~
    Finished build in 0.12 sec
    Started prune
    Finished prune in 0.01 sec

Other bugs (or behavior I don't understand):

  • I tried replacing blog by foo (in configs/tags.ini: parent = /foo instead of parent = /blog, and in templates/blog-post.html: /foo@tag/ instead of /blog@tag/), and tag pages are not generated. But if I also rename the directory content/blog to content/foo, tag pages are generated.

    Is this a (implicit ? undocumented ? buggy ?) requirement that the parent configuration option must be equal to the non-empty root of the pages being tagged?

  • You gave an example of a website where the parent configuration option is /, and it works: tag pages are created as expected. But I cannot see the difference between your demo project (where it works) and mine paternal/lektor-tags-mwe@c3e3a7f (where it does not).

Everything is done on a debian testing, in a virtualenv, with python 3.10.5 and lektor 3.3.4.

@paternal
Copy link
Contributor Author

🎉 I GOT THE CULPRIT ! 🎉

The issue is that with parent = / in the configs/tags.ini, tags defined in first level pages (e.g. /content/foo/contents.lr) are correctly handled (their corresponding tag page is created), but tags defined in second level pages or below (e.g. /content/foo/bar/contents.lr) are broken (their corresponding tag page is not created).

I have witnessed this behavior in your demo project, in my minimum working example, as well as in my real project.

@paternal paternal changed the title How to reference tags when parent = / With configuration option parent = /, tags are created for pages, but not for sub pages Jun 29, 2022
@paternal paternal changed the title With configuration option parent = /, tags are created for pages, but not for sub pages Pages are not processed recursively Jun 29, 2022
@paternal
Copy link
Contributor Author

🎉 I GOT THE CULPRIT ! (AGAIN) 🎉

Since the beginning, I assumed that pages were processed recursively, while only the children of the parent page (defined with option parent in the configuration file) are processed.

  • Easy fix: Improve documentation to state this.

  • Less easy fix: Make the page processing recursive. If we do want this (which is what I would like), I think most of the changes have to be done in lektor, that is:

    • add a descendant property of record, which acts like children, but recursively, and use it instead of children in lektor-tags;
    • add a recursive argument to query (or create a new method recursive_query, and use it in lektor-tags.

    If I start working on it, is there any chance that a pull request would be reviewed and merged?

@nixjdm
Copy link
Member

nixjdm commented Jul 14, 2022

@paternal Good finds. I think you should check out the discussion on lektor/lektor#445 and see what you think.

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

No branches or pull requests

2 participants