jekyll-auto-relative 0.1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/jekyll-auto-relative.rb +34 -0
  3. metadata +60 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e275665d2b167ad49bbcbb854103ee06e909f44ab3d730af84f0c89af88dc43
4
+ data.tar.gz: eb266885089dffc795d077885419567de6a61baa27d96b64e14b9f212bfbf92d
5
+ SHA512:
6
+ metadata.gz: 0f437606c143b41c8d02defa36d79ec4b24f59fc8a6954ed5ddb27a68cde62428bdbc0376a6a20bd6be0e633070b16dc3cdecf2e45d0902419b16cfec7bf4d7b
7
+ data.tar.gz: 8afb79071b707a2a5b585f1b63b20d35167698dc56f8ccf2ee2242a468ed1bc797a9bc2c6f43654f15fb545c19edb20d984bb05d35cdb99f1669c65a546f9f49
@@ -0,0 +1,34 @@
1
+ # JEKYLL AUTO RELATIVE
2
+ # This is a plugin for converting urls in markdown files to relative paths required by Jekyll.
3
+ # Author: Qucheng Miao
4
+
5
+ require "jekyll"
6
+
7
+ module Jekyll
8
+ class AutoRelative
9
+ class << self
10
+ INLINE_LINK_REGEX = /\[((?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?)\]\(\s*(?:<\s*(\/(?:\\.|[^\n<>\\])+)>|(\/[^\s\x00-\x1f]*))(?:\s+("(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)))?\s*\)/
11
+ INLINE_REFLINK_REGEX = /^\s*\[((?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?)\]:\s*(?:<\s*(\/(?:\\.|[^\n<>\\])+)>|(\/[^\s\x00-\x1f]*))(?:\s+("(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)))?\s*$/
12
+
13
+ def convert (doc)
14
+ text = doc.content
15
+ text.gsub!(INLINE_LINK_REGEX, '[\1]({{ "\2\3" | relative_url }} \4)')
16
+ text.gsub!(INLINE_REFLINK_REGEX, '[\1]: {{ "\2\3" | relative_url }} \4')
17
+ # puts text
18
+ end
19
+
20
+ def needconvert? (doc)
21
+ site_config = doc.site.config
22
+ extname_list ||= site_config["markdown_ext"].split(",").map! { |e| ".#{e.downcase}" }
23
+
24
+ extname_list.include?(doc.extname.downcase) &&
25
+ site_config["auto-relative"] != false && doc.data["auto-relative"] != false &&
26
+ (site_config["auto-relative"] == true || doc.data["auto-relative"] == true)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ Jekyll::Hooks.register [:pages, :documents], :pre_render do |doc|
33
+ Jekyll::AutoRelative.convert(doc) if Jekyll::AutoRelative.needconvert?(doc)
34
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-auto-relative
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Qucheng Miao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
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
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/jekyll-auto-relative.rb
34
+ homepage: https://github.com/qcmiao1998/jekyll-auto-relative
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ homepage_uri: https://github.com/qcmiao1998/jekyll-auto-relative
39
+ source_code_uri: https://github.com/qcmiao1998/jekyll-auto-relative
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.3.7
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: This is a plugin for converting urls in markdown files to relative paths
59
+ required by Jekyll.
60
+ test_files: []