nesta-plugin-smartmeta 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +1 -0
- data/lib/nesta-plugin-smartmeta.rb +3 -0
- data/lib/nesta-plugin-smartmeta/init.rb +34 -0
- data/lib/nesta-plugin-smartmeta/version.rb +7 -0
- data/nesta-plugin-smartmeta.gemspec +23 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Joshua Mervine
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Nesta::Plugin::Smartmeta
|
2
|
+
|
3
|
+
This plugin generates a meta description and keywords if they're not specified.
|
4
|
+
|
5
|
+
* description: from a page or article summary if there is no description
|
6
|
+
* keywords: from page.categories and page.articles if no keywords are given
|
7
|
+
|
8
|
+
> WARNING: This has the potential to be slow. With my benchmarking it wasn't, but I don't have a great number of pages and articles. That said, if you do, you should use something like [httperf](http://www.rubyops.net/httperf) to benchmark your site before going live. If you do see a performance hit, using caching -- Nesta's default or something like my [nesta-plugin-diskcached](http://github.com/jmervine/nesta-plugin-diskcached) should help.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'nesta-plugin-smartmeta'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install nesta-plugin-smartmeta
|
23
|
+
|
24
|
+
Or from source via bundler:
|
25
|
+
|
26
|
+
$ echo "gem 'nesta-plugin-smartmeta', :git => 'https://github.com/jmervine/nesta-plugin-smartmeta.git'" >> Gemfile
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
This should work out of the box.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Nesta
|
2
|
+
module Plugin
|
3
|
+
module Smartmeta
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class FileModel
|
8
|
+
def description
|
9
|
+
metadata('description') || metadata('summary')
|
10
|
+
end
|
11
|
+
def keywords
|
12
|
+
metadata('keywords') || generated_keywords
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def generated_keywords
|
17
|
+
keywords = ""
|
18
|
+
keywords << keywords_from_pages(categories)
|
19
|
+
keywords << keywords_from_pages(articles)
|
20
|
+
(keywords.empty? ? nil : keywords)
|
21
|
+
end
|
22
|
+
|
23
|
+
def keywords_from_pages(pages)
|
24
|
+
unless pages.empty?
|
25
|
+
return pages.map do |page|
|
26
|
+
page.filename.split("/").last.split(".").first
|
27
|
+
end.map do |page|
|
28
|
+
page.split("-").join(" ")
|
29
|
+
end.join(", ")
|
30
|
+
end
|
31
|
+
return ""
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nesta-plugin-smartmeta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "nesta-plugin-smartmeta"
|
8
|
+
gem.version = Nesta::Plugin::Smartmeta::VERSION
|
9
|
+
gem.authors = ["Joshua Mervine"]
|
10
|
+
gem.email = ["joshua@mervine.net"]
|
11
|
+
gem.description = %q{
|
12
|
+
Generate http meta data from existing data, when not specified.
|
13
|
+
}
|
14
|
+
gem.summary = gem.description
|
15
|
+
gem.homepage = "https://github.com/jmervine/nesta-plugin-smartmeta"
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.add_dependency("nesta", ">= 0.9.11")
|
22
|
+
gem.add_development_dependency("rake")
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nesta-plugin-smartmeta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Mervine
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nesta
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.9.11
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.11
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! " \n Generate http meta data from existing data, when not specified.
|
47
|
+
\n "
|
48
|
+
email:
|
49
|
+
- joshua@mervine.net
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/nesta-plugin-smartmeta.rb
|
60
|
+
- lib/nesta-plugin-smartmeta/init.rb
|
61
|
+
- lib/nesta-plugin-smartmeta/version.rb
|
62
|
+
- nesta-plugin-smartmeta.gemspec
|
63
|
+
homepage: https://github.com/jmervine/nesta-plugin-smartmeta
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Generate http meta data from existing data, when not specified.
|
87
|
+
test_files: []
|