2

the problem: we are porting a wordpress blog to lektor. The slugs in wordpress of the post are directly under the main domain e.g. www.mypage.com/my-blogpost-about-food/ not www.mypage.com/blog/my-blogpost-about-food/.

Now the owner is not ready to accept any broken links. Broken links from the outside, e.g. some random internet page links to www.mypage.com/my-blogpost-about-food/. This link will not work in lektor. This will decrease the page rank of the redesign of the page with lektor. What can I do to avoid this?

Again, in our current wordpress website

the main blog page sits under:

www.mypage.com/blog/

each blog post has a unique slug, NOT under /blog/ but directly in the main. e.g.

www.mypage.com/my-blogpost-about-food/

What can I do, to make these URLs be valid for lektor as well? that e.g. mypage.com/my-blogpost-about-food is a blog post.

EDIT: this is what lektor does not support. Blog posts in lektor must sit in www.mypage.com/blog/SINGLE-BLOG-POSTS-MUSTBEHERE but I want the blog posts to be here www.mypage.com/SINGLE-BLOG-POSTS-MUSTBEHERE

reading here https://www.getlektor.com/docs/content/urls/

if I go to the system fields and enter my-blogpost-about-food it will still appear in /blog/my-blogpost-about-food/

reading here it becomes clear that I cannot change the slug in the parent model neither:

With the above settings the blog will live at blog/ and the posts at blog/. But what if you want to put the date of the blog post into the URL? That's thankfully very easy. All you need to do is to set up a new URL format for the children. Just edit blog.ini and add this to the [children] section:

slug_format = {{ (this.pub_date|dateformat('YYYY/M/') if this.pub_date) ~ this._id }}

What this does is that it will prepend the year (YYYY) and month (M) to the ID of the page if the publication date is configured. Otherwise it will just use the ID of the page. With this change our blog post will move from for instance blog/hello/ to blog/2015/12/hello/.

now how would I achieve a behaviour similar to this?

this is the formal of the perma links of our wordpress installation: enter image description here

Toskan
  • 13,911
  • 14
  • 95
  • 185
  • [How to show my posts in the first page and not in the “/blog” and maintaining other sub folders working like “/about” and “/projects”](https://stackoverflow.com/q/37473790/1591669) – unor Oct 17 '17 at 23:40

2 Answers2

2

This is possible. If you started with the default setup from lektor quickstart:

  • In models/blog-post.ini, remove hidden = yes
  • In models/blog.ini, under the pagination section, add items = site.query('/').filter(F._model == 'blog-post')

The first step lets you create blog posts under root in the admin. The second step tells the page blog to look for its pagination items under /, and only include the ones of type blog-post. This will exclude e.g. About, Blog, etc.

You will now have your site's home page at /, a blog page with list of all posts at /blog, and each post will be located at example.com/my-blogpost-about-food/.

To create a new blog post in the admin, go to the root admin page (not the /blog admin page), click the +, and select Blog Post for your new page type. It will show up in the list on /blog, and live directly under /.

Wisco crew
  • 1,337
  • 1
  • 17
  • 25
  • it is possible yes, but it doesn't work well. What about having pagination for the blogs? archives? the lektor admin backend gets super messy because all blog posts are in the root folder, welcome in greeting 100 blog posts in the main root. You can do it yes, but it doesn't work well at all... – Toskan Jul 23 '18 at 05:49
  • I believe pagination should work normally. Yes, the admin can get crowded... I would consider this a workaround, the ideal solution would be to configure permalinks in the manner of wordpress. Until and if lektor implements that, this will at least give the desired result. – Wisco crew Jul 23 '18 at 06:20
  • I can assure you that the pagination gets very messy. Notice: in wordpress it is no problem to have a blog post in `/`, but have a bunch of blog posts as well in `/mainblogpost/subblogpost` or have some as well in `/mikesblog/blogpost`. – Toskan Jul 24 '18 at 05:15
0

I'm not certain I understand exactly what you want to achieve. If I understand correctly you can possibly solve this using the replaced_with for children functionality:

https://www.getlektor.com/docs/guides/categories/

runfalk
  • 1,996
  • 1
  • 17
  • 20
  • interesting. But `replaced_with` in the end of the day, is just a filter or select of posts. E.g. you go to `/project/categories/FOOBAR` it will select all posts that contain `FOOBAR` category. What I really would want is something that solves `/FOOBAR` without `/project/categories/` – Toskan Jul 07 '17 at 21:44
  • what I thought is maybe just using symlinks or duplicates of the same files / folders in the main folder and having the URLs be absolute. This would solve the issue – Toskan Jul 07 '17 at 22:33