jekyll-wikilinks 0.0.6 → 0.0.10

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: e65a8cc36608b07333b7fe02a0f37f100117c7ed94d0b2e0fa500520eee6a2aa
4
- data.tar.gz: 8d28d1930fedbddfd17d13c431f42043cdfb3333493929f78977d8da122c0647
3
+ metadata.gz: 9067c4d2ad9673d39b79195cb9bd4ef955e5cccac52702bfdd731c9d0aade4b7
4
+ data.tar.gz: 9b5a31b067e375100933d101b9bab94b8a1d19e17327ab0306cea6ea83543b18
5
5
  SHA512:
6
- metadata.gz: bae180a6824ea1a646d9103a0e6701814e1792275ae1037119db819b91fc35a9d01d8fc5c4b64ea8ba689f9b799309fd662ce66e001fd89e1e83eb1114257fba
7
- data.tar.gz: d9327ed183e0d9ade35f23633a70f01157b388cdb627de5890d63cfd151a0bf070ddf92313b92ca385f187b360b96fbaaa770b2dfc29cf9a28fc4ffdb45caa57
6
+ metadata.gz: e3ff8a744de37ca82b01bed3ebeff321c43fa442a923fe9c1a19da6affbc0a54e6bc6f0a9901b86b66b223fe55a7f8277d7594e740d040faa80bfb71cc64e215
7
+ data.tar.gz: b04df5871d0c527e4d86c3e560205da232b2b1fe48bfe23919c0b400d6888ed373e6b5fffa6a6da687b89620096ef09223e0a691ec1e1dd8c00a533223f124e6
@@ -15,6 +15,7 @@ module Jekyll
15
15
  NAME_KEY = "name"
16
16
  # names
17
17
  ## valid
18
+ TYPED_KEY = "typed"
18
19
  WEB_KEY = "web"
19
20
  WIKI_KEY = "wiki"
20
21
  ## invalid
@@ -31,26 +32,27 @@ module Jekyll
31
32
  def initialize(config)
32
33
  @config ||= config
33
34
  self.old_config_warn()
34
- 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?
35
36
  end
36
37
 
37
38
  # util
38
39
 
39
40
  def css_name(name_key)
40
41
  return option_css_name(name_key) if option_css_name(name_key)
42
+ return "typed" if name_key == TYPED_KEY
41
43
  # valid
42
- return "wiki-link" if name_key == WIKI_KEY
44
+ return "wiki-link" if name_key == WIKI_KEY
43
45
  # invalid
44
- return "invalid-wiki-link" if name_key == INV_WIKI_KEY
46
+ return "invalid-wiki-link" if name_key == INV_WIKI_KEY
45
47
  # return "invalid-web-link" if name_key == INV_WEB_KEY
46
48
  # embeds
47
- return "embed-wrapper" if name_key == EMBED_WRAPPER_KEY
48
- return "embed-title" if name_key == EMBED_TITLE_KEY
49
- return "embed-content" if name_key == EMBED_CONTENT_KEY
50
- 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
51
53
  # img
52
- return "embed-image-wrapper" if name_key == EMBED_IMG_WRAPPER_KEY
53
- 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
54
56
  end
55
57
 
56
58
  def disabled?
@@ -66,6 +68,10 @@ module Jekyll
66
68
  return option(EXCLUDE_KEY).include?(type.to_s)
67
69
  end
68
70
 
71
+ def excluded_css_names
72
+ return self.option_css(EXCLUDE_KEY)
73
+ end
74
+
69
75
  # options
70
76
 
71
77
  def option(key)
@@ -92,13 +98,13 @@ module Jekyll
92
98
 
93
99
  def old_config_warn()
94
100
  if @config.include?("wikilinks_collection")
95
- 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.")
96
102
  end
97
103
  if option_exist?("assets_rel_path")
98
- 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'.")
99
105
  end
100
106
  if @config.include?("d3_graph_data")
101
- 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.")
102
108
  end
103
109
  end
104
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.debug("No documents to process.")
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
- return nil if filename.nil? || @md_docs.size == 0
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
- return nil if url.nil? || @md_docs.size == 0
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
- 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
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
- return nil if filename.nil? || @static_files.size == 0 || !SUPPORTED_IMG_FORMATS.any?{ |ext| ext == File.extname(filename).downcase }
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
- def self.doc_has_header?(doc, header)
66
- return nil if header.nil?
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 self.doc_has_block_id?(doc, block_id)
74
- return nil if block_id.nil?
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)
@@ -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