middleman-autometatags 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a40ca721323d03892e8887bd929f27b649afef70
4
+ data.tar.gz: 68f0fff51124c4eec0bdc0e1e7946139c118a59b
5
+ SHA512:
6
+ metadata.gz: 7e1660656f05fdf15d09c5e47a30176fe0d777310e188c144388a9fe0827b3a26428aa016f4873cb909f919e2f7aa6322e508fcb53570614a18ea05cb7c08635
7
+ data.tar.gz: 96897941f5002c8aa7b715ab021f116bd771958d7a4000742f3defb0d2d117fa8b0b5152e3bed9ce370810296cce4ab1195cfffc89521617031f9340e20ede84
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-autometatags.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Will Schenk
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,111 @@
1
+ # Middleman::Autometatags
2
+
3
+ This is a middleman extension that helps manage metatags. It will make guesses pages on the page metadata and data/site.yml to set things correctly.
4
+
5
+ SEO gem for your Middleman apps.
6
+
7
+ Based on [meta-tags](https://github.com/kpumuk/meta-tags) Rails gem and the [middleman-meta-tags](https://github.com/tiste/middleman-meta-tags) middleman extension.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your middleman's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'middleman-autometatags'
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ### Configuration
21
+
22
+ Edit `config.rb` and add:
23
+
24
+ ```rb
25
+ activate :autometatags
26
+ ```
27
+
28
+ ### Create data/site.yml
29
+
30
+ This will look inside of data/site.yml file to find any site wide defaults.
31
+
32
+ For example
33
+
34
+ ```yml
35
+ title: "Will Schenk"
36
+ twitter_author: "@wschenk"
37
+ ```
38
+
39
+ ### Title
40
+
41
+ ```rb
42
+ set_meta_tags title: 'Relevant title'
43
+ title 'Relevant title'
44
+ ```
45
+
46
+ ### Description
47
+
48
+ ```rb
49
+ set_meta_tags description: 'Powerful website full of best practices and keywords'
50
+ description 'Powerful website full of best practices and keywords'
51
+ ```
52
+
53
+ ### Keywords
54
+
55
+ ```rb
56
+ set_meta_tags keywords: %w(some seo keywords).join(', ')
57
+ keywords %w(some seo keywords).join(', ')
58
+ ```
59
+
60
+ ## Display meta tags
61
+
62
+ Into your `<head></head>` tag:
63
+
64
+ ```rb
65
+ auto_display_meta_tags
66
+ ```
67
+
68
+ By default, there is a `|` as separator between title and website name.
69
+
70
+ You can modify it by adding: `separator: '&raquo;'`
71
+
72
+ ## Autotagging
73
+
74
+ This will look inside of data/site.yml file to find any site wide defaults.
75
+ Then it looks the page meta data to attempt to display the following keys:
76
+
77
+ - MM `title` => META `site`
78
+ - MM `description` => META `description`
79
+ - MM `title` => `og:site_name`
80
+ - MM `twitter_card` (defaults to `summary_large_image`) => META `twitter:card`
81
+ - MM `title` => META `twitter:title`
82
+ - MM `publisher_twitter` => META `twitter:site`
83
+ - MM `twitter_author` => META `twitter:creator`
84
+ - MM `description` => META `twitter:description`
85
+ - MM `pull_image` => META `twitter:image:src`
86
+ - MM `title` => META `og:title`
87
+ - MM `description` => META `og:description`
88
+ - MM `pull_image` => META `og:image`
89
+
90
+ ### Manually adding addition tags
91
+
92
+ Create a helper method inside of your config.rb, like so
93
+
94
+ ```rb
95
+ helper do
96
+ def my_tags
97
+ set_meta_tags key => value
98
+ end
99
+ end
100
+ ```
101
+
102
+ And add it to the layouts and views that you need.
103
+
104
+
105
+ ## Contributing
106
+
107
+ 1. [Fork it](http://github.com/tiste/middleman-meta-tags/fork)
108
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
109
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
110
+ 4. Push to the branch (`git push origin my-new-feature`)
111
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require 'middleman-core'
2
+
3
+ ::Middleman::Extensions.register(:autometatags) do
4
+ require 'middleman-autometatags/extension'
5
+ ::Middleman::Autometatags
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'middleman-autometatags/helpers'
2
+
3
+ module Middleman
4
+ module Autometatags
5
+ class << self
6
+ def registered(app, options_hash = {}, &block)
7
+ app.helpers Middleman::Autometatags::Helpers
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,110 @@
1
+ module Middleman
2
+ module Autometatags
3
+ module Helpers
4
+ def meta_tags
5
+ @meta_tags ||= {}
6
+ end
7
+
8
+ def set_meta_tags(meta_tags = {})
9
+ self.meta_tags.merge! meta_tags
10
+ end
11
+
12
+ def description(description = nil)
13
+ set_meta_tags(description: description) unless description.nil?
14
+ end
15
+
16
+ def keywords(keywords = nil)
17
+ set_meta_tags(keywords: keywords) unless keywords.nil?
18
+ end
19
+
20
+ def title(title = nil)
21
+ set_meta_tags(title: title) unless title.nil?
22
+ end
23
+
24
+ def display_meta_tags(default = {})
25
+ result = []
26
+ meta_tags = default.merge(self.meta_tags)
27
+
28
+ title = full_title(meta_tags)
29
+ result << content_tag(:title, title) unless title.blank?
30
+
31
+ description = safe_description(meta_tags.delete(:description))
32
+ result << tag(:meta, name: :description, content: description) unless description.blank?
33
+
34
+ keywords = meta_tags.delete(:keywords)
35
+ result << tag(:meta, name: :keywords, content: keywords) unless keywords.blank?
36
+
37
+ meta_tags.each do |name,content|
38
+ result << tag(:meta, name: name, content: content ) unless content.blank?
39
+ end
40
+
41
+ result = result.join("\n")
42
+ result.html_safe
43
+ end
44
+
45
+ # This looks at page data, and data['site'] to set tags that we
46
+ # may know about. The autotag method sets up the information
47
+ # and then the tags are generated.
48
+
49
+ def auto_display_meta_tags(default = {})
50
+ auto_tag
51
+
52
+ display_meta_tags( default )
53
+ end
54
+
55
+ # This looks at page data, and data['site'] to set tags that we
56
+ # may know about
57
+ def auto_tag
58
+ site_data = data['site'] || {}
59
+
60
+
61
+ set_meta_tags :site => site_data['title']
62
+ set_meta_tags "og:site_name" => site_data['title']
63
+
64
+ fall_through( site_data, :title, "title" )
65
+ fall_through( site_data, :description, "description" )
66
+
67
+ # Twitter cards
68
+ fall_through( site_data, "twitter:card", "twitter_card", "summary_large_image" )
69
+ fall_through( site_data, "twitter:title", "title" )
70
+ fall_through( site_data, "twitter:site", "publisher_twitter" )
71
+ fall_through( site_data, "twitter:creator", "twitter_author" )
72
+ fall_through( site_data, "twitter:description", "description" )
73
+ fall_through( site_data, "twitter:image:src", "pull_image" )
74
+
75
+ # Open Graph
76
+ fall_through( site_data, "og:title", "title" )
77
+ fall_through( site_data, "og:description", "description" )
78
+ fall_through( site_data, "og:image", "pull_image" )
79
+ end
80
+
81
+
82
+ private
83
+
84
+ def full_title(meta_tags)
85
+ separator = meta_tags[:separator] || '|'
86
+ full_title = ''
87
+ title = safe_title(meta_tags[:title])
88
+
89
+ (full_title << title) unless title.blank?
90
+ (full_title << " #{separator} ") unless title.blank? || meta_tags[:site].blank?
91
+ (full_title << meta_tags[:site]) unless meta_tags[:site].blank?
92
+ full_title
93
+ end
94
+
95
+ def safe_description(description)
96
+ truncate(strip_tags(description), length: 200)
97
+ end
98
+
99
+ def safe_title(title)
100
+ title = strip_tags(title)
101
+ end
102
+
103
+ def fall_through( site_data, name, key, default = nil )
104
+ value = current_page.data[key] || site_data[key] || default
105
+ set_meta_tags name => value unless value.blank?
106
+ value
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Autometatags
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-autometatags/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-autometatags"
8
+ spec.version = Middleman::Autometatags::VERSION
9
+ spec.authors = ["Will Schenk"]
10
+ spec.email = ["wschenk@gmail.com"]
11
+ spec.summary = %q{A middleman extension inspired by the metatag gem that helps manage metatags.}
12
+ spec.description = %q{A middleman extension inspired by the metatag gem that helps manage metatags.}
13
+ spec.homepage = "https://github.com/HappyFunCorp/middleman-autometatags"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'middleman-core', ['>= 3.0.0']
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-autometatags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Will Schenk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: A middleman extension inspired by the metatag gem that helps manage metatags.
56
+ email:
57
+ - wschenk@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/middleman-autometatags.rb
68
+ - lib/middleman-autometatags/extension.rb
69
+ - lib/middleman-autometatags/helpers.rb
70
+ - lib/middleman-autometatags/version.rb
71
+ - middleman-autometatags.gemspec
72
+ homepage: https://github.com/HappyFunCorp/middleman-autometatags
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A middleman extension inspired by the metatag gem that helps manage metatags.
96
+ test_files: []