'How to show my posts in the first page and not in the "/blog" and maintaining other sub folders working like "/about" and "/projects"

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.



Solution 1:[1]

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. :)

Solution 2:[2]

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.

Solution 3:[3]

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')

Solution 4:[4]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xiº
Solution 2 Chillar Anand
Solution 3 Animesh
Solution 4 webknjaz