middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
325 stars 179 forks source link

blog.permalink get confused with the {title} #338

Closed andreamoro closed 7 years ago

andreamoro commented 7 years ago

As far as I understand the blog.permalink should allow to build the final URL in whichever desired format, also using frontmatter properties. However, no matter whether I use the {title} or :title, the final permalink title always correspond to the filename.

Let's say a default source filename format as %Y-%m-%d-something ... the title in this circumstance is the filename and not the value in the front-matter.

It would be good renaming this as "filename", leaving the title (which it is likely to be used in the frontmatter) for what the real word mean implies.

andreamoro commented 7 years ago

Just to add something else. According to the link below, a slug should be already produced when the :title is used.

http://www.rubydoc.info/github/middleman/middleman-blog/Middleman%2FBlog%2FBlogArticle%3Aslug

iwarner commented 7 years ago

Hiya,

Thanks for sending in the your report. To further aid in finding the issue can you please supply either a full repository that mimics your issue. Or at least a GIST of the config.rb file and an explanation on what steps to take to replicate this

Thank you.

andreamoro commented 7 years ago

Hi Ian,

Below the config.rb for my project.

activate :i18n, :mount_at_root => false, :templates_dir => "content", :locales => [:en, :it]
activate :directory_indexes

activate :autoprefixer do |config|
  config.browsers = ['last 2 versions', 'Explorer >= 9']
end

set :markdown, auto_ids: false
set :markdown_engine, :kramdown

activate :blog do |blog|
  blog.name = "blog";
  blog.prefix = I18n.locale.to_s+'/blog'
  blog.permalink = "{category}/:permalink"
  blog.layout = "Blog-inner"
  blog.summary_separator = /(READMORE)/
  blog.summary_length = 390

  blog.generate_day_pages = false
  blog.generate_month_pages = false
  blog.generate_year_pages = false

  # Enable pagination
  blog.paginate = true
  blog.per_page = 6
  blog.page_link = I18n.t(:blogPageLink) + "-{num}"#
end

As for the repository, not sure I can share that one that easily, but have a look at the screenshot below that shows the structure of my blog posts:

screen shot 2017-03-24 at 19 58 54

And the FrontMatter of one of them

---
date: 2015-03-03
cssLayout: blog
category: test
tags: test
title: "Keep going with the development"
permalink: "ciao"
description: "Let's see whether this works"
keywords: 'keyword 1, keyword 2'
author: Andrea Moro
heading: This is my header
SearchFromSummary: true
---

Now, the logic would have suggested a blog.permalink = "{category}/:title" the title in the FrontMatter being to construct the permalink. However, the title in the case of this project always equals to the "filename" of the blog post without the date.

In the case of the frontmatter above, that is "keepgoing".

Hence my suggestion to rename the property / behaviour of the title into filename.

Hope this makes more sense, or that you can spot something wrong in the configuration above.

Please note that I added the permalink data in the FrontMatter only after I realised I couldn't get this done any better.

Thanks

iwarner commented 7 years ago

Can you also add the versions of Middleman and Middleman Blog please.

iwarner commented 7 years ago

Ok getting to the bottom of this:

Title - is the correct name (and we wont be changing this) - for instance if you use the CLI command to create an article then you reference the title in this command and its applied to the filename for uniqueness : middleman article TITLE

If the Title appears in the filename then its takes precedence over the frontmatter as is applied to the metadata of the article, now for your scenario you want

config :

activate :blog do | blog |

    blog.sources   = ":category/:year-:month-:day.html"
    blog.permalink = ":category/{title}.html"

end

Post frontmatter :

---

title  : "Newer Article 1"
date   : 2011-01-01

---

Then the title becomes the slug for the permalink.

This example means you need to need to rename your files

If you want an extra front matter for say a title in the page then create something like

heading : "New custom page heading"

And use this in the article loop

And also stated in the Forum, consider the

slug : custom-url-for-each-post

This way you get full manipulation of the URL you want per post, better for SEO also.

andreamoro commented 7 years ago

Hi Ian,

Thanks for looking into this, but that "permalink" configurations were already explored, and that's the reason I opened this issue.

Please have a look at the new screenshot. As you can see, the title in the frontmatter is not used to build the permalink, and - assuming I understand you correctly - the filename "title" is not the same of the frontmatter title. And I don't understand in which other way a title could not appear in the filename itself. Can you please advice?

screen shot 2017-03-28 at 21 17 08

screen shot 2017-03-28 at 21 18 31