我在铁轨上用红宝石制作的博客很少有文章。文章保存在数据库中。要写内容我使用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>
它尚未准备好进行审核。有什么想法吗?
答案 0 :(得分:3)
内容应该包含在CDATA注释块中。
这就是我在Rails中的表现。
xml.instruct!
xml.rss "version" => "2.0" do
xml.channel do
# Required channel elements...
xml.title "Thinker's Playground"
xml.link root_url(utm_source: "Feed", utm_medium: "RSS", utm_campaign: "RSS")
xml.description TAGLINE
# Optional channel elements...
xml.language "en"
xml.copyright "Copyright 2008—#{Date.today.year}, Thinker's Playground"
xml.managingEditor rss_user(User.first)
xml.webMaster rss_user(User.first)
xml.pubDate @posts.first.updated_at.to_s(:rfc822)
xml.lastBuildDate @posts.first.updated_at.to_s(:rfc822)
xml.category "Personal growth"
xml.generator "Ruby on Rails"
xml.docs "https://validator.w3.org/feed/docs/rss2.html"
xml.ttl 1440
xml.image do
xml.title "Thinker's Playground"
xml.url "https://thinkersplayground.com/paperplane.png"
xml.link root_url(utm_source: "Feed", utm_medium: "RSS", utm_campaign: "RSS")
end
# For each post, create an <item> tag...
@posts.each do |post|
xml.item do
# Required item elements...
xml.title post.title
# Optional item elements...
xml.link post_url(post)
xml.description post.description.to_s.html_safe
xml.author "#{post.blogger_email} (#{post.blogger_name})"
xml.category post.category.name
xml.pubDate post.published_at.to_s(:rfc822)
xml.source("Thinker's Playground", url: feed_url)
xml.tag!("content:encoded") do
xml.cdata!(render(template: "posts/rss/_instant_article_html", formats: "html", locals: { post: post }))
end
end
end
end
end
# _instant_article_html.html.slim
doctype html
html lang="en" prefix="op: http://media.facebook.com/op#"
head
meta property="op:markup_version" content="v1.0"
meta charset="utf-8"
link rel="canonical" href== post_url(post)
body
article
header
= post.title
= markdown post.content
footer
// footer