这很好用:
<% blog.articles.each_with_index do |article, i| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<%= article.body %>
<% end %>
这不是:
<% blog.articles.each_with_index do |article, i| %>
<h2><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></h2>
<%= article.summary %>
<% end %>
关于该摘要的某些内容会引发错误:
TypeError: type mismatch: String given
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `=~'
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:110:in `default_summary_generator'
/Users/bob/.rvm/gems/ruby-2.3.0/gems/middleman-blog-4.0.0/lib/middleman-blog/blog_article.rb:98:in `summary'
/Users/bob/Dropbox/Web Development/Projects/Middleman/BRP/source/index.html.erb:11:in `block (2 levels) in singleton class'
依旧......
这是我的config.rb中关于博客gem的部分:
activate :blog do |blog|
# This will add a prefix to all links, template references and source paths
# blog.prefix = "blog"
# blog.permalink = "{year}/{month}/{day}/{title}.html"
# Matcher for blog source files
blog.sources = "posts/{year}-{month}-{day}-{title}.html"
# blog.taglink = "tags/{tag}.html"
# blog.layout = "layout"
blog.summary_separator = "==="
blog.summary_length = 250
# blog.year_link = "{year}.html"
# blog.month_link = "{year}/{month}.html"
# blog.day_link = "{year}/{month}/{day}.html"
# blog.default_extension = ".markdown"
blog.tag_template = "tag.html"
blog.calendar_template = "calendar.html"
# Enable pagination
blog.paginate = true
blog.per_page = 10
blog.page_link = "page/{num}"
end
# activate :directory_indexes
我的宝石文件:
``` 来源&#39; http://rubygems.org&#39;
gem&#34; middleman&#34;,&#34;〜&gt; 4.1.0&#34; 宝石&#34;中间人博客&#34; gem&#34; middleman-livereload&#34; gem&#39; middleman-autoprefixer&#39;
gem&#34; builder&#34;,&#34;〜&gt; 3.0&#34; ```
我哪里出错?
答案 0 :(得分:0)
只是预感,但blog.summary_separator = "==="
看起来像麻烦制造者。
尝试另一个不能被错误地解释为比较运算符的字符串,看看它是否有效。
也许试试blog.summary_separator = /(READMORE)/
不要忘记在帖子文件中进行更改。 (忘记那种东西是让我经常追逐我的尾巴的原因。)
答案 1 :(得分:0)
您实际上不需要取消注释config.rb中的两行:
blog.summary_separator = "==="
blog.summary_length = 250
尝试在下面添加此行
<%= article.summary %>
<%= link_to 'Read more…', article %>