Reputation: 111
I'm trying to use Lektor as my blog platform, but I am running into a few issues.
Following the guide I can make everything work. My problem begin when I try to make the blog the first page, without the "/blog".
If I query in the page template the blogs children, the pagination don't work.
If I make the blog-post children of the page using "replaced_with = site.query('/blog')" the initial page renders fine, but if I try to access any page, appears a Not Found message.
My goal is show my posts in the first page and have other folders, like "/about" or "/projects" in the root folder.
Upvotes: 5
Views: 477
Reputation: 703
My latest use case was a little different. I didn't want a blog on the front page but a copy of /about
and the template used was page.html
.
So just replacing pagination items
as shown in https://stackoverflow.com/a/37558059/595220 (N.B. I used this one in the past for a blog too) wouldn't work. I needed to replace the whole this
variable which I've successfully done.
To achieve this, I've added the following at the top (well, almost — after the {% extends %}
line) of the page.html
template:
{% if this.path == '/' %}
{% set this = site.get('/about') %}
{% endif %}
This works great and I think it is somewhat more generic and elegant.
I suppose, to make it even better, I'd put '/about'
into a data bag and source from there. Moreover, I could have this whole mapping of / = /about
in a data bag to account for an unspecified number of aliases.
Upvotes: 0
Reputation: 5002
This is how I did it.
[model]
name = Blog
label = {{ this.title }}
hidden = yes
[fields.title]
label = Title
type = string
[children]
model = blog-post
order_by = -pub_date, title
[pagination]
enabled = yes
per_page = 5
items = this.children.filter(F._model == 'blog-post')
Upvotes: 0
Reputation: 111
I get it! The way to do it was setting a query in the "items" key on the page model.
Like this:
[model]
name = Page
label = {{ this.title }}
hidden = yes
protected = yes
[fields.title]
label = Title
type = string
[pagination]
enabled = yes
per_page = 10
items = site.query('/blog')
After that it worked like a charm. :)
Upvotes: 6
Reputation: 29524
I had same problem. I tried several thing and none of them worked.
I ended up doing page redirection. Lektor doesn't support redirects yet, they are working on it.
I created home.html
so that it redirects to /blog
.
<meta http-equiv="refresh" content="0; url=http://example.com/blog/" />
This is deprecated by WWC. Until lektor supports redirection, this the way to go.
Upvotes: 0