jekyll-soopr-seo-tag 2.7.3
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 +7 -0
- data/.github/workflows/actions/memprof.rb +14 -0
- data/.github/workflows/third-party.yml +61 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +13 -0
- data/.travis.yml +18 -0
- data/Gemfile +8 -0
- data/History.markdown +202 -0
- data/LICENSE.txt +21 -0
- data/docs/README.md +34 -0
- data/docs/_config.yml +10 -0
- data/docs/_layouts/default.html +18 -0
- data/docs/advanced-usage.md +156 -0
- data/docs/installation.md +24 -0
- data/docs/usage.md +80 -0
- data/jekyll-soopr-seo-tag.gemspec +34 -0
- data/lib/jekyll-seo-tag/author_drop.rb +93 -0
- data/lib/jekyll-seo-tag/drop.rb +252 -0
- data/lib/jekyll-seo-tag/filters.rb +14 -0
- data/lib/jekyll-seo-tag/image_drop.rb +78 -0
- data/lib/jekyll-seo-tag/json_ld.rb +31 -0
- data/lib/jekyll-seo-tag/json_ld_drop.rb +95 -0
- data/lib/jekyll-seo-tag/soopr_drop.rb +54 -0
- data/lib/jekyll-seo-tag/url_helper.rb +23 -0
- data/lib/jekyll-seo-tag/version.rb +10 -0
- data/lib/jekyll-soopr-seo-tag.rb +96 -0
- data/lib/template.html +125 -0
- data/script/bootstrap +5 -0
- data/script/cibuild +7 -0
- data/script/release +38 -0
- data/script/site +3 -0
- metadata +153 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
## Advanced usage
|
2
|
+
|
3
|
+
Jekyll SEO Tag is designed to implement SEO best practices by default and to be the right fit for most sites right out of the box. If for some reason, you need more control over the output, read on:
|
4
|
+
|
5
|
+
### Disabling `<title>` output
|
6
|
+
|
7
|
+
If for some reason, you don't want the plugin to output `<title>` tags on each page, simply invoke the plugin within your template like so:
|
8
|
+
|
9
|
+
<!-- {% raw %} -->
|
10
|
+
```
|
11
|
+
{% seo title=false %}
|
12
|
+
```
|
13
|
+
<!-- {% endraw %} -->
|
14
|
+
|
15
|
+
### Author information
|
16
|
+
|
17
|
+
Author information is used to propagate the `creator` field of Twitter summary cards. This should be an author-specific, not site-wide Twitter handle (the site-wide username be stored as `site.twitter.username`).
|
18
|
+
|
19
|
+
*TL;DR: In most cases, put `author: [your Twitter handle]` in the document's front matter, for sites with multiple authors. If you need something more complicated, read on.*
|
20
|
+
|
21
|
+
There are several ways to convey this author-specific information. Author information is found in the following order of priority:
|
22
|
+
|
23
|
+
1. An `author` object, in the documents's front matter, e.g.:
|
24
|
+
|
25
|
+
```yml
|
26
|
+
author:
|
27
|
+
twitter: benbalter
|
28
|
+
```
|
29
|
+
|
30
|
+
2. An `author` object, in the site's `_config.yml`, e.g.:
|
31
|
+
|
32
|
+
```yml
|
33
|
+
author:
|
34
|
+
twitter: benbalter
|
35
|
+
```
|
36
|
+
|
37
|
+
3. `site.data.authors[author]`, if an author is specified in the document's front matter, and a corresponding key exists in `site.data.authors`. E.g., you have the following in the document's front matter:
|
38
|
+
|
39
|
+
```yml
|
40
|
+
author: benbalter
|
41
|
+
```
|
42
|
+
|
43
|
+
And you have the following in `_data/authors.yml`:
|
44
|
+
|
45
|
+
```yml
|
46
|
+
benbalter:
|
47
|
+
picture: /img/benbalter.png
|
48
|
+
twitter: jekyllrb
|
49
|
+
|
50
|
+
potus:
|
51
|
+
picture: /img/potus.png
|
52
|
+
twitter: whitehouse
|
53
|
+
```
|
54
|
+
|
55
|
+
In the above example, the author `benbalter`'s Twitter handle will be resolved to `@jekyllrb`. This allows you to centralize author information in a single `_data/authors` file for site with many authors that require more than just the author's username.
|
56
|
+
|
57
|
+
*Pro-tip: If `authors` is present in the document's front matter as an array (and `author` is not), the plugin will use the first author listed, as Twitter supports only one author.*
|
58
|
+
|
59
|
+
4. An author in the document's front matter (the simplest way), e.g.:
|
60
|
+
|
61
|
+
```yml
|
62
|
+
author: benbalter
|
63
|
+
```
|
64
|
+
|
65
|
+
5. An author in the site's `_config.yml`, e.g.:
|
66
|
+
|
67
|
+
```yml
|
68
|
+
author: benbalter
|
69
|
+
```
|
70
|
+
|
71
|
+
### Customizing JSON-LD output
|
72
|
+
|
73
|
+
The following options can be set for any particular page. While the default options are meant to serve most users in the most common circumstances, there may be situations where more precise control is necessary.
|
74
|
+
|
75
|
+
* `seo`
|
76
|
+
* `name` - If the name of the thing that the page represents is different from the page title. (i.e.: "Frank's Café" vs "Welcome to Frank's Café")
|
77
|
+
* `type` - The type of things that the page represents. This must be a [Schema.org type](https://schema.org/docs/schemas.html), and will probably usually be something like [`BlogPosting`](https://schema.org/BlogPosting), [`NewsArticle`](https://schema.org/NewsArticle), [`Person`](https://schema.org/Person), [`Organization`](https://schema.org/Organization), etc.
|
78
|
+
* `links` - An array of other URLs that represent the same thing that this page represents. For instance, Jane's bio page might include links to Jane's GitHub and Twitter profiles.
|
79
|
+
* `date_modified` - Manually specify the `dateModified` field in the JSON-LD output to override Jekyll's own `dateModified`.
|
80
|
+
This field will take **first priority** for the `dateModified` JSON-LD output. This is useful when the file timestamp does not match the true time that the content was modified. A user may also install [Last Modified At](https://github.com/gjtorikian/jekyll-last-modified-at) which will offer an alternative way of providing for the `dateModified` field.
|
81
|
+
|
82
|
+
### Customizing image output
|
83
|
+
|
84
|
+
For most users, setting `image: [path-to-image]` on a per-page basis should be enough. If you need more control over how images are represented, the `image` property can also be an object, with the following options:
|
85
|
+
|
86
|
+
* `path` - The relative path to the image. Same as `image: [path-to-image]`
|
87
|
+
* `height` - The height of the Open Graph (`og:image`) image
|
88
|
+
* `width` - The width of the Open Graph (`og:image`) image
|
89
|
+
|
90
|
+
You can use any of the above, optional properties, like so:
|
91
|
+
|
92
|
+
```yml
|
93
|
+
image:
|
94
|
+
path: /img/twitter.png
|
95
|
+
height: 100
|
96
|
+
width: 100
|
97
|
+
```
|
98
|
+
|
99
|
+
### Setting a default image
|
100
|
+
|
101
|
+
You can define a default image using [Front Matter defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/), to provide a default Twitter Card or OGP image to all of your posts and pages.
|
102
|
+
|
103
|
+
Here is a very basic example, that you are encouraged to adapt to your needs:
|
104
|
+
|
105
|
+
```yml
|
106
|
+
defaults:
|
107
|
+
- scope:
|
108
|
+
path: ""
|
109
|
+
values:
|
110
|
+
image: /assets/images/default-card.png
|
111
|
+
```
|
112
|
+
|
113
|
+
### SmartyPants Titles
|
114
|
+
|
115
|
+
Titles will be processed using [Jekyll's `smartify` filter](https://jekyllrb.com/docs/liquid/filters/). This will use SmartyPants to translate plain ASCII punctuation into "smart" typographic punctuation. This will not render or strip any Markdown you may be using in a page title.
|
116
|
+
|
117
|
+
### Setting customized Canonical URL
|
118
|
+
|
119
|
+
You can set custom Canonical URL for a page by specifying canonical_url option in page front matter.
|
120
|
+
E.g., you have the following in the page's front matter:
|
121
|
+
```yml
|
122
|
+
layout: post
|
123
|
+
title: Title of Your Post
|
124
|
+
canonical_url: 'https://github.com/jekyll/jekyll-seo-tag/'
|
125
|
+
```
|
126
|
+
|
127
|
+
Which will generate canonical_url with specified link in canonical_url.
|
128
|
+
```html
|
129
|
+
<link rel="canonical" href="https://github.com/jekyll/jekyll-seo-tag/" />
|
130
|
+
```
|
131
|
+
|
132
|
+
If no canonical_url option was specified, then uses page url for generating canonical_url.
|
133
|
+
E.g., you have not specified canonical_url in front matter:
|
134
|
+
```yml
|
135
|
+
layout: post
|
136
|
+
title: Title of Your Post
|
137
|
+
```
|
138
|
+
|
139
|
+
Which will generate following canonical_url:
|
140
|
+
```html
|
141
|
+
<link rel="canonical" href="https://example.com/title-of-your-post" />
|
142
|
+
```
|
143
|
+
|
144
|
+
### Customizing title modifier for paginated pages
|
145
|
+
|
146
|
+
You can override the default title modifier for paginated pages from `Page %{current} of %{total} for ` to a string of your
|
147
|
+
choice by setting a `seo_paginator_message` key in your `_config.yml`.
|
148
|
+
|
149
|
+
For example:
|
150
|
+
|
151
|
+
```yml
|
152
|
+
seo_paginator_message: "%<current>s / %<total>s | "
|
153
|
+
```
|
154
|
+
|
155
|
+
While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total`
|
156
|
+
similar to the example above, to incorporate the current page-number and total number of paginated pages in the title.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Installing Jekyll SEO Tag
|
2
|
+
|
3
|
+
1. Add the following to your site's `Gemfile`:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
gem 'jekyll-seo-tag'
|
7
|
+
```
|
8
|
+
|
9
|
+
2. Add the following to your site's `_config.yml`:
|
10
|
+
|
11
|
+
```yml
|
12
|
+
plugins:
|
13
|
+
- jekyll-seo-tag
|
14
|
+
```
|
15
|
+
|
16
|
+
If you are using a Jekyll version less than `3.5.0`, use the `gems` key instead of `plugins`.
|
17
|
+
|
18
|
+
3. Add the following right before `</head>` in your site's template(s):
|
19
|
+
|
20
|
+
<!-- {% raw %} -->
|
21
|
+
```liquid
|
22
|
+
{% seo %}
|
23
|
+
```
|
24
|
+
<!-- {% endraw %} -->
|
data/docs/usage.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
## Usage
|
2
|
+
|
3
|
+
The SEO tag will respect any of the following if included in your site's `_config.yml` (and simply not include them if
|
4
|
+
they're not defined):
|
5
|
+
|
6
|
+
* `title` - Your site's title (e.g., *Ben's Awesome Site*, *The GitHub Blog*, etc.), used as part of the title tag like
|
7
|
+
`Home | Ben's Awesome Site`.
|
8
|
+
* `tagline` - A short description (e.g., *A blog dedicated to reviewing cat gifs*), used as part of the title tag like
|
9
|
+
`Ben's Awesome Site | A blog dedicated to reviewing cat gifs` instead of `Ben's Awesome Site | Long description about a
|
10
|
+
blog dedicated to reviewing cat gifs` that would be used when `page.title` is not defined.
|
11
|
+
* `description` - A longer description used for the description meta tag. Also used as fallback for pages that don't
|
12
|
+
provide their own `description`, and also as part of the page's title tag if neither `page.title` nor `site.tagline`
|
13
|
+
has been defined.
|
14
|
+
* `url` - The full URL to your site. Note: `site.github.url` will be used by default.
|
15
|
+
* `author` - global author information (see [Advanced usage](advanced-usage.md#author-information))
|
16
|
+
* `twitter` - The following properties are available:
|
17
|
+
* `twitter:card` - The site's default card type
|
18
|
+
* `twitter:username` - The site's Twitter handle.
|
19
|
+
|
20
|
+
You'll want to describe them like so:
|
21
|
+
|
22
|
+
```yml
|
23
|
+
twitter:
|
24
|
+
username: benbalter
|
25
|
+
card: summary
|
26
|
+
```
|
27
|
+
* `facebook` - The following properties are available:
|
28
|
+
* `facebook:app_id` - a Facebook app ID for Facebook insights
|
29
|
+
* `facebook:publisher` - a Facebook page URL or ID of the publishing entity
|
30
|
+
* `facebook:admins` - a Facebook user ID for domain insights linked to a personal account
|
31
|
+
|
32
|
+
You'll want to describe one or more like so:
|
33
|
+
|
34
|
+
```yml
|
35
|
+
facebook:
|
36
|
+
app_id: 1234
|
37
|
+
publisher: 1234
|
38
|
+
admins: 1234
|
39
|
+
```
|
40
|
+
* `logo` - URL to a site-wide logo (e.g., `/assets/your-company-logo.png`) - If you would like the "publisher" property
|
41
|
+
to be present, you must add this field to your site's configuration, during the validation of the structured data by
|
42
|
+
Google Search Console, if the `logo` field is not validated, you will find errors inherent to the publisher in the
|
43
|
+
[Rich Results Testing Tool](https://search.google.com/test/rich-results)
|
44
|
+
* `social` - For [specifying social profiles](https://developers.google.com/search/docs/guides/enhance-site#add-your-sites-name-logo-and-social-links).
|
45
|
+
The following properties are available:
|
46
|
+
* `name` - If the user or organization name differs from the site's name
|
47
|
+
* `links` - An array of links to social media profiles.
|
48
|
+
|
49
|
+
```yml
|
50
|
+
social:
|
51
|
+
name: Ben Balter
|
52
|
+
links:
|
53
|
+
- https://twitter.com/BenBalter
|
54
|
+
- https://www.facebook.com/ben.balter
|
55
|
+
- https://www.linkedin.com/in/BenBalter
|
56
|
+
- https://github.com/benbalter
|
57
|
+
- https://keybase.io/benbalter
|
58
|
+
```
|
59
|
+
* `google_site_verification` for verifying ownership via Google Search Console
|
60
|
+
* Alternatively, verify ownership with several services at once using the following format:
|
61
|
+
```yml
|
62
|
+
webmaster_verifications:
|
63
|
+
google: 1234
|
64
|
+
bing: 1234
|
65
|
+
alexa: 1234
|
66
|
+
yandex: 1234
|
67
|
+
baidu: 1234
|
68
|
+
```
|
69
|
+
* `locale` - The locale these tags are marked up in. Of the format `language_TERRITORY`. Default is `en_US`. Takes priority
|
70
|
+
over existing config key `lang`.
|
71
|
+
|
72
|
+
The SEO tag will respect the following YAML front matter if included in a post, page, or document:
|
73
|
+
|
74
|
+
* `title` - The title of the post, page, or document
|
75
|
+
* `description` - A short description of the page's content
|
76
|
+
* `image` - URL to an image associated with the post, page, or document (e.g., `/assets/page-pic.jpg`)
|
77
|
+
* `author` - Page-, post-, or document-specific author information (see [Advanced usage](advanced-usage.md#author-information))
|
78
|
+
* `locale` - Page-, post-, or document-specific locale information. Takes priority over existing front matter attribute `lang`.
|
79
|
+
|
80
|
+
*Note:* Front matter defaults can be used for any of the above values as described in advanced usage with an image example.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jekyll-seo-tag/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-soopr-seo-tag"
|
7
|
+
spec.version = Jekyll::SeoTag::VERSION
|
8
|
+
spec.authors = ["Ben Balter"]
|
9
|
+
spec.email = ["ben.balter@github.com"]
|
10
|
+
spec.summary = "A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content."
|
11
|
+
spec.homepage = "https://github.com/abhinavs/jekyll-soopr-seo-tag"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
15
|
+
# delete this section to allow pushing this gem to any host.
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
else
|
19
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.required_ruby_version = ">= 2.4.0"
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|spec|features)/!) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r!^exe/!) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "jekyll", ">= 3.8", "< 5.0"
|
30
|
+
spec.add_development_dependency "bundler", ">= 1.15"
|
31
|
+
spec.add_development_dependency "html-proofer", "~> 3.7"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
33
|
+
spec.add_development_dependency "rubocop-jekyll", "~> 0.11"
|
34
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class SeoTag
|
5
|
+
# A drop representing the current page's author
|
6
|
+
#
|
7
|
+
# Author name will be pulled from:
|
8
|
+
#
|
9
|
+
# 1. The page's `author` key
|
10
|
+
# 2. The first author in the page's `authors` key
|
11
|
+
# 3. The `author` key in the site config
|
12
|
+
#
|
13
|
+
# If the result from the name search is a string, we'll also check
|
14
|
+
# for additional author metadata in `site.data.authors`
|
15
|
+
class AuthorDrop < Jekyll::Drops::Drop
|
16
|
+
# Initialize a new AuthorDrop
|
17
|
+
#
|
18
|
+
# page - The page hash (e.g., Page#to_liquid)
|
19
|
+
# site - The Jekyll::Drops::SiteDrop
|
20
|
+
def initialize(page: nil, site: nil)
|
21
|
+
raise ArgumentError unless page && site
|
22
|
+
|
23
|
+
@mutations = {}
|
24
|
+
@page = page
|
25
|
+
@site = site
|
26
|
+
end
|
27
|
+
|
28
|
+
# AuthorDrop#to_s should return name, allowing the author drop to safely
|
29
|
+
# replace `page.author`, if necessary, and remain backwards compatible
|
30
|
+
def name
|
31
|
+
author_hash["name"]
|
32
|
+
end
|
33
|
+
alias_method :to_s, :name
|
34
|
+
|
35
|
+
def twitter
|
36
|
+
return @twitter if defined? @twitter
|
37
|
+
|
38
|
+
twitter = author_hash["twitter"] || author_hash["name"]
|
39
|
+
@twitter = twitter.is_a?(String) ? twitter.sub(%r!^@!, "") : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :page
|
45
|
+
attr_reader :site
|
46
|
+
|
47
|
+
# Finds the page author in the page.author, page.authors, or site.author
|
48
|
+
#
|
49
|
+
# Returns a string or hash representing the author
|
50
|
+
def resolved_author
|
51
|
+
return @resolved_author if defined? @resolved_author
|
52
|
+
|
53
|
+
sources = [page["author"]]
|
54
|
+
sources << page["authors"].first if page["authors"].is_a?(Array)
|
55
|
+
sources << site["author"]
|
56
|
+
@resolved_author = sources.find { |s| !s.to_s.empty? }
|
57
|
+
end
|
58
|
+
|
59
|
+
# If resolved_author is a string, attempts to find coresponding author
|
60
|
+
# metadata in `site.data.authors`
|
61
|
+
#
|
62
|
+
# Returns a hash representing additional metadata or an empty hash
|
63
|
+
def site_data_hash
|
64
|
+
@site_data_hash ||= begin
|
65
|
+
return {} unless resolved_author.is_a?(String)
|
66
|
+
return {} unless site.data["authors"].is_a?(Hash)
|
67
|
+
|
68
|
+
author_hash = site.data["authors"][resolved_author]
|
69
|
+
author_hash.is_a?(Hash) ? author_hash : {}
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns the normalized author hash representing the page author,
|
74
|
+
# including site-wide metadata if the author is provided as a string,
|
75
|
+
# or an empty hash, if the author cannot be resolved
|
76
|
+
def author_hash
|
77
|
+
@author_hash ||= begin
|
78
|
+
if resolved_author.is_a? Hash
|
79
|
+
resolved_author
|
80
|
+
elsif resolved_author.is_a? String
|
81
|
+
{ "name" => resolved_author }.merge!(site_data_hash)
|
82
|
+
else
|
83
|
+
{}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Since author_hash is aliased to fallback_data, any values in the hash
|
89
|
+
# will be exposed via the drop, allowing support for arbitrary metadata
|
90
|
+
alias_method :fallback_data, :author_hash
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
class SeoTag
|
5
|
+
class Drop < Jekyll::Drops::Drop
|
6
|
+
include Jekyll::SeoTag::UrlHelper
|
7
|
+
|
8
|
+
TITLE_SEPARATOR = " | "
|
9
|
+
FORMAT_STRING_METHODS = [
|
10
|
+
:markdownify, :strip_html, :normalize_whitespace, :escape_once,
|
11
|
+
].freeze
|
12
|
+
HOMEPAGE_OR_ABOUT_REGEX = %r!^/(about/)?(index.html?)?$!.freeze
|
13
|
+
|
14
|
+
EMPTY_READ_ONLY_HASH = {}.freeze
|
15
|
+
private_constant :EMPTY_READ_ONLY_HASH
|
16
|
+
|
17
|
+
def initialize(text, context)
|
18
|
+
@obj = EMPTY_READ_ONLY_HASH
|
19
|
+
@mutations = {}
|
20
|
+
@text = text
|
21
|
+
@context = context
|
22
|
+
end
|
23
|
+
|
24
|
+
def version
|
25
|
+
Jekyll::SeoTag::VERSION
|
26
|
+
end
|
27
|
+
|
28
|
+
# Should the `<title>` tag be generated for this page?
|
29
|
+
def title?
|
30
|
+
return false unless title
|
31
|
+
return @display_title if defined?(@display_title)
|
32
|
+
|
33
|
+
@display_title = (@text !~ %r!title=false!i)
|
34
|
+
end
|
35
|
+
|
36
|
+
def site_title
|
37
|
+
@site_title ||= format_string(site["title"] || site["name"])
|
38
|
+
end
|
39
|
+
|
40
|
+
def site_tagline
|
41
|
+
@site_tagline ||= format_string site["tagline"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def site_description
|
45
|
+
@site_description ||= format_string site["description"]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Page title without site title or description appended
|
49
|
+
def page_title
|
50
|
+
@page_title ||= format_string(page["title"]) || site_title
|
51
|
+
end
|
52
|
+
|
53
|
+
def site_tagline_or_description
|
54
|
+
site_tagline || site_description
|
55
|
+
end
|
56
|
+
|
57
|
+
# Page title with site title or description appended
|
58
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
59
|
+
def title
|
60
|
+
@title ||= begin
|
61
|
+
if site_title && page_title != site_title
|
62
|
+
page_title + TITLE_SEPARATOR + site_title
|
63
|
+
elsif site_description && site_title
|
64
|
+
site_title + TITLE_SEPARATOR + site_tagline_or_description
|
65
|
+
else
|
66
|
+
page_title || site_title
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
return page_number + @title if page_number
|
71
|
+
|
72
|
+
@title
|
73
|
+
end
|
74
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
75
|
+
|
76
|
+
def name
|
77
|
+
return @name if defined?(@name)
|
78
|
+
|
79
|
+
@name = if seo_name
|
80
|
+
seo_name
|
81
|
+
elsif !homepage_or_about?
|
82
|
+
nil
|
83
|
+
elsif site_social["name"]
|
84
|
+
format_string site_social["name"]
|
85
|
+
elsif site_title
|
86
|
+
site_title
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def description
|
91
|
+
@description ||= begin
|
92
|
+
format_string(page["description"] || page["excerpt"]) || site_description
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# A drop representing the page author
|
97
|
+
def author
|
98
|
+
@author ||= AuthorDrop.new(:page => page, :site => site)
|
99
|
+
end
|
100
|
+
|
101
|
+
# A drop representing the JSON-LD output
|
102
|
+
def json_ld
|
103
|
+
@json_ld ||= JSONLDDrop.new(self)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns a Drop representing the page's image
|
107
|
+
# Returns nil if the image has no path, to preserve backwards compatability
|
108
|
+
def image
|
109
|
+
@image ||= ImageDrop.new(:page => page, :context => @context)
|
110
|
+
@image if @image.path
|
111
|
+
end
|
112
|
+
|
113
|
+
def date_modified
|
114
|
+
@date_modified ||= begin
|
115
|
+
date = page_seo["date_modified"] || page["last_modified_at"].to_liquid || page["date"]
|
116
|
+
filters.date_to_xmlschema(date) if date
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def date_published
|
121
|
+
@date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"]
|
122
|
+
end
|
123
|
+
|
124
|
+
def type
|
125
|
+
@type ||= begin
|
126
|
+
if page_seo["type"]
|
127
|
+
page_seo["type"]
|
128
|
+
elsif homepage_or_about?
|
129
|
+
"WebSite"
|
130
|
+
elsif page["date"]
|
131
|
+
"BlogPosting"
|
132
|
+
else
|
133
|
+
"WebPage"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def links
|
139
|
+
@links ||= begin
|
140
|
+
if page_seo["links"]
|
141
|
+
page_seo["links"]
|
142
|
+
elsif homepage_or_about? && site_social["links"]
|
143
|
+
site_social["links"]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def logo
|
149
|
+
@logo ||= begin
|
150
|
+
return unless site["logo"]
|
151
|
+
|
152
|
+
if absolute_url? site["logo"]
|
153
|
+
filters.uri_escape site["logo"]
|
154
|
+
else
|
155
|
+
filters.uri_escape filters.absolute_url site["logo"]
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def page_lang
|
161
|
+
@page_lang ||= page["lang"] || site["lang"] || "en_US"
|
162
|
+
end
|
163
|
+
|
164
|
+
def page_locale
|
165
|
+
@page_locale ||= (page["locale"] || site["locale"] || page_lang).tr("-", "_")
|
166
|
+
end
|
167
|
+
|
168
|
+
def canonical_url
|
169
|
+
@canonical_url ||= begin
|
170
|
+
if page["canonical_url"].to_s.empty?
|
171
|
+
filters.absolute_url(page["url"]).to_s.gsub(%r!/index\.html$!, "/")
|
172
|
+
else
|
173
|
+
page["canonical_url"]
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def soopr
|
179
|
+
@soopr ||= SooprDrop.new(:page => page, :site => site)
|
180
|
+
@soopr if @soopr.publish_token
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
def filters
|
186
|
+
@filters ||= Jekyll::SeoTag::Filters.new(@context)
|
187
|
+
end
|
188
|
+
|
189
|
+
def page
|
190
|
+
@page ||= @context.registers[:page].to_liquid
|
191
|
+
end
|
192
|
+
|
193
|
+
def site
|
194
|
+
@site ||= @context.registers[:site].site_payload["site"].to_liquid
|
195
|
+
end
|
196
|
+
|
197
|
+
def homepage_or_about?
|
198
|
+
page["url"] =~ HOMEPAGE_OR_ABOUT_REGEX
|
199
|
+
end
|
200
|
+
|
201
|
+
def page_number
|
202
|
+
return unless @context["paginator"] && @context["paginator"]["page"]
|
203
|
+
|
204
|
+
current = @context["paginator"]["page"]
|
205
|
+
total = @context["paginator"]["total_pages"]
|
206
|
+
paginator_message = site["seo_paginator_message"] || "Page %<current>s of %<total>s for "
|
207
|
+
|
208
|
+
format(paginator_message, :current => current, :total => total) if current > 1
|
209
|
+
end
|
210
|
+
|
211
|
+
attr_reader :context
|
212
|
+
|
213
|
+
def fallback_data
|
214
|
+
@fallback_data ||= {}
|
215
|
+
end
|
216
|
+
|
217
|
+
def format_string(string)
|
218
|
+
string = FORMAT_STRING_METHODS.reduce(string) do |memo, method|
|
219
|
+
filters.public_send(method, memo)
|
220
|
+
end
|
221
|
+
|
222
|
+
string unless string.empty?
|
223
|
+
end
|
224
|
+
|
225
|
+
def seo_name
|
226
|
+
@seo_name ||= format_string(page_seo["name"]) if page_seo["name"]
|
227
|
+
end
|
228
|
+
|
229
|
+
def page_seo
|
230
|
+
@page_seo ||= sub_hash(page, "seo")
|
231
|
+
end
|
232
|
+
|
233
|
+
def site_social
|
234
|
+
@site_social ||= sub_hash(site, "social")
|
235
|
+
end
|
236
|
+
|
237
|
+
# Safely returns a sub hash
|
238
|
+
#
|
239
|
+
# hash - the parent hash
|
240
|
+
# key - the key in the parent hash
|
241
|
+
#
|
242
|
+
# Returns the sub hash or an empty hash, if it does not exist
|
243
|
+
def sub_hash(hash, key)
|
244
|
+
if hash[key].is_a?(Hash)
|
245
|
+
hash[key]
|
246
|
+
else
|
247
|
+
EMPTY_READ_ONLY_HASH
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|