Is it possible to link to an article by name?
In jekyll you could do : [Some Link]({% post_url 2010-07-21-name-of-post %})
Is it possible to link to an article by name?
In jekyll you could do : [Some Link]({% post_url 2010-07-21-name-of-post %})
Are you wanting to link from a post using middleman-blog to another post? What’s your middleman set up?
yes, link to another blog post within a blog post. here is my setup: https://github.com/chrishough/myblog
Your blog posts in source/posts
are marked as being in the Slim templating that I haven’t used. I had to go find this post on Stackoverflow about slim & links. What I understand you want is to use a syntax closer to Markdown of
[This link](http://example.net/)
which Middleman can use. You’d have to convert your posts from slim template to markdown
Middleman does support slim.
I am trying to see if there is a method that stores an index of posts that can be accessed to get the post title and url without having to manually add it like: <a href="/2013/05/06/constant-learning/">learning to code</a>
Yep, that’s in the blog documentation. The blog object has an articles property that is an index of all posts.
If you wanted the 3 most recent posts (my markup is in ERB but it’s the gist of the logic)
<% blog.articles[0...3].each do |article| %>
<h2><%= link_to article.title, article.url %></h2>
<% end %>
Yes, I know I could do that from the guide, but I was curious if anyone had a method or extension to parse the full article list quickly to get the title and url of a given post.
To anyone looking for a way to search for a post by the post title to build urls, this is how I solved this:
def post_url(article_title)
blog.articles.find { |article| article.title.downcase == article_title.downcase }.url
rescue
""
end
accessed by:
#{post_url("Who's online at 2am?")}
Hi Chris,
could you explain in details when I need to add provided by you solution?
I’m new with Middleman so it will be very helpfull for me.
Thank you in advance.
Which piece are you referencing? I have since moved away from this older approach.