From a76a1d1cf2890dc170db5d8aedd7f4181a02153c Mon Sep 17 00:00:00 2001 From: danyang685 <496298685@qq.com> Date: Sat, 27 Jun 2020 21:22:35 +0800 Subject: [PATCH] Remove custom support of WeChat mp articles Current parser doesn't support the latest WeChat mp article pages, but it supports The Open Graph protocol now --- lib/onebox/engine.rb | 1 - lib/onebox/engine/wechat_mp_onebox.rb | 62 -- .../engine/whitelisted_generic_onebox.rb | 1 + spec/fixtures/wechat-mp.response | 631 ------------------ .../onebox/engine/wechat_mp_onebox_spec.rb | 28 - templates/wechatmp.mustache | 4 - 6 files changed, 1 insertion(+), 726 deletions(-) delete mode 100644 lib/onebox/engine/wechat_mp_onebox.rb delete mode 100644 spec/fixtures/wechat-mp.response delete mode 100644 spec/lib/onebox/engine/wechat_mp_onebox_spec.rb delete mode 100644 templates/wechatmp.mustache diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb index 5cea541e..9d42cf8b 100644 --- a/lib/onebox/engine.rb +++ b/lib/onebox/engine.rb @@ -168,7 +168,6 @@ def always_https? require_relative "engine/twitch_stream_onebox" require_relative "engine/twitch_video_onebox" require_relative "engine/trello_onebox" -require_relative "engine/wechat_mp_onebox" require_relative "engine/cloudapp_onebox" require_relative "engine/wistia_onebox" require_relative "engine/simplecast_onebox" diff --git a/lib/onebox/engine/wechat_mp_onebox.rb b/lib/onebox/engine/wechat_mp_onebox.rb deleted file mode 100644 index 0ac9ec59..00000000 --- a/lib/onebox/engine/wechat_mp_onebox.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -module Onebox - module Engine - class WechatMpOnebox - include Engine - include LayoutSupport - include HTML - - always_https - matches_regexp(/^https?:\/\/mp\.weixin\.qq\.com\/s.*$/) - - def tld - @tld || @@matcher.match(@url)["tld"] - end - - def http_params - { - 'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3', - 'Accept-Encoding' => 'plain' - } - end - - private - - def extract_script_value(var_name) - if (script_elem = raw.css("script").select { |script| script.inner_text.include? "var #{var_name} = " }) && script_elem.any? - e = Nokogiri::HTML(script_elem[0].inner_text.match(/var\s+#{Regexp.quote(var_name)}\s+=\s+"(.*?)";/)[1]) - CGI::unescapeHTML(e.text.scan(/(?:\\x([a-f0-9]{2}))|(.)/i).map { |x| x[0] ? [x[0].to_i(16)].pack('U') : x[1] }.join) - end - end - - # TODO need to handle hotlink protection from wechat - def image - if banner_image = extract_script_value("msg_cdn_url") - return banner_image - end - - if (main_image = raw.css("img").select { |img| not img['class'] }) && main_image.any? - attributes = main_image.first.attributes - - return attributes["data-src"].to_s if attributes["data-src"] - end - end - - def data - title = CGI.unescapeHTML(raw.css("title").inner_text) - by_info = CGI.unescapeHTML(raw.css("span.rich_media_meta_text.rich_media_meta_nickname").inner_text) - - result = { - link: extract_script_value("msg_link") || link, - title: title, - image: image, - description: extract_script_value("msg_desc"), - by_info: by_info - } - - result - end - end - end -end diff --git a/lib/onebox/engine/whitelisted_generic_onebox.rb b/lib/onebox/engine/whitelisted_generic_onebox.rb index 56064b87..10e1ffae 100644 --- a/lib/onebox/engine/whitelisted_generic_onebox.rb +++ b/lib/onebox/engine/whitelisted_generic_onebox.rb @@ -86,6 +86,7 @@ def self.default_whitelist meetup.com mixcloud.com mlb.com + mp.weixin.qq.com myshopify.com myspace.com nba.com diff --git a/spec/fixtures/wechat-mp.response b/spec/fixtures/wechat-mp.response deleted file mode 100644 index 7116606d..00000000 --- a/spec/fixtures/wechat-mp.response +++ /dev/null @@ -1,631 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - 不是月光宝盒,但也能回到过去 - - - - - - - - - - -
- -
- -
- -
- -
- -

- 不是月光宝盒,但也能回到过去

-
- 2017-06-22 - - 微信派 - 微信派 - - -
- - - - - - - -
- - - - - - -

不用念咒,直接回到过去——


今天,微信公众平台后台更新:所有帐号都可以在图文编辑查看图文历史版本


具体操作如下:


1.在图文素材编辑界面,选择右上角的“图文历史版本”。



2.进入图文历史版本列表,编辑时间、编辑者、操作内容一览无余。



3.运营者可以选择需要查看的历史编辑版本,在历史列表上轻松切换。



需要提醒的是,目前,用户只能看到新版本上线后操作过程中的历史编辑记录,不包含上线前的编辑记录。



图文“剁手党”们是不是高兴坏了?派爷再给你们播送三个福音


他们是?

1、图文素材编辑提供本地草稿:


还在为误操作或浏览器崩溃离开丢失本地草稿而猛拍大腿?


现在,没有保存本地草稿到服务器、主动关闭编辑页面或浏览器崩溃导致编辑页面关闭,可以再次进入该素材:



重新进入未保存的图文,会自动出现“有未保存的草稿”的提示,可通过此界面查看草稿。


2素材版本冲突时增加详细提示


你是否遇到过这种情况:多个浏览器操作中,旧素材一不小心就覆盖了新素材的草稿……


现在,当进入一个旧版本(与服务器最新的版本对比)素材草稿时,会自动出现弹框提示用户详细的操作信息



这里,派爷推荐你选择编辑新内容。如果选择查看当前内容,你就会进入一个只读的草稿页面,此时的草稿是只能复制不能编辑的。


3、多个本地草稿定时自动同步:


在图文素材编辑里,每隔1分钟草稿会自动保存N个窗口同时编辑手忙脚乱、本地素材太多经常混淆,从此挥手告别这些问题,群发内容不再怕出错。

从此,图文编辑有“迹”可循。多人同时操作,多个电脑同时浏览时再也不怕素材内容丢失了~


互动话题 


此次能力的开放,运营者们,是不是感到多年的“剁手症”终于有救了?


说说在编辑图文的时候,你有过哪些恨不得“剁手”的黑历史?



-
- - - - - - - - - -
- -
- - - - - - -
- - -
- - - - -
- - -
- - - - -
- - - -
-
- - - - - - - - - - - - - - - - - - - - diff --git a/spec/lib/onebox/engine/wechat_mp_onebox_spec.rb b/spec/lib/onebox/engine/wechat_mp_onebox_spec.rb deleted file mode 100644 index 4eef2007..00000000 --- a/spec/lib/onebox/engine/wechat_mp_onebox_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" - -describe Onebox::Engine::WechatMpOnebox do - - let(:link) { "https://mp.weixin.qq.com/s?__biz=MjM5NjM4MDAxMg==&mid=2655075181&idx=1&sn=7c58f17de2c687f4763f17359ecc6e72&chksm=bd5fb76e8a283e7856cae30a74e905a18d9511e81c047b6e12390889de15976fb2c297b04106#rd" } - let(:html) { described_class.new(link).to_html } - - describe "#to_html" do - before do - fake("https://mp.weixin.qq.com/s?__biz=MjM5NjM4MDAxMg==&mid=2655075181&idx=1&sn=7c58f17de2c687f4763f17359ecc6e72&chksm=bd5fb76e8a283e7856cae30a74e905a18d9511e81c047b6e12390889de15976fb2c297b04106", response("wechat-mp")) - end - - it "has the article's title" do - expect(html).to include("不是月光宝盒,但也能回到过去") - end - - it "has the article's description" do - expect(html).to include("你知道吗?从今天起,公众号后台编辑文章时可以……") - end - - it "has the article's author" do - expect(html).to include("微信派") - end - end - -end diff --git a/templates/wechatmp.mustache b/templates/wechatmp.mustache deleted file mode 100644 index a8db1e68..00000000 --- a/templates/wechatmp.mustache +++ /dev/null @@ -1,4 +0,0 @@ -

{{title}}

-{{#by_info}}{{by_info}}{{/by_info}} -

{{description}}

-