jekyll-wikilinks 0.0.7 → 0.0.8
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/lib/jekyll-wikilinks/config.rb +17 -13
- data/lib/jekyll-wikilinks/patch/doc_manager.rb +43 -19
- data/lib/jekyll-wikilinks/patch/site.rb +1 -1
- data/lib/jekyll-wikilinks/plugins/filter.rb +23 -21
- data/lib/jekyll-wikilinks/plugins/generator.rb +4 -4
- data/lib/jekyll-wikilinks/util/link_index.rb +42 -65
- data/lib/jekyll-wikilinks/util/parser.rb +70 -364
- data/lib/jekyll-wikilinks/util/regex.rb +36 -30
- data/lib/jekyll-wikilinks/util/wikilink.rb +278 -0
- data/lib/jekyll-wikilinks/version.rb +1 -1
- data/lib/jekyll-wikilinks.rb +3 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9faa067220a9b3603654fbcf2fc240fd66b9e143ad197700e5773c9c1876e5d0
|
4
|
+
data.tar.gz: fd3b93e960ed6dc0f7e2e7cc09a6ec7ee3d1742a5e377c801fe2d054927d0f2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca52556545cfaf6d09be217fe824e1e07f7d7621b4a8ca06d4e9c62dc85df95561f5c00468cf302d978bb2fd5b61548d14ac860ed746d91d2a25fa5e9d1cccee
|
7
|
+
data.tar.gz: cba704245f83e5eeed86b21a20fd26a7713312b76e4ce5ef44e60dfc1b55020c2af6d8c0de4bd258a927f3131d313312964ecc7a55d94a83dcf53beeeeb48ff7
|
@@ -32,27 +32,27 @@ module Jekyll
|
|
32
32
|
def initialize(config)
|
33
33
|
@config ||= config
|
34
34
|
self.old_config_warn()
|
35
|
-
Jekyll.logger.debug
|
35
|
+
Jekyll.logger.debug("Jekyll-Wikilinks: Excluded jekyll types: #{option(EXCLUDE_KEY)}") unless disabled?
|
36
36
|
end
|
37
37
|
|
38
38
|
# util
|
39
39
|
|
40
40
|
def css_name(name_key)
|
41
41
|
return option_css_name(name_key) if option_css_name(name_key)
|
42
|
-
return "typed"
|
42
|
+
return "typed" if name_key == TYPED_KEY
|
43
43
|
# valid
|
44
|
-
return "wiki-link"
|
44
|
+
return "wiki-link" if name_key == WIKI_KEY
|
45
45
|
# invalid
|
46
|
-
return "invalid-wiki-link"
|
46
|
+
return "invalid-wiki-link" if name_key == INV_WIKI_KEY
|
47
47
|
# return "invalid-web-link" if name_key == INV_WEB_KEY
|
48
48
|
# embeds
|
49
|
-
return "embed-wrapper"
|
50
|
-
return "embed-title"
|
51
|
-
return "embed-content"
|
52
|
-
return "embed-wiki-link"
|
49
|
+
return "embed-wrapper" if name_key == EMBED_WRAPPER_KEY
|
50
|
+
return "embed-title" if name_key == EMBED_TITLE_KEY
|
51
|
+
return "embed-content" if name_key == EMBED_CONTENT_KEY
|
52
|
+
return "embed-wiki-link" if name_key == EMBED_LINK_KEY
|
53
53
|
# img
|
54
|
-
return "embed-image-wrapper"
|
55
|
-
return "embed-image"
|
54
|
+
return "embed-image-wrapper" if name_key == EMBED_IMG_WRAPPER_KEY
|
55
|
+
return "embed-image" if name_key == EMBED_IMG_KEY
|
56
56
|
end
|
57
57
|
|
58
58
|
def disabled?
|
@@ -68,6 +68,10 @@ module Jekyll
|
|
68
68
|
return option(EXCLUDE_KEY).include?(type.to_s)
|
69
69
|
end
|
70
70
|
|
71
|
+
def excluded_css_names
|
72
|
+
return self.option_css(EXCLUDE_KEY)
|
73
|
+
end
|
74
|
+
|
71
75
|
# options
|
72
76
|
|
73
77
|
def option(key)
|
@@ -94,13 +98,13 @@ module Jekyll
|
|
94
98
|
|
95
99
|
def old_config_warn()
|
96
100
|
if @config.include?("wikilinks_collection")
|
97
|
-
Jekyll.logger.warn
|
101
|
+
Jekyll.logger.warn("Jekyll-Wikilinks: As of 0.0.3, 'wikilinks_collection' is no longer used for configs. jekyll-wikilinks will scan all markdown files by default. Check README for details.")
|
98
102
|
end
|
99
103
|
if option_exist?("assets_rel_path")
|
100
|
-
Jekyll.logger.warn
|
104
|
+
Jekyll.logger.warn("Jekyll-Wikilinks: As of 0.0.5, 'assets_rel_path' is now 'path'.")
|
101
105
|
end
|
102
106
|
if @config.include?("d3_graph_data")
|
103
|
-
Jekyll.logger.warn
|
107
|
+
Jekyll.logger.warn("Jekyll-Wikilinks: As of 0.0.6, 'd3_graph_data' and graph functionality have been moved to the 'jekyll-graph' plugin.")
|
104
108
|
end
|
105
109
|
end
|
106
110
|
end
|
@@ -7,8 +7,22 @@ module Jekyll
|
|
7
7
|
#
|
8
8
|
# this class is responsible for answering any questions
|
9
9
|
# related to jekyll markdown documents
|
10
|
-
# that are meant to be processed by the wikilinks plugin
|
10
|
+
# that are meant to be processed by the wikilinks plugin.
|
11
11
|
#
|
12
|
+
# the following methods are specifically to address two things:
|
13
|
+
# 1. ruby's 'find' / 'detect' function does not throw errors if
|
14
|
+
# there are multiple matches. fail fast, i want to know if there
|
15
|
+
# are duplicates.
|
16
|
+
# (not using sets because i don't want to clobber existing documents)
|
17
|
+
# 2. handle all jekyll documents in one place. i don't want to
|
18
|
+
# have to filter all documents for target markdown documents
|
19
|
+
# every time i need to check if a file exists.
|
20
|
+
#
|
21
|
+
# there is probably a better way to do this...i would prefer to have
|
22
|
+
# a plugin-wide function that just wraps all of this and can be called
|
23
|
+
# from anywhere in the plugin...but ruby is not a functional language...
|
24
|
+
# gotta have classes...
|
25
|
+
#
|
12
26
|
class DocManager
|
13
27
|
CONVERTER_CLASS = Jekyll::Converters::Markdown
|
14
28
|
|
@@ -22,7 +36,7 @@ module Jekyll
|
|
22
36
|
docs += site.docs_to_write.filter { |d| !$wiki_conf.exclude?(d.type) }
|
23
37
|
@md_docs = docs.filter { |doc| markdown_converter.matches(doc.extname) }
|
24
38
|
if @md_docs.nil? || @md_docs.empty?
|
25
|
-
Jekyll.logger.
|
39
|
+
Jekyll.logger.warn("Jekyll-Wikilinks: No documents to process.")
|
26
40
|
end
|
27
41
|
|
28
42
|
@static_files ||= site.static_files
|
@@ -35,43 +49,53 @@ module Jekyll
|
|
35
49
|
end
|
36
50
|
|
37
51
|
def get_doc_by_fname(filename)
|
38
|
-
|
52
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
|
39
53
|
docs = @md_docs.select{ |d| File.basename(d.basename, File.extname(d.basename)) == filename }
|
40
|
-
return nil if docs.nil? || docs.size > 1
|
54
|
+
return nil if docs.nil? || docs.empty? || docs.size > 1
|
41
55
|
return docs[0]
|
42
56
|
end
|
43
57
|
|
44
58
|
def get_doc_by_url(url)
|
45
|
-
|
59
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'url'") if url.nil? || url.empty?
|
46
60
|
docs = @md_docs.select{ |d| d.url == url }
|
47
|
-
return nil if docs.nil? || docs.size > 1
|
61
|
+
return nil if docs.nil? || docs.empty? || docs.size > 1
|
48
62
|
return docs[0]
|
49
63
|
end
|
50
64
|
|
51
65
|
def get_doc_content(filename)
|
52
|
-
|
53
|
-
|
54
|
-
return
|
55
|
-
return nil
|
66
|
+
doc = self.get_doc_by_fname(filename)
|
67
|
+
return nil if docs.nil?
|
68
|
+
return doc.content
|
56
69
|
end
|
57
70
|
|
58
71
|
def get_image_by_fname(filename)
|
59
|
-
|
72
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
|
73
|
+
return nil if @static_files.size == 0 || !SUPPORTED_IMG_FORMATS.any?{ |ext| ext == File.extname(filename).downcase }
|
60
74
|
docs = @static_files.select{ |d| File.basename(d.relative_path) == filename }
|
61
|
-
return nil if docs.nil? || docs.size > 1
|
75
|
+
return nil if docs.nil? || docs.empty? || docs.size > 1
|
62
76
|
return docs[0]
|
63
77
|
end
|
64
78
|
|
65
|
-
|
66
|
-
|
79
|
+
# validators
|
80
|
+
|
81
|
+
def file_exists?(filename)
|
82
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
|
83
|
+
docs = @md_docs.select{ |d| File.basename(d.basename, File.extname(d.basename)) == filename }
|
84
|
+
docs += @static_files.select{ |d| File.basename(d.relative_path) == filename }
|
85
|
+
return false if docs.nil? || docs.empty? || docs.size > 1
|
86
|
+
return true
|
87
|
+
end
|
88
|
+
|
89
|
+
def doc_has_header?(doc, header)
|
90
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'header'") if header.nil? || header.empty?
|
67
91
|
# leading + trailing whitespace is ignored when matching headers
|
68
|
-
header_results = doc.content.scan(REGEX_ATX_HEADER).flatten.map { |htxt| htxt.strip }
|
69
|
-
setext_header_results = doc.content.scan(REGEX_SETEXT_HEADER).flatten.map { |htxt| htxt.strip }
|
70
|
-
return header_results.include?(header.strip) || setext_header_results.include?(header.strip)
|
92
|
+
header_results = doc.content.scan(REGEX_ATX_HEADER).flatten.map { |htxt| htxt.downcase.strip }
|
93
|
+
setext_header_results = doc.content.scan(REGEX_SETEXT_HEADER).flatten.map { |htxt| htxt.downcase.strip }
|
94
|
+
return header_results.include?(header.downcase.strip) || setext_header_results.include?(header.downcase.strip)
|
71
95
|
end
|
72
96
|
|
73
|
-
def
|
74
|
-
|
97
|
+
def doc_has_block_id?(doc, block_id)
|
98
|
+
Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'block_id'") if block_id.nil? || block_id.empty?
|
75
99
|
# leading + trailing whitespace is ignored when matching blocks
|
76
100
|
block_id_results = doc.content.scan(REGEX_BLOCK).flatten.map { |bid| bid.strip }
|
77
101
|
return block_id_results.include?(block_id)
|
@@ -5,66 +5,68 @@ module Jekyll
|
|
5
5
|
|
6
6
|
module TypeFilters
|
7
7
|
# 'links' accepts untyped links, typed links, and attributes; fore and back.
|
8
|
+
# why: these filters are useful when you want to list backlinks of certain type(s) and don't want type mismatches to display as "missing"
|
8
9
|
|
9
|
-
# usage: {% assign note_links = page.links | doc_type
|
10
|
-
# TODO: if you simply filter links against specific jekyll types, this filter is completely unecessary...
|
11
|
-
# // looping through backlinks:
|
12
|
-
# {% assign note_links = site.notes | where: "url", backlink.url | first %}
|
10
|
+
# usage: {% assign note_links = page.links | doc_type: "notes" %}
|
13
11
|
def doc_type(links, doc_type)
|
14
|
-
Jekyll.logger.error("'links'
|
15
|
-
|
12
|
+
Jekyll.logger.error("Jekyll-Wikilinks: 'links' invalid") if links.nil?
|
13
|
+
Jekyll.logger.error("Jekyll-Wikilinks: 'doc_type' invalid") if doc_type.nil? || doc_type.empty?
|
16
14
|
return [] if links.empty?
|
17
15
|
|
18
16
|
site = @context.registers[:site]
|
17
|
+
|
18
|
+
links_of_type = []
|
19
19
|
links.each do |l|
|
20
20
|
# links
|
21
21
|
if l.keys.include?('url')
|
22
|
-
|
23
|
-
if !
|
24
|
-
|
22
|
+
docs = site.documents.select{ |d| d.url == l['url'] && d.type.to_s == doc_type.to_s }
|
23
|
+
if !docs.nil? && docs.size == 1
|
24
|
+
links_of_type << l
|
25
25
|
end
|
26
26
|
# attributes
|
27
27
|
elsif l.keys.include?('urls')
|
28
28
|
l['urls'].each do |lurl|
|
29
|
-
|
30
|
-
if !
|
31
|
-
|
29
|
+
docs = site.documents.select{ |d| d.url == lurl && d.type.to_s == doc_type.to_s }
|
30
|
+
if !docs.nil? && docs.size == 1
|
31
|
+
links_of_type << l
|
32
32
|
end
|
33
33
|
end
|
34
34
|
else
|
35
|
-
Jekyll.
|
35
|
+
Jekyll.logger.error("Jekyll-Wikilinks: In 'doc_type' filter, 'links' do not have 'url' or 'urls'")
|
36
36
|
end
|
37
37
|
end
|
38
|
-
return
|
38
|
+
return links_of_type.uniq
|
39
39
|
end
|
40
40
|
|
41
|
-
# usage: {% assign author_links = page.links | rel_type
|
41
|
+
# usage: {% assign author_links = page.links | rel_type: "author" %}
|
42
42
|
def rel_type(links, link_type)
|
43
|
-
Jekyll.logger.error("'links'
|
44
|
-
|
43
|
+
Jekyll.logger.error("Jekyll-Wikilinks: 'links' invalid") if links.nil?
|
44
|
+
Jekyll.logger.error("Jekyll-Wikilinks: 'link_type' invalid") if link_type.nil?
|
45
45
|
return [] if links.empty?
|
46
46
|
|
47
47
|
site = @context.registers[:site]
|
48
|
+
|
49
|
+
links_of_type = []
|
48
50
|
links.each do |l|
|
49
51
|
if l.keys.include?('url')
|
50
52
|
if l['type'].to_s == link_type.to_s
|
51
53
|
docs = site.documents.select{ |d| d.url == l['url'] }
|
52
54
|
if !doc.nil? && doc.size != 1
|
53
|
-
|
55
|
+
links_of_type << l
|
54
56
|
end
|
55
57
|
end
|
56
58
|
elsif l.keys.include?('urls')
|
57
59
|
l['urls'].each do |lurl|
|
58
60
|
docs = site.documents.select{ |d| d.url == lurl }
|
59
61
|
if !doc.nil? && doc.size != 1
|
60
|
-
|
62
|
+
links_of_type << lurl
|
61
63
|
end
|
62
64
|
end
|
63
65
|
else
|
64
|
-
Jekyll.logge.error("In 'rel_type' filter, 'links' do not have 'url' or 'urls'")
|
66
|
+
Jekyll.logge.error("Jekyll-Wikilinks: In 'rel_type' filter, 'links' do not have 'url' or 'urls'")
|
65
67
|
end
|
66
68
|
end
|
67
|
-
return
|
69
|
+
return links_of_type.uniq
|
68
70
|
end
|
69
71
|
|
70
72
|
end
|
@@ -6,7 +6,6 @@ require_relative "../patch/doc_manager"
|
|
6
6
|
require_relative "../patch/site"
|
7
7
|
require_relative "../util/link_index"
|
8
8
|
require_relative "../util/parser"
|
9
|
-
require_relative "converter"
|
10
9
|
|
11
10
|
module Jekyll
|
12
11
|
module WikiLinks
|
@@ -24,13 +23,14 @@ module Jekyll
|
|
24
23
|
@site.link_index = LinkIndex.new(@site)
|
25
24
|
|
26
25
|
@site.doc_mngr.all.each do |doc|
|
27
|
-
|
28
|
-
@
|
26
|
+
filename = File.basename(doc.basename, File.extname(doc.basename))
|
27
|
+
@parser.parse(filename, doc.content)
|
28
|
+
@site.link_index.populate(doc, @parser.wikilink_blocks, @parser.wikilink_inlines)
|
29
29
|
end
|
30
30
|
# wait until all docs are processed before assigning backward facing metadata,
|
31
31
|
# this ensures all attributed/backlinks are collected for assignment
|
32
32
|
@site.doc_mngr.all.each do |doc|
|
33
|
-
|
33
|
+
# populate frontmatter metadata from (wiki)link index
|
34
34
|
@site.link_index.assign_metadata(doc)
|
35
35
|
end
|
36
36
|
end
|
@@ -10,7 +10,7 @@ module Jekyll
|
|
10
10
|
@baseurl = site.baseurl
|
11
11
|
@index = {}
|
12
12
|
site.doc_mngr.all.each do |doc|
|
13
|
-
@index[doc.url] =
|
13
|
+
@index[doc.url] = DocLinks.new()
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -22,80 +22,57 @@ module Jekyll
|
|
22
22
|
doc.data['missing'] = @index[doc.url].missing.uniq
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
#
|
27
|
-
wikilink_blocks.each do |
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
def populate(doc, wikilink_blocks, wikilink_inlines)
|
26
|
+
# blocks
|
27
|
+
wikilink_blocks.each do |wlbl|
|
28
|
+
if wlbl.is_valid?
|
29
|
+
# attributes
|
30
|
+
target_attr = @index[doc.url].attributes.detect { |atr| atr['type'] == wlbl.link_type }
|
31
|
+
## create
|
32
|
+
if target_attr.nil?
|
33
|
+
@index[doc.url].attributes << wlbl.linked_fm_data
|
34
|
+
## append
|
35
|
+
else
|
36
|
+
target_attr['urls'] += wlbl.urls
|
33
37
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Jekyll.logger.warn("No documents found for urls: #{urls}")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
# forelinks - inlines
|
45
|
-
wikilink_inlines.each do |wlil|
|
46
|
-
link_doc = md_docs.detect { |d| File.basename(d.basename, File.extname(d.basename)) == wlil.filename }
|
47
|
-
if !link_doc.nil?
|
48
|
-
@index[doc.url].forelinks << {
|
49
|
-
'type' => wlil.link_type,
|
50
|
-
'url' => link_doc.url,
|
51
|
-
}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
# ...process missing links
|
55
|
-
doc.content.scan(REGEX_INVALID_WIKI_LINK).each do |m|
|
56
|
-
ltext = m[0]
|
57
|
-
@index[doc.url].missing << ltext
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def populate_backward(doc, md_docs)
|
62
|
-
md_docs.each do |doc_to_link|
|
63
|
-
# attributed
|
64
|
-
@index[doc_to_link.url].attributes.each do |al|
|
65
|
-
urls = al['urls'].map { |url| self.remove_baseurl(url) }
|
66
|
-
if urls.include?(doc.url)
|
67
|
-
target_attr = @index[doc.url].attributed.detect { |atr| atr['type'] == al['type']}
|
68
|
-
# add
|
69
|
-
if !target_attr.nil?
|
70
|
-
target_attr['urls'] << doc_to_link.url
|
71
|
-
# create new
|
38
|
+
# attributed
|
39
|
+
wlbl.linked_docs.each do |linked_doc|
|
40
|
+
target_attr = @index[linked_doc.url].attributed.detect { |atr| atr['type'] == wlbl.link_type }
|
41
|
+
## create
|
42
|
+
if target_attr.nil?
|
43
|
+
@index[linked_doc.url].attributed << wlbl.context_fm_data
|
44
|
+
## append
|
72
45
|
else
|
73
|
-
urls
|
74
|
-
@index[doc.url].attributed << {
|
75
|
-
'type' => al['type'],
|
76
|
-
'urls' => [ doc_to_link.url ],
|
77
|
-
}
|
46
|
+
target_attr['urls'] << doc.url
|
78
47
|
end
|
79
48
|
end
|
49
|
+
else
|
50
|
+
wlbl.filenames.each do |fn|
|
51
|
+
@index[doc.url].missing << fn
|
52
|
+
end
|
80
53
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
54
|
+
end
|
55
|
+
# inlines
|
56
|
+
wikilink_inlines.each do |wlil|
|
57
|
+
if !wlil.is_img?
|
58
|
+
if wlil.is_valid?
|
59
|
+
# forelink
|
60
|
+
@index[doc.url].forelinks << wlil.linked_fm_data
|
61
|
+
# backlink
|
62
|
+
@index[wlil.linked_doc.url].backlinks << wlil.context_fm_data
|
63
|
+
else
|
64
|
+
@index[doc.url].missing << wlil.filename
|
88
65
|
end
|
89
66
|
end
|
90
67
|
end
|
91
68
|
end
|
92
69
|
|
93
|
-
def remove_baseurl(url)
|
94
|
-
|
95
|
-
|
96
|
-
end
|
70
|
+
# def remove_baseurl(url)
|
71
|
+
# return url.gsub(@baseurl, '') if !@baseurl.nil?
|
72
|
+
# return url
|
73
|
+
# end
|
97
74
|
|
98
|
-
class
|
75
|
+
class DocLinks
|
99
76
|
attr_accessor :attributes, :attributed, :backlinks, :forelinks, :missing
|
100
77
|
|
101
78
|
def initialize
|
@@ -103,7 +80,7 @@ module Jekyll
|
|
103
80
|
@attributes = [] # block typed forelinks; { 'type' => str, 'urls' => [ str ] }
|
104
81
|
@backlinks = [] # inline typed and basic backlinks; { 'type' => str, 'url' => str }
|
105
82
|
@forelinks = [] # inline typed and basic forelinks; { 'type' => str, 'url' => str }
|
106
|
-
@missing = [] # missing forelinks;
|
83
|
+
@missing = [] # missing forelinks + attributes; ( built from (missing) filenames )
|
107
84
|
end
|
108
85
|
end
|
109
86
|
end
|