sweetie 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -0
- data/Rakefile +8 -0
- data/lib/sweetie.rb +80 -80
- metadata +8 -6
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Sweetie is a plugin for [jekyll](https://github.com/mojombo/jekyll) to count all links, images, pages, and the last build time on a jekyll site. You can then use this information at a any place in your jekyll project.
|
2
|
+
|
3
|
+
|
4
|
+
## Configuration variables
|
5
|
+
To get the plugin working you must add `build`, `htmlpages`, `images`, and `links` in your `_config.yml` file. _sweetie_ will save the information to this variables. You can then use them everywhere in your page with the liquid snippet for example `{{ site.build }}`on all of your pages (of course you can use the other variables mentioned above).
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
Put the `sweetie.rb` file in the root of your jekyll project and then run the file to update your `_config.yml`file. To get the right calculated number of html pages, your pages must have the file ending *.html.
|
10
|
+
|
11
|
+
|
12
|
+
## Possible usage
|
13
|
+
Before you deploy your page, you can run the `sweetie.rb` in a rake task:
|
14
|
+
|
15
|
+
desc "deploy"
|
16
|
+
task :create_stati do
|
17
|
+
system("ruby sweetie.rb")
|
18
|
+
sh 'glynn'
|
19
|
+
end
|
20
|
+
|
data/Rakefile
ADDED
data/lib/sweetie.rb
CHANGED
@@ -2,95 +2,95 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
class Sweetie
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
@@config = "../_config.yml"
|
6
|
+
@@dir = "_site"
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
8
|
+
def self.change_config
|
9
|
+
file = File.open(@@config)
|
10
|
+
text = ""
|
11
|
+
while line = file.gets
|
12
|
+
if line.match(/build:/)
|
13
|
+
text << "build: #{build_time}\n"
|
14
|
+
elsif line.match(/htmlpages:/)
|
15
|
+
text << "htmlpages: #{count_html_pages(@@dir)}\n"
|
16
|
+
elsif line.match(/images:/)
|
17
|
+
text << "images: #{count_all_images(@@dir)}\n"
|
18
|
+
elsif line.match(/links:/)
|
19
|
+
text << "links: #{count_all_links(@@dir)}\n"
|
20
|
+
else
|
21
|
+
text << line
|
22
|
+
end
|
23
|
+
end
|
24
|
+
file.close
|
25
|
+
File.open(@@config, 'w') do |file|
|
26
|
+
file.puts text
|
27
|
+
file.close
|
28
|
+
end
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
def self.count_link_of_one_page(page)
|
32
|
+
links = []
|
33
|
+
links = harvest('//a', page, links, 'a')
|
34
|
+
output_count(links)
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
def self.count_images_of_one_page(page)
|
38
|
+
images = []
|
39
|
+
images = harvest('//img', page, images, 'img')
|
40
|
+
output_count(images)
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
def self.count_html_pages(dir)
|
44
|
+
pages = []
|
45
|
+
traverse('//html', pages, 'html', dir)
|
46
|
+
output_count(pages)
|
47
|
+
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
def self.count_all_links(dir)
|
50
|
+
links = []
|
51
|
+
traverse('//a', links, 'a', dir)
|
52
|
+
output_count(links)
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
def self.count_all_images(dir)
|
56
|
+
images = []
|
57
|
+
traverse('//img', images, 'img', dir)
|
58
|
+
output_count(images)
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
def self.build_time
|
62
|
+
time = Time.now
|
63
|
+
"#{time.month}-#{time.day}-#{time.year}"
|
64
|
+
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
66
|
+
def self.traverse(pattern, ar, type, dir)
|
67
|
+
Dir.glob(dir+"/**/*") do |file|
|
68
|
+
next if file == '.' or file == '..' or file.include?("html~")
|
69
|
+
if file.match(/(.*).html/)
|
70
|
+
harvest(pattern, file, ar, type)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
75
|
+
def self.harvest(pattern, html, ar, type)
|
76
|
+
file = File.open(html)
|
77
|
+
doc = Nokogiri::HTML(file)
|
78
|
+
doc.xpath(pattern).each do |node|
|
79
|
+
if type == "a"
|
80
|
+
ar << node.text
|
81
|
+
elsif type == "img" and ar.include?(node.to_s)
|
82
|
+
elsif type == "img"
|
83
|
+
ar << node.to_s
|
84
|
+
elsif type == "html"
|
85
|
+
ar << node
|
86
|
+
else
|
87
|
+
end
|
88
|
+
end
|
89
|
+
ar
|
90
|
+
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
def self.output_count(file)
|
93
|
+
file.uniq.count
|
94
|
+
end
|
95
95
|
end
|
96
96
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweetie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthias Guenther
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-05 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: nokogiri
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: 2.6.0
|
50
50
|
type: :development
|
51
51
|
version_requirements: *id002
|
52
|
-
description: Sweetie
|
52
|
+
description: Sweetie counts the links, images, number of html pages, and last-build time of a jekyll project.
|
53
53
|
email: matthias.guenther@wikimatze.de
|
54
54
|
executables:
|
55
55
|
- sweetie
|
@@ -59,6 +59,8 @@ extra_rdoc_files: []
|
|
59
59
|
|
60
60
|
files:
|
61
61
|
- lib/sweetie.rb
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
62
64
|
- bin/sweetie
|
63
65
|
homepage: http://github.com/matthias-guenther/sweetie
|
64
66
|
licenses: []
|
@@ -92,6 +94,6 @@ rubyforge_project:
|
|
92
94
|
rubygems_version: 1.8.5
|
93
95
|
signing_key:
|
94
96
|
specification_version: 3
|
95
|
-
summary: Count
|
97
|
+
summary: Count links, images, number of html pages, and last-build time of a jekyll project.
|
96
98
|
test_files: []
|
97
99
|
|