jekyll-wikilinks 0.0.7 → 0.0.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 861b1b580036bacff2ddf67c3080e21ec36adfe550944fb637ee07ce6afa5b58
4
- data.tar.gz: 62380a8fbc94fdb4646055999b1deaf339a561bf3fbdfb8f858b0b8e993573fb
3
+ metadata.gz: c2acbae9be49d78fdcbbe55411349c1321ac86cd8222ccd44657d04bbbd446ea
4
+ data.tar.gz: 28811da20a489fbd36c8566aea26b493e5a26b11e1e020f52d88b69d17d30e08
5
5
  SHA512:
6
- metadata.gz: fa76884a4da7bdca8ec6d389140a8c7f0b193563bba676abe81ea683b6932444abcfe1fb619c0e6186450f38eb81cced6067c154c275854fd73bc81b932c4455
7
- data.tar.gz: 4e2ffa8675e1a6d5066f472d3b021d1d8c20a11104c1802b0dd451c45d92120b410aea44c8bf8b6af6a42b0d9d3bb287cb4469382e8c66d7e03448cff650c0da
6
+ metadata.gz: 914ed17d2a796330f190f7e97edb14f7dc328445c2e0a044ddc35532d927bca469baabb90a179455e39d04c368188bdeb328e1a7ce8a1be7d2f01a3356594ebc
7
+ data.tar.gz: 8bdd89667f8beba351bfd7233245135222d1cb3a432b9ff4b3df2c471252b5f9b09e2cc95cb75f57607e6d47ca73559f7c964b8b1f977a8a5ecd3b734b9d751a
@@ -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 "Excluded jekyll types: ", option(EXCLUDE_KEY) unless disabled?
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" if name_key == TYPED_KEY
42
+ return "typed" if name_key == TYPED_KEY
43
43
  # valid
44
- return "wiki-link" if name_key == WIKI_KEY
44
+ return "wiki-link" if name_key == WIKI_KEY
45
45
  # invalid
46
- return "invalid-wiki-link" if name_key == INV_WIKI_KEY
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" 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
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" if name_key == EMBED_IMG_WRAPPER_KEY
55
- return "embed-image" if name_key == EMBED_IMG_KEY
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 "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."
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 "As of 0.0.5, 'assets_rel_path' is now 'path'."
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 "As of 0.0.6, 'd3_graph_data' and graph functionality have been moved to the 'jekyll-graph' plugin."
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
@@ -4,11 +4,26 @@ require_relative "../util/regex"
4
4
  module Jekyll
5
5
  module WikiLinks
6
6
 
7
+ # todo: move these methods to the 'WikiLink' classes...?
7
8
  #
8
9
  # this class is responsible for answering any questions
9
10
  # related to jekyll markdown documents
10
- # that are meant to be processed by the wikilinks plugin
11
+ # that are meant to be processed by the wikilinks plugin.
11
12
  #
13
+ # the following methods are specifically to address two things:
14
+ # 1. ruby's 'find' / 'detect' function does not throw errors if
15
+ # there are multiple matches. fail fast, i want to know if there
16
+ # are duplicates.
17
+ # (not using sets because i don't want to clobber existing documents)
18
+ # 2. handle all jekyll documents in one place. i don't want to
19
+ # have to filter all documents for target markdown documents
20
+ # every time i need to check if a file exists.
21
+ #
22
+ # there is probably a better way to do this...i would prefer to have
23
+ # a plugin-wide function that just wraps all of this and can be called
24
+ # from anywhere in the plugin...but ruby is not a functional language...
25
+ # gotta have classes...
26
+ #
12
27
  class DocManager
13
28
  CONVERTER_CLASS = Jekyll::Converters::Markdown
14
29
 
@@ -22,7 +37,7 @@ module Jekyll
22
37
  docs += site.docs_to_write.filter { |d| !$wiki_conf.exclude?(d.type) }
23
38
  @md_docs = docs.filter { |doc| markdown_converter.matches(doc.extname) }
24
39
  if @md_docs.nil? || @md_docs.empty?
25
- Jekyll.logger.debug("No documents to process.")
40
+ Jekyll.logger.warn("Jekyll-Wikilinks: No documents to process.")
26
41
  end
27
42
 
28
43
  @static_files ||= site.static_files
@@ -35,43 +50,63 @@ module Jekyll
35
50
  end
36
51
 
37
52
  def get_doc_by_fname(filename)
38
- return nil if filename.nil? || @md_docs.size == 0
53
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
39
54
  docs = @md_docs.select{ |d| File.basename(d.basename, File.extname(d.basename)) == filename }
40
- return nil if docs.nil? || docs.size > 1
55
+ return nil if docs.nil? || docs.empty? || docs.size > 1
56
+ return docs[0]
57
+ end
58
+
59
+ def get_doc_by_fpath(file_path)
60
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'file_path'") if file_path.nil? || file_path.empty?
61
+ docs = @md_docs.select{ |d| d.relative_path == (file_path + ".md") }
62
+ return nil if docs.nil? || docs.empty? || docs.size > 1
41
63
  return docs[0]
42
64
  end
43
65
 
44
66
  def get_doc_by_url(url)
45
- return nil if url.nil? || @md_docs.size == 0
67
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'url'") if url.nil? || url.empty?
46
68
  docs = @md_docs.select{ |d| d.url == url }
47
- return nil if docs.nil? || docs.size > 1
69
+ return nil if docs.nil? || docs.empty? || docs.size > 1
48
70
  return docs[0]
49
71
  end
50
72
 
51
73
  def get_doc_content(filename)
52
- return nil if filename.nil? || @md_docs.size == 0
53
- docs = @md_docs.select{ |d| File.basename(d.basename, File.extname(d.basename)) == filename }
54
- return docs[0].content if docs.size == 1
55
- return nil
74
+ doc = self.get_doc_by_fname(filename)
75
+ return nil if docs.nil?
76
+ return doc.content
56
77
  end
57
78
 
58
79
  def get_image_by_fname(filename)
59
- return nil if filename.nil? || @static_files.size == 0 || !SUPPORTED_IMG_FORMATS.any?{ |ext| ext == File.extname(filename).downcase }
80
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
81
+ return nil if @static_files.size == 0 || !SUPPORTED_IMG_FORMATS.any?{ |ext| ext == File.extname(filename).downcase }
60
82
  docs = @static_files.select{ |d| File.basename(d.relative_path) == filename }
61
- return nil if docs.nil? || docs.size > 1
83
+ return nil if docs.nil? || docs.empty? || docs.size > 1
62
84
  return docs[0]
63
85
  end
64
86
 
65
- def self.doc_has_header?(doc, header)
66
- return nil if header.nil?
87
+ # validators
88
+
89
+ def file_exists?(filename, file_path=nil)
90
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'filename'") if filename.nil? || filename.empty?
91
+ if file_path.nil?
92
+ return false if get_doc_by_fname(filename).nil? && get_image_by_fname(filename).nil?
93
+ return true
94
+ else
95
+ return false if get_doc_by_fpath(file_path).nil?
96
+ return true
97
+ end
98
+ end
99
+
100
+ def doc_has_header?(doc, header)
101
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'header'") if header.nil? || header.empty?
67
102
  # 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)
103
+ header_results = doc.content.scan(REGEX_ATX_HEADER).flatten.map { |htxt| htxt.downcase.strip }
104
+ setext_header_results = doc.content.scan(REGEX_SETEXT_HEADER).flatten.map { |htxt| htxt.downcase.strip }
105
+ return header_results.include?(header.downcase.strip) || setext_header_results.include?(header.downcase.strip)
71
106
  end
72
107
 
73
- def self.doc_has_block_id?(doc, block_id)
74
- return nil if block_id.nil?
108
+ def doc_has_block_id?(doc, block_id)
109
+ Jekyll.logger.error("Jekyll-Wikilinks: Must provide a 'block_id'") if block_id.nil? || block_id.empty?
75
110
  # leading + trailing whitespace is ignored when matching blocks
76
111
  block_id_results = doc.content.scan(REGEX_BLOCK).flatten.map { |bid| bid.strip }
77
112
  return block_id_results.include?(block_id)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "jekyll"
3
3
 
4
- # appending to built-in jekyll site object to pass data to jekyll-d3
4
+ # appending to built-in jekyll site object to pass data to jekyll-graph
5
5
 
6
6
  module Jekyll
7
7
 
@@ -5,66 +5,74 @@ 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 = "notes" %}
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' should not be nil") if links.nil?
15
- return "No doc type given" if doc_type.empty?
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
- doc = site.documents.select{ |d| d.url == l['url'] && d.type.to_s == doc_type.to_s }
23
- if !doc.nil? && doc.size != 1
24
- links.delete(l)
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
- doc = site.documents.select{ |d| d.url == lurl && d.type.to_s == doc_type.to_s }
30
- if !doc.nil? && doc.size != 1
31
- links['urls'].delete(lurl)
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.logge.error("In 'doc_type' filter, 'links' do not have 'url' or 'urls'")
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 links.uniq
38
+ return links_of_type.uniq
39
39
  end
40
40
 
41
- # usage: {% assign author_links = page.links | rel_type = "author" %}
42
- def rel_type(links, link_type)
43
- Jekyll.logger.error("'links' should not be nil") if links.nil?
44
- return "No link type given" if link_type.empty?
41
+ # usage: {% assign author_links = page.links | link_type: "author" %}
42
+ def link_type(links, link_type)
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
- if l.keys.include?('url')
50
- if l['type'].to_s == link_type.to_s
51
+ if l['type'].to_s == link_type.to_s
52
+ # links
53
+ if l.keys.include?('url')
51
54
  docs = site.documents.select{ |d| d.url == l['url'] }
52
- if !doc.nil? && doc.size != 1
53
- links.delete(l)
55
+ if !doc.nil? && docs.size != 1
56
+ links_of_type << l
54
57
  end
55
- end
56
- elsif l.keys.include?('urls')
57
- l['urls'].each do |lurl|
58
- docs = site.documents.select{ |d| d.url == lurl }
59
- if !doc.nil? && doc.size != 1
60
- links['urls'].delete(lurl)
58
+ # attributes
59
+ elsif l.keys.include?('urls')
60
+ all_docs_exist = true
61
+ l['urls'].each do |lurl|
62
+ docs = site.documents.select{ |d| d.url == lurl }
63
+ if !docs.nil? && docs.size != 1
64
+ all_docs_exist = false
65
+ end
61
66
  end
67
+ if all_docs_exist
68
+ links_of_type << l
69
+ end
70
+ else
71
+ Jekyll.logge.error("Jekyll-Wikilinks: In 'link_type' filter, 'links' do not have 'url' or 'urls'")
62
72
  end
63
- else
64
- Jekyll.logge.error("In 'rel_type' filter, 'links' do not have 'url' or 'urls'")
65
73
  end
66
74
  end
67
- return links.uniq
75
+ return links_of_type.uniq
68
76
  end
69
77
 
70
78
  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
- @parser.parse(doc.content)
28
- @site.link_index.populate_forward(doc, @parser.wikilink_blocks, @parser.wikilink_inlines, @site.doc_mngr.all)
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
- @site.link_index.populate_backward(doc, @site.doc_mngr.all)
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] = LinksInfo.new()
13
+ @index[doc.url] = DocLinks.new()
14
14
  end
15
15
  end
16
16
 
@@ -22,80 +22,67 @@ module Jekyll
22
22
  doc.data['missing'] = @index[doc.url].missing.uniq
23
23
  end
24
24
 
25
- def populate_forward(doc, wikilink_blocks, wikilink_inlines, md_docs)
26
- # attributes - blocks
27
- wikilink_blocks.each do |tlbl|
28
- urls = []
29
- tlbl.list_items.each do |bullet_type, filename|
30
- attr_doc = md_docs.detect { |d| File.basename(d.basename, File.extname(d.basename)) == filename }
31
- if !attr_doc.nil?
32
- urls << attr_doc.url
25
+ def populate(doc, wikilink_blocks, wikilink_inlines)
26
+ # #
27
+ # blocks #
28
+ # #
29
+ wikilink_blocks.each do |wlbl|
30
+ if wlbl.is_valid?
31
+ #
32
+ # attributes
33
+ #
34
+ target_attr = @index[doc.url].attributes.detect { |atr| atr['type'] == wlbl.link_type }
35
+ # create
36
+ if target_attr.nil?
37
+ @index[doc.url].attributes << wlbl.linked_fm_data
38
+ # append
39
+ else
40
+ target_attr['urls'] += wlbl.urls
33
41
  end
34
- end
35
- if !urls.nil? && !urls.empty?
36
- @index[doc.url].attributes << {
37
- 'type' => tlbl.link_type,
38
- 'urls' => urls,
39
- }
40
- else
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
42
+ ## append missing docs
43
+ @index[doc.url].missing += wlbl.missing_doc_filenames
44
+ #
45
+ # attributed
46
+ #
47
+ wlbl.linked_docs.each do |linked_doc|
48
+ target_attr = @index[linked_doc.url].attributed.detect { |atr| atr['type'] == wlbl.link_type }
49
+ # create
50
+ if target_attr.nil?
51
+ @index[linked_doc.url].attributed << wlbl.context_fm_data
52
+ # append
72
53
  else
73
- urls = @index[doc.url].attributed.detect { |a| a['type'] == al['type'] }
74
- @index[doc.url].attributed << {
75
- 'type' => al['type'],
76
- 'urls' => [ doc_to_link.url ],
77
- }
54
+ target_attr['urls'] << doc.url
78
55
  end
79
56
  end
57
+ else
58
+ #
59
+ # invalid || empty
60
+ #
61
+ @index[doc.url].missing += wlbl.missing_doc_filenames
80
62
  end
81
- # backlinks
82
- @index[doc_to_link.url].forelinks.each do |l|
83
- if self.remove_baseurl(l['url']) == doc.url
84
- @index[doc.url].backlinks << {
85
- 'type' => l['type'],
86
- 'url' => doc_to_link.url,
87
- }
88
- end
63
+ end
64
+ # #
65
+ # inlines #
66
+ # #
67
+ wikilink_inlines.each do |wlil|
68
+ return if wlil.is_img?
69
+ if wlil.is_valid?
70
+ # forelink
71
+ @index[doc.url].forelinks << wlil.linked_fm_data
72
+ # backlink
73
+ @index[wlil.linked_doc.url].backlinks << wlil.context_fm_data
74
+ else
75
+ @index[doc.url].missing << wlil.filename
89
76
  end
90
77
  end
91
78
  end
92
79
 
93
- def remove_baseurl(url)
94
- return url.gsub(@baseurl, '') if !@baseurl.nil?
95
- return url
96
- end
80
+ # def remove_baseurl(url)
81
+ # return url.gsub(@baseurl, '') if !@baseurl.nil?
82
+ # return url
83
+ # end
97
84
 
98
- class LinksInfo
85
+ class DocLinks
99
86
  attr_accessor :attributes, :attributed, :backlinks, :forelinks, :missing
100
87
 
101
88
  def initialize
@@ -103,7 +90,7 @@ module Jekyll
103
90
  @attributes = [] # block typed forelinks; { 'type' => str, 'urls' => [ str ] }
104
91
  @backlinks = [] # inline typed and basic backlinks; { 'type' => str, 'url' => str }
105
92
  @forelinks = [] # inline typed and basic forelinks; { 'type' => str, 'url' => str }
106
- @missing = [] # missing forelinks; [ str ]
93
+ @missing = [] # missing forelinks + attributes; ( built from (missing) filenames )
107
94
  end
108
95
  end
109
96
  end