jekyll-hashtags 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '095c38c828b59386d64ccbd146cd436d648dbee0'
4
- data.tar.gz: d401e722673026f6de0ab63659fafbc752783a06
3
+ metadata.gz: b1545e79b465d7005f1e46b7165029d2ff54092d
4
+ data.tar.gz: 41957d75b14b4986059ecf2c0d5cebeeac20437e
5
5
  SHA512:
6
- metadata.gz: 88f0763e84d5d8a27641efe4617b4852dae26479602dbbf45a8c2a5e4ce035572a8c62c74fc91b10a59e202b8082bcd048e62eeb63382c7cbedbd6a0aeddbce2
7
- data.tar.gz: c49e73b37e070e95f036ac72f4a4e7e05fcb844d8f3d391bd9ee929dad4867044a82a91206ab4595a7223bfba50df5dd90a5436cb3e6c40b0e72b37a29039821
6
+ metadata.gz: 0d019105cdf73f1d932f93540f3371cd92706b605df374059809bc77491e04bb95df3e8a45b4d848ebd8ac39da816edfa70484191523fe8c1927114abca13e51
7
+ data.tar.gz: 339a94fee34d0b4cf1ec35a564b32a7ec1f9325db1fc46a8f9e147045c6ab89ecb2cf1c731c5ea7d341fe3c6293602b0588f7cc088ba1cb645948f670061e3b9
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ bin
7
7
  Gemfile.lock
8
8
  pkg/*.gem
9
9
  .rspec_status
10
+ spec/blog/_site/
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Jekyll::Hashtags
2
2
 
3
- #hashtags support for you jekyll site.
3
+ #hashtags support for you jekyll site.
4
4
 
5
5
  ## Installation
6
6
 
@@ -11,48 +11,53 @@ gem 'jekyll-hashtags'
11
11
  ```
12
12
 
13
13
  And then execute:
14
-
14
+ ```
15
15
  $ bundle
16
-
16
+ ```
17
17
  Or install it yourself as:
18
-
18
+ ```
19
19
  $ gem install jekyll-hashtags
20
-
20
+ ```
21
21
  ## Usage
22
22
 
23
23
 
24
24
  Add the following to your site's Gemfile
25
-
25
+ ```
26
26
  gem 'jekyll-hashtags'
27
+ ```
28
+
27
29
  And add the following to your site's _config.yml
28
30
 
31
+ ```
29
32
  plugins:
30
33
  - jekyll-hashtags
31
- Note: if jekyll --version is less than 3.5 use:
34
+ ```
32
35
 
36
+ Note: if jekyll --version is less than 3.5 use:
37
+ ```
33
38
  gems:
34
39
  - jekyll-hashtags
35
-
40
+ ```
36
41
  In any page or post, use @hashtags as you would normally, e.g.
37
42
 
38
- Hey #TradeWar, what do you think of this?
43
+ > Hey #TradeWar, what do you think of this?
39
44
 
40
45
  ## Configuration
41
46
  Have your own social network? No problem. We allow you to configure the base URL of all the hashtags.
42
47
 
43
48
  To change it, add the following to your Jekyll configuration:
44
-
49
+ ```
45
50
  jekyll-hashtags:
46
51
  base_url: https://hengwei.me
47
-
52
+ ```
48
53
  An example of Twitter hashtags using jekyll-hashtags:
49
-
54
+ ```
50
55
  plugins:
51
56
  - jekyll-hashtags
52
57
 
53
58
  jekyll-hashtags:
54
59
  base_url: https://hengwei.me
55
-
60
+ ```
56
61
  ## Development
57
62
 
58
63
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -32,8 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency "html-pipeline-hashtag", "~> 0.1.1"
35
+ spec.required_ruby_version = ">= 2.3.0"
36
+
36
37
  spec.add_dependency "jekyll", "~> 3.0"
38
+ spec.add_dependency "html-pipeline-hashtag", "~> 0.1.1"
37
39
 
38
40
  spec.add_development_dependency "bundler", "~> 1.16"
39
41
  spec.add_development_dependency "rake", "~> 10.0"
@@ -21,9 +21,14 @@ module Jekyll
21
21
  if content.include? BODY_START_TAG
22
22
  head, opener, tail = content.partition(OPENING_BODY_TAG_REGEX)
23
23
  body, *rest = tail.partition(BODY_END_TAG)
24
- return unless body =~ get_hashtag_pattern(doc.site.config)
25
- processed_markup = filter_with_hashtag(doc.site.config, base_url).call(body)[:output].to_s
24
+ context = {
25
+ "hashtag_pattern" => get_hashtag_pattern(doc.site.config),
26
+ "tag_url" => get_tag_url(doc.site.config),
27
+ }
28
+ processed_markup = filter_with_hashtag(base_url, context).call(body)[:output].to_html
26
29
  doc.output = String.new(head) << opener << processed_markup << rest.join
30
+ else
31
+ doc.output = filter_with_hashtag(base_url, context).call(content)[:output].to_html
27
32
  end
28
33
  end
29
34
 
@@ -34,11 +39,9 @@ module Jekyll
34
39
  #
35
40
  # Returns an HTML::Pipeline instance for the given base URL.
36
41
  #
37
- def filter_with_hashtag(config = {}, base_url = DEFAULT_HASHTAG_BASE_URL)
42
+ def filter_with_hashtag(base_url = DEFAULT_HASHTAG_BASE_URL, context = {})
38
43
  filters[base_url] ||= HTML::Pipeline.new([HTML::Pipeline::HashtagFilter],
39
- :hashtag_pattern => get_hashtag_pattern(config),
40
- :tag_url => get_tag_url(config)
41
- )
44
+ context)
42
45
  end
43
46
 
44
47
  # Public: Filters hash where the key is the mention base URL.
@@ -61,11 +64,11 @@ module Jekyll
61
64
  hashtag_config = config["jekyll-hashtags"]
62
65
  case hashtag_config
63
66
  when nil, NilClass
64
- Regexp.new(HTML::Pipeline::HashtagFilter::HashtagPattern)
67
+ HTML::Pipeline::HashtagFilter::HashtagPattern
65
68
  when String
66
- Regexp.new(hashtag_config.to_s)
69
+ hashtag_config.to_s
67
70
  when Hash
68
- Regexp.new(hashtag_config.fetch("tag_pattern", DEFAULT_HASHTAG_PATTERN))
71
+ hashtag_config.fetch("tag_pattern", DEFAULT_HASHTAG_PATTERN)
69
72
  else
70
73
  raise Class.new(Jekyll::Errors::FatalException),
71
74
  "Your jekyll-hashtag config has to either be a" \
@@ -124,10 +127,20 @@ module Jekyll
124
127
  " string or a hash. It's a #{hashtag_config.class} right now."
125
128
  end
126
129
  end
130
+
131
+ # Public: Defines the conditions for a document to be tagable.
132
+ #
133
+ # doc - the Jekyll::Document or Jekyll::Page
134
+ #
135
+ # Returns true if the doc is written & is HTML.
136
+ def tagable?(doc)
137
+ (doc.is_a?(Jekyll::Page) || doc.write?) &&
138
+ doc.output_ext == ".html" || (doc.permalink&.end_with?("/"))
139
+ end
127
140
  end
128
141
  end
129
142
  end
130
143
 
131
144
  Jekyll::Hooks.register %i[pages documents], :post_render do |doc|
132
- Jekyll::Hashtags.hashtag_it(doc)
145
+ Jekyll::Hashtags.hashtag_it(doc) if Jekyll::Hashtags.tagable?(doc)
133
146
  end
@@ -1,3 +1,3 @@
1
1
  module JekyllHashtags
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hashtags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wei Heng
@@ -11,33 +11,33 @@ cert_chain: []
11
11
  date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: html-pipeline-hashtag
14
+ name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.1
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: jekyll
28
+ name: html-pipeline-hashtag
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: 0.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: 0.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: '0'
112
+ version: 2.3.0
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="