Class: Jekyll::WikiRefs::LinkIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-wikirefs/util/link_index.rb

Defined Under Namespace

Classes: DocLinks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ LinkIndex

Returns a new instance of LinkIndex.



9
10
11
12
13
14
15
# File 'lib/jekyll-wikirefs/util/link_index.rb', line 9

def initialize(site)
  @baseurl = site.baseurl
  @index = {}
  site.doc_mngr.all.each do |doc|
    @index[doc.url] = DocLinks.new()
  end
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



7
8
9
# File 'lib/jekyll-wikirefs/util/link_index.rb', line 7

def index
  @index
end

Instance Method Details

#assign_metadata(doc) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/jekyll-wikirefs/util/link_index.rb', line 17

def (doc)
  doc.data['attributed'] = @index[doc.url].attributed.uniq
  doc.data['attributes'] = @index[doc.url].attributes.uniq
  doc.data['backlinks']  = @index[doc.url].backlinks.uniq
  doc.data['forelinks']  = @index[doc.url].forelinks.uniq
  doc.data['missing']    = @index[doc.url].missing.uniq
end

#populate(doc, wikilink_blocks, wikilink_inlines) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/jekyll-wikirefs/util/link_index.rb', line 25

def populate(doc, wikilink_blocks, wikilink_inlines)
  #        #
  # blocks #
  #        #
  wikilink_blocks.each do |wlbl|
    if wlbl.is_valid?
      #
      # attributes
      #
      target_attr = @index[doc.url].attributes.detect { |atr| atr['type'] == wlbl.link_type }
      # create
      if target_attr.nil?
        @index[doc.url].attributes << wlbl.linked_fm_data
      # append
      else
        target_attr['urls'] += wlbl.urls 
      end
      ## append missing docs
      @index[doc.url].missing += wlbl.missing_doc_filenames 
      #
      # attributed
      #
      wlbl.linked_docs.each do |linked_doc|
        target_attr = @index[linked_doc.url].attributed.detect { |atr| atr['type'] == wlbl.link_type }
        # create
        if target_attr.nil?
          @index[linked_doc.url].attributed << wlbl.context_fm_data
        # append
        else
          target_attr['urls'] << doc.url
        end
      end
    else
      #
      # invalid || empty
      #
      @index[doc.url].missing += wlbl.missing_doc_filenames
    end
  end
  #         #
  # inlines #
  #         #
  wikilink_inlines.each do |wlil|
    return if wlil.is_img?
    if wlil.is_valid?
      # forelink
      @index[doc.url].forelinks << wlil.linked_fm_data
      # backlink
      @index[wlil.linked_doc.url].backlinks << wlil.context_fm_data
    else
      @index[doc.url].missing << wlil.filename
    end
  end
end