4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Middleman(middleman-blog)で続きがないときに「続きを読む(READMORE)」を表示しない

Last updated at Posted at 2014-12-25

Middlemanで要約に全文表示したい時って、文の最後にREADMOREを書くのが良いのですが、こうすると今度は「続きを読む」ボタンが常に表示されて鬱陶しいですね。

- blog.articles[0...3].each do |article|
  = article.summary
  - unless article.summary == article.body
    = link_to "続きを読む", article

こんな風に、article.summaryとarticle.bodyを比較してあげると、本当に要約されているのかどうか判断ができるので、必要なときだけ「続きを読む」ボタンを表示できます。

http://4th-cluster.com で実際に使っている様子が見れるので参考まで。

しかしMiddlemanってどれぐらいの人が使ってるんだろうね...

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?