Class: Jekyll::SiteTreeGenerator

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-site-tree.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll-site-tree.rb', line 6

def generate(site)
    @site = site

    unless site_tree_file
        Jekyll.logger.warn("SiteTree:", "skipped because no 'site-tree' file specified in config")
        return
    end

    page = @site.pages.find { |page| page.dir.slice(1, page.dir.length) + page.name == site_tree_file }

    if page.nil?
        Jekyll.logger.error("SiteTree:", "unable to find 'site-tree' file: " + site_tree_file)
        return
    end

    Jekyll.logger.info("SiteTree:", "building site tree")
    # page.data['site_tree_permalinks'] = permalinks
    page.data['site_tree']            = site_tree
end


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll-site-tree.rb', line 26

def permalinks
    pages  = @site.pages
    pages += @site.static_files
    pages += @site.collections.map do |tuple|
        name, collection = tuple
        (collection.write?) ? collection.docs : []
    end.flatten

    pages.map { |pg| pg.url }.select do |page|
        !excludes.any? { |rx| rx.match? page }
    end.uniq.sort(&NaturalSort)
end

#recursive_construct_tree(name, tree) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jekyll-site-tree.rb', line 111

def recursive_construct_tree(name, tree)
    result = '<li>'

    current_path = tree.delete(:path)
    current_link = tree.delete(:link)

    if current_path
        result += "<a href=\"%s\">%s</a>" % [
            current_link, name].map { |s| html_coder.encode(s) }
    end

    unless tree.empty?
        if tree.length == 1 && !current_path then
            child_name = tree.keys[0]

            return recursive_construct_tree(
                name + '/' + child_name, tree[child_name])
        else
            result += html_coder.encode(name) if !current_path

            result += '<ul>'
            tree.each do |name, subtree|
                result += recursive_construct_tree(name, subtree)
            end
            result += '</ul>'
        end
    end

    result += '</li>'
end