Merge pull request #87 from tfe/use-prev-next-for-pagination
Different philosophy for rel prev/next links based on recommendations from Google
This commit is contained in:
commit
43786da92a
|
@ -11,7 +11,7 @@ Jekyll SEO Tag adds the following meta tags to your site:
|
|||
* Pages title (with site title appended when available)
|
||||
* Page description
|
||||
* Canonical URL
|
||||
* Next and previous URLs for posts
|
||||
* Next and previous URLs on paginated pages
|
||||
* [JSON-LD Site and post metadata](https://developers.google.com/structured-data/) for richer indexing
|
||||
* [Open graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.)
|
||||
* [Twitter summary card](https://dev.twitter.com/cards/overview) metadata
|
||||
|
|
|
@ -30,6 +30,7 @@ module Jekyll
|
|||
{
|
||||
'page' => context.registers[:page],
|
||||
'site' => context.registers[:site].site_payload['site'],
|
||||
'paginator' => context['paginator'],
|
||||
'seo_tag' => options
|
||||
}
|
||||
end
|
||||
|
|
|
@ -139,14 +139,13 @@
|
|||
{% if page.date %}
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}" />
|
||||
{% endif %}
|
||||
|
||||
{% if page.next.url %}
|
||||
<link rel="next" href="{{ page.next.url | prepend: seo_url | replace:'/index.html','/' }}" title="{{ page.next.title | escape }}" />
|
||||
{% endif %}
|
||||
|
||||
{% if page.previous.url %}
|
||||
<link rel="prev" href="{{ page.previous.url | prepend: seo_url | replace:'/index.html','/' }}" title="{{ page.previous.title | escape }}" />
|
||||
{% endif %}
|
||||
{% if paginator.previous_page %}
|
||||
<link rel="prev" href="{{ paginator.previous_page_path | prepend: seo_url }}">
|
||||
{% endif %}
|
||||
{% if paginator.next_page %}
|
||||
<link rel="next" href="{{ paginator.next_page_path | prepend: seo_url }}">
|
||||
{% endif %}
|
||||
|
||||
{% if site.twitter %}
|
||||
|
|
|
@ -10,6 +10,7 @@ describe Jekyll::SeoTag do
|
|||
let(:output) { Liquid::Template.parse("{% #{tag} #{text} %}").render!(context, {}) }
|
||||
let(:json) { output.match(%r{<script type=\"application/ld\+json\">(.*)</script>}m)[1] }
|
||||
let(:json_data) { JSON.parse(json) }
|
||||
let(:paginator) { { 'previous_page' => true, 'previous_page_path' => 'foo', 'next_page' => true, 'next_page_path' => 'bar' } }
|
||||
|
||||
before do
|
||||
Jekyll.logger.log_level = :error
|
||||
|
@ -24,6 +25,16 @@ describe Jekyll::SeoTag do
|
|||
expect(output).to match(/Jekyll SEO tag v#{version}/i)
|
||||
end
|
||||
|
||||
it 'outputs valid HTML' do
|
||||
site.process
|
||||
options = {
|
||||
check_html: true,
|
||||
checks_to_ignore: %w(ScriptCheck LinkCheck ImageCheck)
|
||||
}
|
||||
status = HTML::Proofer.new(dest_dir, options).run
|
||||
expect(status).to eql(true)
|
||||
end
|
||||
|
||||
context 'with page.title' do
|
||||
let(:page) { make_page('title' => 'foo') }
|
||||
|
||||
|
@ -434,13 +445,12 @@ EOS
|
|||
end
|
||||
end
|
||||
|
||||
it 'outputs valid HTML' do
|
||||
site.process
|
||||
options = {
|
||||
check_html: true,
|
||||
checks_to_ignore: %w(ScriptCheck LinkCheck ImageCheck)
|
||||
}
|
||||
status = HTML::Proofer.new(dest_dir, options).run
|
||||
expect(status).to eql(true)
|
||||
context 'with pagination' do
|
||||
let(:context) { make_context({}, 'paginator' => paginator) }
|
||||
|
||||
it 'outputs pagination links' do
|
||||
expect(output).to match(/<link rel="prev" href="foo">/)
|
||||
expect(output).to match(/<link rel="next" href="bar">/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,6 +38,6 @@ def make_site(options = {})
|
|||
Jekyll::Site.new(config)
|
||||
end
|
||||
|
||||
def make_context(registers = {})
|
||||
Liquid::Context.new({}, {}, { site: site, page: page }.merge(registers))
|
||||
def make_context(registers = {}, environments = {})
|
||||
Liquid::Context.new(environments, {}, { site: site, page: page }.merge(registers))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue