Open paternal opened 6 years ago
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.
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.
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).
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@8441cfda20308b580813724953f2ab59d47a18fd: 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@d41b1c6104db66a5470d01302bdd512de2bb98b7: 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@c3e3a7f66a8981ff5cbc322cf6ed1406218de39a (where it does not).
Everything is done on a debian testing, in a virtualenv, with python 3.10.5 and lektor 3.3.4.
🎉 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.
🎉 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.
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:
descendant
property of record, which acts like children
, but recursively, and use it instead of children
in lektor-tags;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?
@paternal Good finds. I think you should check out the discussion on https://github.com/lektor/lektor/issues/445 and see what you think.
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):{{ ('/@tag/' ~ t.lower())|url }}
produce the error(KeyError: '/@tag/foo/')
(and page does not build, and tag pages are not created);{{ ('/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 = /
?