jekyll-refergen 0.1.3 → 0.2.0
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 +4 -4
- data/README.md +52 -11
- data/lib/jekyll/refergen/reference_generator.rb +85 -21
- data/lib/jekyll/refergen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e590b644a9abe0f2de11955ae50d0da67ac54dbcd1cdd3478ef7196dc6bbbead
|
|
4
|
+
data.tar.gz: 8927925a82183080a7e5c90d82aa0b3c21519fdc40acfbd78ce1f28592aa1faf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70c27dc044e30365a61638e579089ed9be3ca66c9f2f9c84f0c7e348661a90f0c295c196fb1de22c1952a8b00c8618fd42ed53acdf34dbbead525c6e7e7c02ed
|
|
7
|
+
data.tar.gz: a2e822df48d961b41cc44643a5fb7c1b7d628a749215d6239ed72e54482de034e126d2ccf33366ad057fd20ad0b5c1926d08b80e316ffe044108ad2f73caf9e0
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jekyll-refergen
|
|
2
2
|
Don’t forget to include a reference at the end of your posts.
|
|
3
3
|
|
|
4
4
|
---
|
|
@@ -8,35 +8,76 @@ Don’t forget to include a reference at the end of your posts.
|
|
|
8
8
|
1. **Gem Installation**
|
|
9
9
|
- Add to your Gemfile:
|
|
10
10
|
```ruby
|
|
11
|
-
gem '
|
|
11
|
+
gem 'jekyll-refergen', git: 'https://github.com/yourname/jekyll-refergen.git'
|
|
12
12
|
```
|
|
13
13
|
- Or after publishing to rubygems.org:
|
|
14
14
|
```ruby
|
|
15
|
-
gem '
|
|
15
|
+
gem 'jekyll-refergen'
|
|
16
16
|
```
|
|
17
17
|
- Run `bundle install`
|
|
18
18
|
|
|
19
19
|
2. **_config.yml Configuration**
|
|
20
20
|
```yaml
|
|
21
|
-
|
|
21
|
+
refergen-plugin:
|
|
22
22
|
collections: ["posts", "wiki"] # Specify which collections to process
|
|
23
23
|
```
|
|
24
|
-
- The plugin
|
|
24
|
+
- The plugin processes all documents in the listed collections.
|
|
25
25
|
|
|
26
|
-
3. **Usage
|
|
27
|
-
-
|
|
26
|
+
3. **Usage Examples**
|
|
27
|
+
- Deduplicate by URL (same URL → same reference number):
|
|
28
28
|
```markdown
|
|
29
29
|
[Example1](https://www.example.com), [Example2](https://www.example2.com), [Again Example1](https://www.example.com)
|
|
30
30
|
```
|
|
31
|
-
|
|
31
|
+
Renders as:
|
|
32
32
|
```markdown
|
|
33
|
-
Example1<sup><a href="#ref-1" id="ref-link-1">[1]</a></sup>, Example2<sup><a href="#ref-2" id="ref-link-2">[2]</a></sup>, Again Example1<sup><a href="#ref-1" id="ref-link-
|
|
33
|
+
Example1<sup><a href="#ref-1" id="ref-link-1">[1]</a></sup>, Example2<sup><a href="#ref-2" id="ref-link-2">[2]</a></sup>, Again Example1<sup><a href="#ref-1" id="ref-link-3">[1]</a></sup>
|
|
34
34
|
|
|
35
35
|
---
|
|
36
36
|
## Reference
|
|
37
|
-
1. <a id="ref-1"></a>[Example1](https://www.example.com)<br/>
|
|
37
|
+
1. <a id="ref-1"></a>[Example1](https://www.example.com) ^ <a href="#ref-link-1">a</a> <a href="#ref-link-3">b</a><br/>
|
|
38
38
|
2. <a id="ref-2"></a>[Example2](https://www.example2.com)<br/>
|
|
39
39
|
```
|
|
40
|
+
When the same URL is referenced multiple times, the Reference section shows `^a b c` format where each letter links to the corresponding reference location in the text.
|
|
41
|
+
|
|
42
|
+
- Custom reference label: use the Markdown link title (`"..."` or unquoted) as the reference display name.
|
|
43
|
+
```markdown
|
|
44
|
+
[Visible text](https://www.example.com "Custom label")
|
|
45
|
+
[Another link](https://www.example.com Custom label)
|
|
46
|
+
```
|
|
47
|
+
Renders as:
|
|
48
|
+
```markdown
|
|
49
|
+
Visible text<sup><a href="#ref-1" id="ref-link-1">[1]</a></sup>
|
|
50
|
+
Another link<sup><a href="#ref-1" id="ref-link-2">[1]</a></sup>
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
## Reference
|
|
54
|
+
1. <a id="ref-1"></a>[Custom label](https://www.example.com) ^ <a href="#ref-link-1">a</a> <a href="#ref-link-2">b</a><br/>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. **Local Test (example)**
|
|
58
|
+
- Install dependencies:
|
|
59
|
+
```bash
|
|
60
|
+
bundle install
|
|
61
|
+
```
|
|
62
|
+
- Prepare a test Jekyll site (create one if needed):
|
|
63
|
+
```bash
|
|
64
|
+
bundle exec jekyll new demo-site --skip-bundle
|
|
65
|
+
cd demo-site
|
|
66
|
+
bundle add ../jekyll-refergen # reference local plugin
|
|
67
|
+
```
|
|
68
|
+
- Add plugin to `_config.yml`:
|
|
69
|
+
```yaml
|
|
70
|
+
plugins:
|
|
71
|
+
- jekyll-refergen
|
|
72
|
+
refergen-plugin:
|
|
73
|
+
collections: ["posts"]
|
|
74
|
+
```
|
|
75
|
+
- Add the usage examples to a post, then build/serve:
|
|
76
|
+
```bash
|
|
77
|
+
bundle exec jekyll build
|
|
78
|
+
bundle exec jekyll serve
|
|
79
|
+
```
|
|
80
|
+
- In the rendered HTML, verify same URLs share the same number and the title is used as the reference label when provided.
|
|
40
81
|
|
|
41
82
|
---
|
|
42
83
|
|
|
@@ -73,7 +114,7 @@ jobs:
|
|
|
73
114
|
```
|
|
74
115
|
|
|
75
116
|
- This workflow builds your Jekyll site and deploys the `_site` folder to GitHub Pages on every push to the master branch.
|
|
76
|
-
- If your Gemfile includes `
|
|
117
|
+
- If your Gemfile includes `jekyll-refergen`, the plugin will work in the GitHub Actions environment.
|
|
77
118
|
|
|
78
119
|
---
|
|
79
120
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
2
|
module Jekyll
|
|
4
3
|
module Refergen
|
|
5
4
|
class ReferenceGenerator < Jekyll::Generator
|
|
@@ -21,31 +20,96 @@ module Jekyll
|
|
|
21
20
|
private
|
|
22
21
|
|
|
23
22
|
def process_references(content)
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
link_data = extract_link_data(content)
|
|
24
|
+
return content if link_data.empty?
|
|
25
|
+
|
|
26
|
+
replaced_content = replace_links(content, link_data)
|
|
27
|
+
reference_section = generate_reference_section(link_data)
|
|
28
|
+
replaced_content + reference_section
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def extract_link_data(content)
|
|
26
32
|
url_to_number = {}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
url_to_label = {}
|
|
34
|
+
url_to_link_positions = {}
|
|
35
|
+
link_index = 0
|
|
36
|
+
|
|
37
|
+
content.scan(/\[([^\]]+)\]\(([^\)]+)\)/) do |text, url_part|
|
|
38
|
+
link_index += 1
|
|
39
|
+
url, ref_name = parse_link(url_part)
|
|
40
|
+
|
|
41
|
+
# Assign reference number
|
|
42
|
+
num = url_to_number[url] ||= url_to_number.length + 1
|
|
43
|
+
|
|
44
|
+
# Store label (use first occurrence)
|
|
45
|
+
label = ref_name&.strip
|
|
46
|
+
label = text if label.nil? || label.empty?
|
|
47
|
+
url_to_label[url] ||= label
|
|
48
|
+
|
|
49
|
+
# Track link positions for this URL
|
|
50
|
+
url_to_link_positions[url] ||= []
|
|
51
|
+
url_to_link_positions[url] << link_index
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
{
|
|
55
|
+
url_to_number: url_to_number,
|
|
56
|
+
url_to_label: url_to_label,
|
|
57
|
+
url_to_link_positions: url_to_link_positions
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def parse_link(url_part)
|
|
62
|
+
# Try to match quoted title: url "title"
|
|
63
|
+
if url_part.match(/^([^\s\)]+)\s+"([^"]+)"$/)
|
|
64
|
+
[Regexp.last_match(1), Regexp.last_match(2)]
|
|
65
|
+
# Try to match unquoted title: url title
|
|
66
|
+
elsif url_part.match(/^([^\s\)]+)\s+(.+)$/)
|
|
67
|
+
[Regexp.last_match(1), Regexp.last_match(2)]
|
|
68
|
+
# No title: just url
|
|
69
|
+
else
|
|
70
|
+
[url_part, nil]
|
|
31
71
|
end
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def replace_links(content, link_data)
|
|
75
|
+
url_to_number = link_data[:url_to_number]
|
|
76
|
+
url_to_label = link_data[:url_to_label]
|
|
77
|
+
link_counter = 0
|
|
78
|
+
|
|
79
|
+
content.gsub(/\[([^\]]+)\]\(([^\)]+)\)/) do
|
|
80
|
+
link_counter += 1
|
|
81
|
+
text = Regexp.last_match(1)
|
|
82
|
+
url_part = Regexp.last_match(2)
|
|
83
|
+
url, = parse_link(url_part)
|
|
84
|
+
|
|
36
85
|
num = url_to_number[url]
|
|
37
|
-
"#{
|
|
86
|
+
"#{text}<sup><a href=\"#ref-#{num}\" id=\"ref-link-#{link_counter}\">[#{num}]</a></sup>"
|
|
38
87
|
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def generate_reference_section(link_data)
|
|
91
|
+
url_to_number = link_data[:url_to_number]
|
|
92
|
+
url_to_label = link_data[:url_to_label]
|
|
93
|
+
url_to_link_positions = link_data[:url_to_link_positions]
|
|
94
|
+
|
|
95
|
+
reference_section = "\n\n---\n## Reference\n"
|
|
96
|
+
|
|
97
|
+
url_to_number.sort_by { |_, num| num }.each do |url, num|
|
|
98
|
+
label = url_to_label[url]
|
|
99
|
+
positions = url_to_link_positions[url]
|
|
100
|
+
|
|
101
|
+
# Generate position links (^a b c format)
|
|
102
|
+
position_links = positions.map.with_index do |pos, idx|
|
|
103
|
+
letter = ('a'.ord + idx).chr
|
|
104
|
+
"<a href=\"#ref-link-#{pos}\">#{letter}</a>"
|
|
105
|
+
end.join(' ')
|
|
106
|
+
|
|
107
|
+
position_prefix = positions.length > 1 ? " ^ #{position_links}" : ""
|
|
108
|
+
|
|
109
|
+
reference_section += "#{num}. <a id=\"ref-#{num}\"></a>[#{label}](#{url})#{position_prefix}<br/>\n"
|
|
47
110
|
end
|
|
48
|
-
|
|
111
|
+
|
|
112
|
+
reference_section
|
|
49
113
|
end
|
|
50
114
|
end
|
|
51
115
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jekyll-refergen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Minseong Lee
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-12-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jekyll
|