Skip to content

Commit 7525264

Browse files
authored
Keep canonical/prev/next independent of the noindex gate (#646)
1 parent 3cec15c commit 7525264

5 files changed

Lines changed: 27 additions & 20 deletions

File tree

resources/views/meta.antlers.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
{{ /image }}
7777
{{ /if }}
7878

79-
{{ unless (robots_indexing == 'noindex') }}
80-
<link href="{{ home_url | striptags | entities | trim }}" rel="home" />
79+
{{ unless (response_code >= 400) }}
8180
<link href="{{ canonical_url | striptags | entities | trim }}" rel="canonical" />
8281

8382
{{ if prev_url }}
@@ -88,18 +87,22 @@
8887
<link href="{{ next_url | striptags | entities | trim }}" rel="next" />
8988
{{ /if }}
9089

91-
{{ if alternate_locales }}
92-
<link rel="alternate" href="{{ canonical_url | striptags | entities | trim }}" hreflang="{{ current_hreflang }}" />
93-
{{ if is_default_site }}
94-
<link rel="alternate" href="{{ canonical_url | striptags | entities | trim }}" hreflang="x-default" />
95-
{{ /if }}
96-
{{ alternate_locales }}
97-
<link rel="alternate" href="{{ url | striptags | entities | trim }}" hreflang="{{ hreflang }}" />
90+
{{ unless (robots_indexing == 'noindex') }}
91+
<link href="{{ home_url | striptags | entities | trim }}" rel="home" />
92+
93+
{{ if alternate_locales }}
94+
<link rel="alternate" href="{{ canonical_url | striptags | entities | trim }}" hreflang="{{ current_hreflang }}" />
9895
{{ if is_default_site }}
99-
<link rel="alternate" href="{{ url | striptags | entities | trim }}" hreflang="x-default" />
96+
<link rel="alternate" href="{{ canonical_url | striptags | entities | trim }}" hreflang="x-default" />
10097
{{ /if }}
101-
{{ /alternate_locales }}
102-
{{ /if }}
98+
{{ alternate_locales }}
99+
<link rel="alternate" href="{{ url | striptags | entities | trim }}" hreflang="{{ hreflang }}" />
100+
{{ if is_default_site }}
101+
<link rel="alternate" href="{{ url | striptags | entities | trim }}" hreflang="x-default" />
102+
{{ /if }}
103+
{{ /alternate_locales }}
104+
{{ /if }}
105+
{{ /unless }}
103106
{{ /unless }}
104107

105108
{{ if humans_txt }}

tests/GraphQLTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function it_queries_for_entry_seo_meta_html()
6969
'<meta property="og:image:alt" content="" />',
7070
'<meta name="twitter:image" content="http://cool-runnings.com/assets/img/stetson.jpg" />',
7171
'<meta name="twitter:image:alt" content="" />',
72-
'<link href="http://cool-runnings.com" rel="home" />',
7372
'<link href="http://cool-runnings.com/nectar" rel="canonical" />',
73+
'<link href="http://cool-runnings.com" rel="home" />',
7474
'<link type="text/plain" rel="author" href="http://cool-runnings.com/humans.txt" />',
7575
])->implode('');
7676

@@ -187,8 +187,8 @@ public function it_queries_for_term_seo_meta_html()
187187
'<meta property="og:locale" content="en_US" />',
188188
'<meta name="twitter:card" content="summary_large_image" />',
189189
'<meta name="twitter:title" content="Dance" />',
190-
'<link href="http://cool-runnings.com" rel="home" />',
191190
'<link href="http://cool-runnings.com/topics/dance" rel="canonical" />',
191+
'<link href="http://cool-runnings.com" rel="home" />',
192192
'<link type="text/plain" rel="author" href="http://cool-runnings.com/humans.txt" />',
193193
])->implode('');
194194

tests/Localized/GraphQLTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function it_queries_multisite_for_canonical_url_and_alternate_locales_in_
4141
'<meta name="twitter:card" content="summary_large_image" />',
4242
'<meta name="twitter:title" content="Les Nectar of the Gods" />',
4343
'<meta name="twitter:description" content="The day started just like any other. Wake up at 5:30am, brush my teeth, bathe in a tub of warm milk, and trim my toenails while quietly resenting the fact that Flipper was on Nickelodeon at this hour instead of Rocko&#039;s Modern Life. That would have to wait until 5:30pm for that, and I am impatient.In truth, the day wou..." />',
44-
'<link href="http://cool-runnings.com" rel="home" />',
4544
'<link href="http://cool-runnings.com/fr/nectar" rel="canonical" />',
45+
'<link href="http://cool-runnings.com" rel="home" />',
4646
'<link rel="alternate" href="http://cool-runnings.com/fr/nectar" hreflang="fr" />',
4747
'<link rel="alternate" href="http://cool-runnings.com/nectar" hreflang="en" />',
4848
'<link rel="alternate" href="http://cool-runnings.com/nectar" hreflang="x-default" />',

tests/Localized/MetaTagTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function it_generates_multisite_meta_for_canonical_url_and_alternate_loca
109109

110110
$expectedAlternateHreflangMeta = <<<'EOT'
111111
<link href="http://cool-runnings.com/fr/about" rel="canonical" />
112+
<link href="http://cool-runnings.com" rel="home" />
112113
<link rel="alternate" href="http://cool-runnings.com/fr/about" hreflang="fr" />
113114
<link rel="alternate" href="http://cool-runnings.com/about" hreflang="en" />
114115
<link rel="alternate" href="http://cool-runnings.com/about" hreflang="x-default" />
@@ -135,6 +136,7 @@ public function it_handles_duplicate_alternate_hreflangs($viewType)
135136

136137
$expectedAlternateHreflangMeta = <<<'EOT'
137138
<link href="http://cool-runnings.com/fr" rel="canonical" />
139+
<link href="http://cool-runnings.com" rel="home" />
138140
<link rel="alternate" href="http://cool-runnings.com/fr" hreflang="fr" />
139141
<link rel="alternate" href="http://cool-runnings.com" hreflang="en-us" />
140142
<link rel="alternate" href="http://cool-runnings.com" hreflang="x-default" />
@@ -161,6 +163,7 @@ public function it_handles_duplicate_current_hreflang($viewType)
161163

162164
$expectedAlternateHreflangMeta = <<<'EOT'
163165
<link href="http://cool-runnings.com/en-gb" rel="canonical" />
166+
<link href="http://cool-runnings.com" rel="home" />
164167
<link rel="alternate" href="http://cool-runnings.com/en-gb" hreflang="en-gb" />
165168
<link rel="alternate" href="http://cool-runnings.com" hreflang="en-us" />
166169
<link rel="alternate" href="http://cool-runnings.com" hreflang="x-default" />

tests/MetaTagTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public function it_generates_normalized_meta($viewType)
7676
<meta name="twitter:card" content="summary_large_image" />
7777
<meta name="twitter:title" content="Home" />
7878
<meta name="twitter:description" content="I see a bad-ass mother." />
79-
<link href="http://cool-runnings.com" rel="home" />
8079
<link href="http://cool-runnings.com" rel="canonical" />
80+
<link href="http://cool-runnings.com" rel="home" />
8181
<link type="text/plain" rel="author" href="http://cool-runnings.com/humans.txt" />
8282
EOT;
8383

@@ -105,8 +105,8 @@ public function it_generates_normalized_meta_when_visiting_statamic_route_with_r
105105
<meta name="twitter:card" content="summary_large_image" />
106106
<meta name="twitter:title" content="The View" />
107107
<meta name="twitter:description" content="A wonderful view!" />
108-
<link href="http://cool-runnings.com" rel="home" />
109108
<link href="http://cool-runnings.com/the-view" rel="canonical" />
109+
<link href="http://cool-runnings.com" rel="home" />
110110
<link type="text/plain" rel="author" href="http://cool-runnings.com/humans.txt" />
111111
EOT;
112112

@@ -135,8 +135,8 @@ public function it_generates_normalized_meta_when_visiting_statamic_route_with_r
135135
<meta name="twitter:card" content="summary_large_image" />
136136
<meta name="twitter:title" content="The View" />
137137
<meta name="twitter:description" content="A wonderful view!" />
138-
<link href="http://cool-runnings.com" rel="home" />
139138
<link href="http://cool-runnings.com/the-view" rel="canonical" />
139+
<link href="http://cool-runnings.com" rel="home" />
140140
<link type="text/plain" rel="author" href="http://cool-runnings.com/humans.txt" />
141141
EOT;
142142

@@ -872,7 +872,7 @@ public function it_generates_pagination_meta_urls_with_trailing_slashes_when_con
872872
}
873873

874874
#[Test]
875-
public function it_doesnt_output_canonical_when_robots_noindex()
875+
public function it_still_outputs_canonical_when_robots_noindex()
876876
{
877877
$this
878878
->prepareViews('antlers')
@@ -881,7 +881,8 @@ public function it_doesnt_output_canonical_when_robots_noindex()
881881
]);
882882

883883
$response = $this->get('/about');
884-
$response->assertDontSee('" rel="canonical"', false);
884+
$response->assertSee('<link href="http://cool-runnings.com/about" rel="canonical" />', false);
885+
$response->assertDontSee(' rel="home"', false);
885886
}
886887

887888
#[Test]

0 commit comments

Comments
 (0)