jekyll-artisync 0.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-artisync.rb +9 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdd1c95dc86f0e265d5e748dd9559cff17968ad55570e7d610ec2441a7339382
4
- data.tar.gz: 184d76a6fe6174d9c0888dbe8126b2bf16a1e6306f28dcd836b347dd2698527a
3
+ metadata.gz: 31d37fc6ffdd79cb4d259d1db001b0abea1f2f4d8be3d17b035e2db5e1a7cc80
4
+ data.tar.gz: 1b5b26500b61c8e271d0c2a2605b28662c041572a1428469e9d30209c718a0c5
5
5
  SHA512:
6
- metadata.gz: 6eead02cfc58bfb5bb24d3860e222a6e04ba3883a9a40a8a9c8e673efc94b29b22f851631e103dbc93ca1ff0a9e43ccefeca1eec1bbf0839c395baa0d2c86a94
7
- data.tar.gz: 7c34719be25ff7b9ab5501c2a2ef5512d71678a4c3ea918ff7b6d53ae8f874adc7683790d8468e1afaf177e167584ae7fe111d8d35f9ea1f432665aa1244cb97
6
+ metadata.gz: 5d643be4d2d2c4831251e06e6f092ff419148b7c21fbdc1d274642d7dad5cf7de741b635af6e556221e47090b61dd0a28cc4614b9adae8a829062c354ce71468
7
+ data.tar.gz: 7334aeea98d30013f3ba030caaeafbb3fbd542d74998f00efb152d1873bbdd83542b9213b0cc041836b2e9becb62622d01e894da0e5fc003b44dbc2a576cb79b
@@ -6,8 +6,8 @@ require "jekyll"
6
6
  # user agent is necessary otherwise certain sites such as Zhihu throws 400
7
7
  USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36'
8
8
 
9
- SITE_TO_ARTICLE_XPATH = {
10
- 'zhihu' => '//div[contains(@class, "Post-RichText") and contains(@class, "ztext")]',
9
+ HOST_TO_ARTICLE_XPATH = {
10
+ 'zhuanlan.zhihu.com' => '//div[contains(@class, "Post-RichText") and contains(@class, "ztext")]',
11
11
  }
12
12
 
13
13
  class ArticleSyncEmbed < Liquid::Tag
@@ -17,8 +17,7 @@ class ArticleSyncEmbed < Liquid::Tag
17
17
  @content = content
18
18
  end
19
19
 
20
- def _fetch_html(url)
21
- uri = URI(url)
20
+ def _fetch_html(uri)
22
21
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
23
22
  # :use_ssl => true for the uri is https
24
23
  http.request(Net::HTTP::Get.new(uri, {'User-Agent' => USER_AGENT}))
@@ -42,9 +41,12 @@ class ArticleSyncEmbed < Liquid::Tag
42
41
  end
43
42
 
44
43
  def render(context)
45
- url, site = @content.strip.split
46
- page_html = self._fetch_html(url)
47
- article = Nokogiri::HTML(page_html).xpath(SITE_TO_ARTICLE_XPATH[site])
44
+ url = @content.strip
45
+ uri = URI(url)
46
+ page_host = uri.hostname
47
+ puts page_host
48
+ page_html = self._fetch_html(uri)
49
+ article = Nokogiri::HTML(page_html).xpath(HOST_TO_ARTICLE_XPATH[page_host])
48
50
  content = []
49
51
  article.children.each do |node|
50
52
  content.append self._handle_node(node)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-artisync
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junhan