Module: GithubPages::JsonRakeExt

Included in:
DeployTask
Defined in:
lib/ghpages_deploy/rake/json.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.directory_sitemap(dir, excluded) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ghpages_deploy/rake/json.rb', line 39

def self.directory_sitemap(dir, excluded)
  mapping =
    Dir.foreach(dir).flat_map do |file|
      file_dir = File.join(dir, file)
      next [] if excluded.include?(file_dir)
      next [] if %w(.git . ..).include?(file)
      next [] unless Dir.exist?(file_dir)

      index =
        %w(index.html _index.html).find do |html|
          File.exist?(File.join(file_dir, html))
        end

      next [File.basename(file_dir), index] if index

      map = directory_sitemap(file_dir, excluded)
      next [] if !map || map.empty?
      map
    end

  return nil if mapping.empty?
  [File.basename(dir), Hash[*mapping]]
end

.update_sitemap(excluded) ⇒ Object

if update_sitemap is being called, excluded directories should be relative to ‘./’



31
32
33
34
35
36
37
# File 'lib/ghpages_deploy/rake/json.rb', line 31

def self.update_sitemap(excluded)
  mapping = directory_sitemap('.', excluded).last

  File.open('sitemap.json', 'w+') do |file|
    file.write mapping.to_json
  end
end

Instance Method Details

#json_sitemap(excluded = []) ⇒ Object



63
64
65
66
67
68
# File 'lib/ghpages_deploy/rake/json.rb', line 63

def json_sitemap(excluded = [])
  handler.handle_deploy do
    JsonRakeExt.update_sitemap(excluded)
    ['sitemap.json']
  end
end