sitemap_gen 0.1.3 → 0.1.4
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 +4 -4
- data/lib/sitemap_gen/version.rb +1 -1
- data/lib/sitemap_gen.rb +0 -69
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022d4c1ad13e6d780fc33e75a83a9bf240a29adc
|
4
|
+
data.tar.gz: 99451c4b69ced7bf9a0937a28070af58e41df52a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8609581a2030771ce3ace6aaba8df58a8706c1e070e1affded32043b90849ec376b297931f9ab1e1988041126c2efd0ab6ef440f7a047438eeaf9fa223d82add
|
7
|
+
data.tar.gz: 65381777ac0d4c165c0a2d8d7f9ae9fcf5e5b59ec105de87406e9b254457dd20aa9f1586e62fd814a2eef629b39ab6ca8499c634328d275cd898f78492f3b9d2
|
data/lib/sitemap_gen/version.rb
CHANGED
data/lib/sitemap_gen.rb
CHANGED
@@ -1,78 +1,9 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'csv'
|
3
|
-
require 'benchmark'
|
4
3
|
require 'sitemap_gen/csv'
|
5
4
|
|
6
5
|
module SitemapGen
|
7
6
|
def self.run(dir_path, base_url, save_path = nil)
|
8
7
|
SitemapGen::Csv.new(dir_path, base_url, save_path).generate
|
9
8
|
end
|
10
|
-
#class << self
|
11
|
-
#def run(dir_path, base_url, save_path = nil)
|
12
|
-
#p Benchmark.measure { generate_csv(csv_data(dir_path, base_url), save_path) }
|
13
|
-
#end
|
14
|
-
|
15
|
-
#def generate_csv(data, save_path)
|
16
|
-
#lheaders = level_headers(data)
|
17
|
-
#save_path ||= Dir.pwd
|
18
|
-
#CSV.open("#{save_path}/sitemap.csv", 'wb') do |csv|
|
19
|
-
#csv << ['id'].concat(lheaders).push('url')
|
20
|
-
#data.each_with_index do |row, i|
|
21
|
-
#gap = lheaders.length - row[:levels].values.length
|
22
|
-
#csv << [i + 1].concat(row[:levels].values).concat(Array.new(gap) { '' }).push(row[:url])
|
23
|
-
#end
|
24
|
-
#end
|
25
|
-
#end
|
26
|
-
|
27
|
-
#def level_headers(data)
|
28
|
-
#data.each_with_object([]) { |item, o| o << item[:levels] }
|
29
|
-
#.inject([]) { |max, row| max.size < row.keys.size ? row.keys : max }
|
30
|
-
#end
|
31
|
-
|
32
|
-
#def csv_data(dir_path, base_url)
|
33
|
-
## Raise error if there is no html files
|
34
|
-
#html_files = Dir.glob("#{dir_path}/**/index.html")
|
35
|
-
#raise 'There is no html files in your directory' if html_files.empty?
|
36
|
-
|
37
|
-
#data = []
|
38
|
-
#html_files.each_with_index do |file_path, i|
|
39
|
-
#next if file_path =~ IGNORE_DIRS_REGEX
|
40
|
-
#page_path = file_path.sub(dir_path, '')
|
41
|
-
#base_path = File.dirname(page_path)
|
42
|
-
#last_slash = base_path == '/' ? '' : '/'
|
43
|
-
#short_page_path = page_path.split('/')[0..-2].join('/')
|
44
|
-
#data.push({ url: base_url + base_path + last_slash, page_path: short_page_path == '' ? '/' : short_page_path }
|
45
|
-
#.merge({ levels: dir_levels(dir_path, page_path) }))
|
46
|
-
#end
|
47
|
-
#organized_data(dir_path, data)
|
48
|
-
#end
|
49
|
-
|
50
|
-
#def page_title(file_path)
|
51
|
-
#html_doc = Nokogiri::HTML(File.read(file_path))
|
52
|
-
#html_doc.css('head title').first.content
|
53
|
-
#end
|
54
|
-
|
55
|
-
#def dir_levels(dir_path, page_path)
|
56
|
-
#levels = {}
|
57
|
-
#order = 0
|
58
|
-
#page_path.split('/')[1..-2].each_with_index do |dir, i|
|
59
|
-
#order = i + 1
|
60
|
-
#levels.merge!({"level_#{order}": ''})
|
61
|
-
#end
|
62
|
-
#html_file = Dir.glob("#{dir_path}#{page_path}").first
|
63
|
-
#levels.merge!({"level_#{order + 1}": page_title(html_file)})
|
64
|
-
#levels
|
65
|
-
#end
|
66
|
-
|
67
|
-
#def organized_data(dir_path, data)
|
68
|
-
#top_level_dirs = Dir.glob("#{dir_path}/**/index.html").map { |path| File.dirname(path).sub(dir_path, '').split('/')[0..-1].join('/') }.uniq
|
69
|
-
#organized_data = []
|
70
|
-
#organized_data.concat data.select { |d| d[:page_path] == '/' }
|
71
|
-
#top_level_dirs.each do |dir|
|
72
|
-
## We group data by page path and then order by alphabet
|
73
|
-
#organized_data.concat(data.select { |d| d[:page_path] =~ /\A#{Regexp.quote(dir)}\z/ }.sort_by { |d| d[:page_path] })
|
74
|
-
#end
|
75
|
-
#organized_data
|
76
|
-
#end
|
77
|
-
#end
|
78
9
|
end
|