I'm new to middleman and all the possibilities that i have. I want to make a deadly simple haml script that works as the index page which lists all my page types for faster navigation inside the project.
Here is the code:
---
layout: no_layout
---
- resources = sitemap.resources.sort {|a,b| a.url <=> b.url}
- pages = Array.new
- resources.each do |resource|
- metadata = resource.metadata[:page]
- if resource.mime_type.match(/^text\/html/) && metadata["title"]
- element = Hash.new
- element["url"] = resource.url
- element["title"] = metadata["title"]
- element["desc"] = metadata["desc"]
- if element["url"].start_with?('/')
- element["url"].slice!(0)
- pages.push(element)
%h1 Page elements
- if pages.length > 0
%ul
- pages.each do |page|
%li
%a{:href => page["url"]} #{page["title"]}
- if page["desc"]
%br
= page["desc"]
- else
No pages found.
Sadly, Middleman generates the following error:
NoMethodError at /
undefined method `mime_type' for #<Middleman::Sitemap::Resource:0x000000069df020>
But the Middleman Documentation says, that the Resources object contains the method and i have some example code that also works that way.
Can somebody tell me what i am doing wrong?
Thanks in advance
I think you want Resource#content_type
instead.
$ bundle exec middleman console
> sitemap.resources[2].content_type
=> "text/html; charset=utf-8"