New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posts are being served as text/plain #277

Closed
brandonweiss opened this Issue Jan 9, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@brandonweiss

brandonweiss commented Jan 9, 2016

My setup worked on v3 but I can't figure out how to make it work on v4. My directory structure looks like this:

source/posts/2015-06-22-some-title.md
source/posts/2015-06-24-some-other-title.md

My URLs look like this:

http://myblog.com/some-title
http://myblog.com/some-other-title

On v3 my config looked like this:

activate :blog do |blog|
  blog.sources   = "posts/{year}-{month}-{day}-{permalink}.html"
  blog.permalink = "{permalink}"
  blog.layout    = "post"
end

Having to append .html to the end of sources was always kind of weird, but it worked. In v4 I have:

activate :blog do |blog|
  blog.sources   = "posts/{year}-{month}-{day}-{title}"
  blog.permalink = "{title}"
  blog.layout    = "post"
end

Now they're displayed correctly on the main page, but if I go to a permalink page it's served as text/plain instead of text/html. How do I get the correct behavior?

@Arcovion

This comment has been minimized.

Show comment
Hide comment
@Arcovion

Arcovion Jan 9, 2016

Member

Your posts must use .html.md extension instead of .md.

Member

Arcovion commented Jan 9, 2016

Your posts must use .html.md extension instead of .md.

@brandonweiss

This comment has been minimized.

Show comment
Hide comment
@brandonweiss

brandonweiss Jan 9, 2016

Oh. Why? They didn't before?

I understand the “tilt” pattern, but it doesn't seem to make any sense here. It makes sense for templates (foobar.html.erb), because it's HTML that you want to be parsed as ERB first. But these posts are not HTML with markdown in—they're just markdown, which happens to be converted to HTML. They're data, not templates.

That pattern was also created to handle the case where the final type is unknown. It could be foobar.html.erb or foobar.js.erb. Other middleman pages need that flexibility because they're templates—you might want to generate an XML feed or something. But the blog posts are always going to be HTML.

Right?

brandonweiss commented Jan 9, 2016

Oh. Why? They didn't before?

I understand the “tilt” pattern, but it doesn't seem to make any sense here. It makes sense for templates (foobar.html.erb), because it's HTML that you want to be parsed as ERB first. But these posts are not HTML with markdown in—they're just markdown, which happens to be converted to HTML. They're data, not templates.

That pattern was also created to handle the case where the final type is unknown. It could be foobar.html.erb or foobar.js.erb. Other middleman pages need that flexibility because they're templates—you might want to generate an XML feed or something. But the blog posts are always going to be HTML.

Right?

@Arcovion

This comment has been minimized.

Show comment
Hide comment
@Arcovion

Arcovion Jan 9, 2016

Member

See middleman/middleman-asciidoc#7 (comment).
You are right, but I quite like the explicitness.

I imagine it makes the underlying code simpler and easier to reason about, you just pop off each extension but the last and run it through Tilt.
Layouts aren't rendered on their own so it follows that they have no .html extension.
If someone does want to serve a raw markdown file with the .md extension they can do that - the user defines the file extension/mine-type explicitly.
As you say, you still had to be explicit in the past for stuff like foobar.erb -> foobar.js.erb or feed.slim -> feed.xml.slim. May as well do this everywhere.

That said, this is apparently missing from the docs - I couldn't find mention of it in the 'upgrading to v4' section. :/

Member

Arcovion commented Jan 9, 2016

See middleman/middleman-asciidoc#7 (comment).
You are right, but I quite like the explicitness.

I imagine it makes the underlying code simpler and easier to reason about, you just pop off each extension but the last and run it through Tilt.
Layouts aren't rendered on their own so it follows that they have no .html extension.
If someone does want to serve a raw markdown file with the .md extension they can do that - the user defines the file extension/mine-type explicitly.
As you say, you still had to be explicit in the past for stuff like foobar.erb -> foobar.js.erb or feed.slim -> feed.xml.slim. May as well do this everywhere.

That said, this is apparently missing from the docs - I couldn't find mention of it in the 'upgrading to v4' section. :/

@brandonweiss

This comment has been minimized.

Show comment
Hide comment
@brandonweiss

brandonweiss Jan 9, 2016

Ah, it didn't occur to me to add/override the mime type for markdown! Although, I can't seem to figure out how to do that... this didn't work:

mime_type :md, "text/html"

Any idea what I'm missing?

brandonweiss commented Jan 9, 2016

Ah, it didn't occur to me to add/override the mime type for markdown! Although, I can't seem to figure out how to do that... this didn't work:

mime_type :md, "text/html"

Any idea what I'm missing?

@Arcovion

This comment has been minimized.

Show comment
Hide comment
@Arcovion

Arcovion Jan 9, 2016

Member

I meant that a .md file would be converted to .html automatically before. Which might be a nuisance if you actually (for some reason) wanted to serve a raw version without converting it, while still having .md path.

To actually rewrite the destination path to use .html you can do this: middleman/middleman-asciidoc@e2fb71e
Which involves making an extension and defining a method like this:

def manipulate_resource_list(resources)
  resources.each do |resource|
    next unless resource.source_file.end_with?('.md')
    next unless resource.destination_path.end_with?('.html')
    resource.destination_path << '.html'
  end
end
Member

Arcovion commented Jan 9, 2016

I meant that a .md file would be converted to .html automatically before. Which might be a nuisance if you actually (for some reason) wanted to serve a raw version without converting it, while still having .md path.

To actually rewrite the destination path to use .html you can do this: middleman/middleman-asciidoc@e2fb71e
Which involves making an extension and defining a method like this:

def manipulate_resource_list(resources)
  resources.each do |resource|
    next unless resource.source_file.end_with?('.md')
    next unless resource.destination_path.end_with?('.html')
    resource.destination_path << '.html'
  end
end
@brandonweiss

This comment has been minimized.

Show comment
Hide comment
@brandonweiss

brandonweiss Jan 9, 2016

Oh, I see what you meant. Thanks so much for your help!

(I think you meant to wrap the path appending in an if statement with the line above it?)

brandonweiss commented Jan 9, 2016

Oh, I see what you meant. Thanks so much for your help!

(I think you meant to wrap the path appending in an if statement with the line above it?)

@Arcovion

This comment has been minimized.

Show comment
Hide comment
@Arcovion

Arcovion Jan 9, 2016

Member

Whoops, yep - fixed. If you get it working you might want to throw it in a gist so other people can use it, might help others who are upgrading. =]

Member

Arcovion commented Jan 9, 2016

Whoops, yep - fixed. If you get it working you might want to throw it in a gist so other people can use it, might help others who are upgrading. =]

@Arcovion Arcovion closed this Jan 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment