middleman / middleman-blog

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

Custom URL for posts? #328

Closed silasb closed 7 years ago

silasb commented 7 years ago

I'm trying to get a post to have a custom URL/permalink. Lets say that I have a blog post titled "Uses" and I want it to be located at /uses. I know I could easily create a custom page outside the blog engine, but I want to include comments as well, which means that it makes sense to be a blog post.

I've started hacking on this with custom frontmatter: permalink: /test for right now. I've modified some middleman-blog code to make the article.destination_path equal to the permalink frontmatter. My sitemap looks like this:

Path: blog/2016-12-10-new-use-page-added.html
Build Path: /test/index.html
URL: /test/
Source File: source/blog/2016-12-10-new-use-page-added.html.markdown
Data: {“title"=>"New Use Page Added", "date"=>"2016-12-10 15:37 UTC", "permalink"=>"/test"}
Options: {:lang=>:en}
Locals: lang

But when I click the link in the http://localhost:4567/test/ I get 404 not found. So it looks like it's not picking up the new route, but looking through the middleman-blog code I can't figure out how it works. I feel like I'm getting close, but it's not 'clicking.' Any help would be appreciated.

silasb commented 7 years ago

Okay, I think I figured it out. article.destination_path can't start with a forward-slash.

Here is my change to handle the destination_path

if article.data.has_key? 'permalink'
  article.destination_path = ::Middleman::Util.normalize_path article.data['permalink']
else
  article.destination_path = template_path @permalink_template, article
end

Does anyone thing this is a good feature to add? I can do a formal PR with tests if needed.

iwarner commented 7 years ago

Hiya

Do you know you can include

---
slug : new-path/to-post
---

In the frontmatter

This will override the blog.permalink = "{category}/{title}.html" from the config.rb.

iwarner commented 7 years ago

@silasb Did my post clear this up - closing - please re-open if its still an issue.

silasb commented 7 years ago

Haven't had time to check. I'll look at it next time I get a blog post ready.

—Silas

On Thu, Mar 23, 2017 at 8:23 PM, Ian Warner notifications@github.com wrote:

Closed #328 https://github.com/middleman/middleman-blog/issues/328.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/middleman/middleman-blog/issues/328#event-1013462113, or mute the thread https://github.com/notifications/unsubscribe-auth/AACe3kBjeD4UZFyE3jx2M7IQ1ew5AHlSks5row0GgaJpZM4LMfMB .