nx-auto-link 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a1a35dab4ab807fe9655750107a0f3f62332a71e455109a5cc89cd2c7b7a9e29
4
+ data.tar.gz: e8a9cf02e775d545959fd6c5bfba30f40899bb586994ebdda937cbe780311c56
5
+ SHA512:
6
+ metadata.gz: a5d21cecac8f3822b0f03180b0674358ca6f10fceebb966ea5667068c1ba5268931893a11e2fef3088cb2e894861536cc33b116fdb46bbb7558964b5905e3f62
7
+ data.tar.gz: 111d8d87346207e4bbac288f1a8488776f4220adbac6b7a710f631c0540024abe8203a321a87c22bf7940dbba5ad81bd359a1dab49b331b3af40cb6946c4e653
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
data/.npmrc ADDED
@@ -0,0 +1,2 @@
1
+ sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
2
+ package-lock=false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in templates.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # nx-auto-link
2
+ > Auto link for next.
3
+
4
+ ## installation
5
+ ```rb
6
+ # from gem
7
+ gem 'nx-auto-link'
8
+ # from git
9
+ gem 'nx-auto-link', git: 'git@github.com:afeiship/nx-auto-link.git'
10
+ ```
11
+
12
+ ## usage
13
+ ```rb
14
+ Nx::AutoLink::start(html, tags)
15
+
16
+ html = '<article class="jsw-content">
17
+ <p>
18
+ 首先要先下载安装包或者建议:
19
+ </p>
20
+ <p>
21
+ ①win7,win8,win10系统,建议下载python3.7.4版本:
22
+ </p>
23
+ </article>';
24
+
25
+ tags = [
26
+ { name: "下载", url: "http://www.baidu.com/tag/2.html" },
27
+ { name: "建议", url: "http://www.baidu.com/tag/1.html" },
28
+ { name: "python", url: "http://www.baidu.com/tag/5.html" },
29
+ ];
30
+ ```
31
+
32
+ ## build/publish
33
+ ```shell
34
+ # build
35
+ gem build nx-auto-link.gemspec
36
+
37
+ # publish
38
+ gem push nx-auto-link-0.1.0.gem
39
+ ```
40
+
41
+ ## rspec
42
+ - https://rspec.info/
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nx-auto-link"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ require "nokogiri"
2
+
3
+ module Nx
4
+ class AutoLink
5
+ def self.start(html, tags)
6
+ parsed_data = Nokogiri::HTML.parse(html)
7
+ paragraphs = parsed_data.css("p")
8
+
9
+ # tags = [
10
+ # { name: "下载", url: "http://www.baidu.com/tag/2.html" },
11
+ # { name: "建议", url: "http://www.baidu.com/tag/1.html" },
12
+ # { name: "python", url: "http://www.baidu.com/tag/5.html" },
13
+ # ]
14
+
15
+ paragraphs.each do |item|
16
+ processed_html = item.content
17
+ tags.reject { |tag| tag[:processed] }.each do |tag|
18
+ tag_name = tag[:name]
19
+ tag_url = tag[:url]
20
+ if item.content.include?(tag_name)
21
+ tag[:processed] = true
22
+ processed_html = processed_html.sub(
23
+ tag_name,
24
+ "<a role=\"tag\" title=\"#{tag_name}\" href=\"#{tag_url}\">#{tag_name}</a>"
25
+ )
26
+ end
27
+ end
28
+ item.inner_html = processed_html
29
+ end
30
+
31
+ parsed_data.at_css("body").inner_html
32
+ end
33
+ end
34
+ end
data/lib/nx/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Nx
2
+ class AutoLink
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "./nx/version"
2
+ require_relative "./nx/auto-link"
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nx/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nx-auto-link"
8
+ spec.version = Nx::AutoLink::VERSION
9
+ spec.licenses = ["MIT"]
10
+ spec.authors = ["afeiship"]
11
+ spec.email = ["1290657123@qq.com"]
12
+
13
+ spec.summary = %q{Auto link for next.}
14
+ spec.description = %q{Auto link for next.}
15
+ spec.homepage = "https://github.com/aric-gem/nx-auto-link"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "nokogiri"
34
+ spec.add_development_dependency "bump"
35
+ spec.add_development_dependency "bundler", "~> 1.14"
36
+ spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
37
+ end
data/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "nx-auto-link",
3
+ "version": "1.0.2",
4
+ "description": "Auto link for next.",
5
+ "directories": {
6
+ "lib": "lib"
7
+ },
8
+ "scripts": {
9
+ "clean": "rm -rf *.gem",
10
+ "test": "ruby __tests__/index.rb",
11
+ "prebuild": "yarn version --patch",
12
+ "build": "gem build *.gemspec",
13
+ "pubpush": "gem push *.gem",
14
+ "unpublish": "gem yank nx-auto-link -v '0.1.0'"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/afeiship/nx-auto-link.git"
19
+ },
20
+ "author": "afei",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/afeiship/nx-auto-link/issues"
24
+ },
25
+ "homepage": "https://js.work"
26
+ }
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nx-auto-link
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - afeiship
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bump
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 12.3.3
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '12.3'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 12.3.3
75
+ description: Auto link for next.
76
+ email:
77
+ - 1290657123@qq.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".npmrc"
84
+ - Gemfile
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/nx-auto-link.rb
90
+ - lib/nx/auto-link.rb
91
+ - lib/nx/version.rb
92
+ - nx-auto-link.gemspec
93
+ - package.json
94
+ homepage: https://github.com/aric-gem/nx-auto-link
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubygems_version: 3.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Auto link for next.
117
+ test_files: []