如何在轨道上使用带有红宝石的FB即时文章?

问题描述:

我有一个用红宝石制作的博客,它的文章很少。文章保存在数据库中。要写内容我使用Tinymce宝石。 rss正在Feedly上工作,我想展示关于FB即时文章的文章。我也跟着上FB页的文档: https://developers.facebook.com/docs/instant-articles/publishing/setup-rss-feed如何在轨道上使用带有红宝石的FB即时文章?

,并试图使其与在此两个链接中找到的信息工作: 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/&gt; 

...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> 

而且它还没有准备好进行审查。有任何想法吗?

内容应包装在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