Skip to content

Commit

Permalink
✨ 🐛 Move meta description into ghost head (#8150)
Browse files Browse the repository at this point in the history
closes #4424

- meta description is an optional SEO tag that we can provide when we have sensible output
- in the cases where we have no useful output, we should not output the tag at all
- ghost_head now takes care of this, and themes should not include their own meta description tag
  • Loading branch information
ErisDS authored and kirrg001 committed Mar 14, 2017
1 parent f52e3e7 commit b8162b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core/server/helpers/ghost_head.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ function ghost_head(options) {

if (context) {
// head is our main array that holds our meta data
if (metaData.metaDescription && metaData.metaDescription.length > 0) {
head.push('<meta name="description" content="' + escapeExpression(metaData.metaDescription) + '" />');
}

head.push('<link rel="shortcut icon" href="' + favicon + '" type="' + iconType + '" />');
head.push('<link rel="canonical" href="' +
escapeExpression(metaData.canonicalUrl) + '" />');
Expand Down
29 changes: 26 additions & 3 deletions core/test/unit/server_helpers/ghost_head_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/page\/2\/" \/>/);
rendered.string.should.match(/<meta name="generator" content="Ghost 0.3" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.not.match(/<meta name="description"/);
rendered.string.should.not.match(/<meta property="og/);
rendered.string.should.not.match(/<script type=\"application\/ld\+json\">/);

Expand All @@ -88,6 +89,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/" \/>/);
rendered.string.should.match(/<meta name="referrer" content="no-referrer-when-downgrade" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Ghost" \/>/);
Expand Down Expand Up @@ -141,6 +143,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/about\/" \/>/);
rendered.string.should.match(/<meta name="referrer" content="no-referrer-when-downgrade" \/>/);
rendered.string.should.match(/<meta name="description" content="all about our blog" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="About" \/>/);
Expand Down Expand Up @@ -187,6 +190,7 @@ describe('{{ghost_head}} helper', function () {
should.exist(rendered);
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/tag\/tagtitle\/" \/>/);
rendered.string.should.match(/<meta name="description" content="tag meta description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="tag meta title" \/>/);
Expand Down Expand Up @@ -229,6 +233,7 @@ describe('{{ghost_head}} helper', function () {
should.exist(rendered);
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/tag\/tagtitle\/" \/>/);
rendered.string.should.match(/<meta name="description" content="tag description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="tagtitle - Ghost" \/>/);
Expand Down Expand Up @@ -269,8 +274,9 @@ describe('{{ghost_head}} helper', function () {
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.not.match(/<meta property="og:description" \/>/);
rendered.string.should.not.match(/<meta name="twitter:description"\/>/);
rendered.string.should.not.match(/<meta name="description"/);
rendered.string.should.not.match(/<meta property="og:description"/);
rendered.string.should.not.match(/<meta name="twitter:description"/);
rendered.string.should.not.match(/"description":/);

done();
Expand All @@ -293,6 +299,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/tag\/tagtitle\/page\/2\/" \/>/);
rendered.string.should.match(/<meta name="generator" content="Ghost 0.3" \/>/);
rendered.string.should.match(/<meta name="description" content="tag meta description" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.not.match(/<meta property="og/);
rendered.string.should.not.match(/<script type=\"application\/ld\+json\">/);
Expand Down Expand Up @@ -320,6 +327,7 @@ describe('{{ghost_head}} helper', function () {
should.exist(rendered);
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/author\/AuthorName\/" \/>/);
rendered.string.should.match(/<meta name="description" content="Author bio" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="profile" \/>/);
rendered.string.should.match(/<meta property="og:description" content="Author bio" \/>/);
Expand Down Expand Up @@ -368,6 +376,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/author\/AuthorName\/page\/2\/" \/>/);
rendered.string.should.match(/<meta name="generator" content="Ghost 0.3" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.not.match(/<meta name="description" /);
rendered.string.should.not.match(/<meta property="og/);
rendered.string.should.not.match(/<script type=\"application\/ld\+json\">/);

Expand Down Expand Up @@ -422,6 +431,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="article" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Welcome to Ghost" \/>/);
Expand Down Expand Up @@ -501,6 +511,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.not.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="article" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Welcome to Ghost" \/>/);
Expand Down Expand Up @@ -580,6 +591,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog &quot;test&quot; description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="article" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Welcome to Ghost &quot;test&quot;" \/>/);
Expand Down Expand Up @@ -657,6 +669,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="article" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Welcome to Ghost" \/>/);
Expand Down Expand Up @@ -732,6 +745,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="article" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Welcome to Ghost" \/>/);
Expand Down Expand Up @@ -791,12 +805,13 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<meta property="og:url" content="http:\/\/testurl.com\/featured\/" \/>/);

rendered.string.should.not.match(/<script type=\"application\/ld\+json\">/);
rendered.string.should.not.match(/<meta name="description" /);

done();
}).catch(done);
});

it('returns twitter and facebook descriptions if no meta description available', function (done) {
it('returns twitter and facebook descriptions even if no meta description available', function (done) {
var post = {
title: 'Welcome to Ghost',
html: '<p>This is a short post</p>',
Expand All @@ -810,6 +825,7 @@ describe('{{ghost_head}} helper', function () {
{data: {root: {context: ['post']}}}
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.not.match(/<meta name="description" /);
rendered.string.should.match(/<link rel="shortcut icon" href="\/favicon.ico" type="x-icon" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta property="og:description" content="This is a short post" \/>/);
Expand Down Expand Up @@ -874,6 +890,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="next" href="http:\/\/testurl.com\/page\/3\/" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.not.match(/<meta property="og/);
rendered.string.should.not.match(/<meta name="description" /);
rendered.string.should.not.match(/<script type=\"application\/ld\+json\">/);

done();
Expand All @@ -899,6 +916,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/blog\/" \/>/);
rendered.string.should.match(/<meta name="generator" content="Ghost 0.3" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/blog\/rss\/" \/>/);
rendered.string.should.not.match(/<meta name="description" /);

done();
}).catch(done);
Expand Down Expand Up @@ -934,6 +952,7 @@ describe('{{ghost_head}} helper', function () {
should.exist(rendered);
rendered.string.should.match(/<link rel="shortcut icon" href="\/content\/images\/favicon.png" type="png" \/>/);
rendered.string.should.match(/<meta name="referrer" content="origin" \/>/);
rendered.string.should.not.match(/<meta name="description" /);

done();
}).catch(done);
Expand Down Expand Up @@ -989,6 +1008,7 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="shortcut icon" href="\/content\/images\/favicon.png" type="png" \/>/);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/post\/" \/>/);
rendered.string.should.match(/<link rel="amphtml" href="http:\/\/testurl.com\/post\/amp\/" \/>/);
rendered.string.should.match(/<meta name="description" content="blog description" \/>/);
rendered.string.should.match(/<meta name="generator" content="Ghost 0.3" \/>/);
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.not.match(/<meta property="og/);
Expand Down Expand Up @@ -1033,6 +1053,9 @@ describe('{{ghost_head}} helper', function () {
rendered.string.should.match(/<link rel="alternate" type="application\/rss\+xml" title="Ghost" href="http:\/\/testurl.com\/rss\/" \/>/);
rendered.string.should.match(/<style>body {background: red;}<\/style>/);

// No default meta desc in paged context
rendered.string.should.not.match(/<meta name="description" \/>/);

done();
}).catch(done);
});
Expand Down

0 comments on commit b8162b1

Please sign in to comment.