我有一个用 ruby on rails 制作的博客,里面的文章很少。文章保存在数据库中。要编写内容,我使用 Tinymce gem。RSS 在 Feedly 上工作,我想在 FB 即时文章上展示文章。我遵循了 FB 页面上的文档: https ://developers.facebook.com/docs/instant-articles/publishing/setup-rss-feed
并尝试使用这两个链接上的信息使其工作: https ://www.codingfish.com/blog/129-how-to-create-rss-feed-rails-4-3-steps
和
http://apidock.com/rails/Builder/XmlMarkup
有时候FB加载了文章但是样式不见了,找不到任何内容,找不到任何文章,然后我得到“出错了......”的错误,不得不等待一段时间等等。我不知道该怎么办。这是 feed.rss.builder 的最后一个版本,FB 什么也看不到(您还没有创建任何即时文章)。
#encoding: UTF-8
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0" do
xml.channel do
xml.title "Blog"
xml.author "Blog"
xml.description "Web Development"
xml.link "http://myblog.dev.eu/"
xml.language "en"
for article in @blog_articles
xml.item do
if article.title
xml.title article.title
else
xml.title ""
end
xml.link("href" => "http://myblog.dev.eu/blog_posts/"+article.slug.to_s)
xml.guid article.id
xml.pubDate article.created_at.to_s(:rfc822)
xml.author article.author_name
xml.description article.short_description
xml.html do
xml.head do
xml.link("rel" => "stylesheet", "title" => "default", "href" => "#")
xml.title(article.title)
xml.meta("property" => "fb:article_style", "content" => "bam")
xml.link("rel" => "canonical", "href" => "http://myblog.dev.eu/blog_posts/"+article.slug.to_s)
end
xml.body do
xml.header do
xml.image "http://myblog.dev.eu/" + article.picture_url.to_s
end
xml.article(article.content)
end
end
end
end
end
end
请帮我修复此代码!我想提交它以供审核,并且再也不会触摸 feed.rss.builder 中的代码。谢谢!
编辑:
我在代码中改变了一些东西,现在看起来是这样的:
#encoding: UTF-8
xml.instruct! :xml, :version => "1.0"
xml.rss :version => "2.0", "xmlns:content"=>"http://purl.org/rss/1.0/modules/content/" do
xml.channel do
xml.title "MyBlog"
xml.link "http://myblog/"
xml.description "Web Development, Digital Marketing, Education"
xml.language "en-us"
xml.lastBuildDate Time.new.strftime("%Y-%-m-%dT%H:%M").to_s
for article in @blog_articles
xml.item do
xml.title article.title
xml.link "http://myblog.eu/"+article.slug.to_s
xml.guid article.id
xml.pubDate article.created_at.strftime("%Y-%-m-%dT%H:%M").to_s
xml.author article.author_name
xml.description article.short_description
xml.content:encoded do
xml.tag!("!doctype html")
xml.html("lang"=>"en", "prefix"=>"op:http://media.facebook.com/op#") do
xml.head do
xml.meta("charset"=>"utf-8")
xml.link("rel" => "stylesheet", "title" => "default", "href" => "#")
xml.title(article.title)
xml.link("rel" => "canonical", "href" => "http://myblog.eu/blog_posts/"+article.slug.to_s)
xml.meta("property" => "fb:article_style", "content" => "bam")
end
xml.body do
xml.article do
xml.header do
xml.figure("data-mode" => "aspect-fit") do
xml.img("src"=>"http://myblog.eu/blog_posts/#{article.picture.url}")
end
xml.h1 article.title
xml.h2 article.short_description
xml.h3("Introduction" , "class"=>"op-kicker")
xml.address "myadr"
xml.time(article.created_at.strftime("%B %dth %Y, %l:%M %p").to_s, "class" => "op-published", "dateTime" => article.created_at.strftime("%Y-%-m-%dT%H:%M").to_s)
xml.time(article.created_at.strftime("%B %dth %Y, %l:%M %p").to_s, "class" => "op-modified", "dateTime" => article.updated_at.strftime("%Y-%-m-%dT%H:%M").to_s)
end
xml.p article.content
xml.figure("data-feedback"=>"fb:likes, fb:comments") do
xml.img("src"=>"http://myblog.eu/blog_posts/#{article.picture.url}")
xml.figcaption do
xml.h1 "descript"
xml.cite "text"
end
end
xml.footer do
xml.small "Lab"
end
end
end
end
end
end
end
end
end
现在 FB 可以识别文章,但我仍然有错误:“缺少徽标”。我在FB样式中添加了徽标,可以在线找到:
xml.meta("property" => "fb:article_style", "content" => "bam")
当我在 FB 编辑器中打开一篇文章时,整个内容都会添加到标题标签之前的文章标签中。它看起来像这样:
<html>
<body><article><p>!doctype html/>
...Content...
</p>
<header><time class="op-modified" datetime="2016-01-19T10:38:00-08:00">2016-01-19T10:38:00-08:00</time><time datetime="2016-01-19T10:38:00-08:00" class="op-published"></time><h1>Title</h1></header><footer></footer></article></body>
<head><link rel="canonical" href="http:///myblog.eu/article.title"></head>
</html>
而且它还没有准备好进行审查。有任何想法吗?