From 01f5dc238f3d20627c2713d86c94c82107f08ca8 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 10 Oct 2016 10:38:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20the=20deprecated=20body?= =?UTF-8?q?=20classes=20(#7510)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #2597 - Remove .archive-template - Remove .page - Don't output .post-template on pages - Use `page-slug` instead of `page-template-slug` - Always output `page-slug` irrelevant of whether or not there is a custom template --- core/server/helpers/body_class.js | 30 +++---------------- .../unit/server_helpers/body_class_spec.js | 14 ++++----- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/core/server/helpers/body_class.js b/core/server/helpers/body_class.js index 8dd5070889..ac7d390b48 100644 --- a/core/server/helpers/body_class.js +++ b/core/server/helpers/body_class.js @@ -8,8 +8,6 @@ var hbs = require('express-hbs'), _ = require('lodash'), - // @TODO Fix this - template = require('../controllers/frontend/templates'), body_class; body_class = function (options) { @@ -17,22 +15,15 @@ body_class = function (options) { context = options.data.root.context, post = this.post, tags = this.post && this.post.tags ? this.post.tags : this.tags || [], - page = this.post && this.post.page ? this.post.page : this.page || false, - activeTheme = options.data.root.settings.activeTheme, - view; - - if (post) { - // To be removed from pages by #2597 when we're ready to deprecate this - // i.e. this should be if (_.includes(context, 'post') && post) { ... } - classes.push('post-template'); - } + page = this.post && this.post.page ? this.post.page : this.page || false; if (_.includes(context, 'home')) { classes.push('home-template'); + } else if (_.includes(context, 'post') && post) { + classes.push('post-template'); } else if (_.includes(context, 'page') && page) { classes.push('page-template'); - // To be removed by #2597 when we're ready to deprecate this - classes.push('page'); + classes.push('page-' + this.post.slug); } else if (_.includes(context, 'tag') && this.tag) { classes.push('tag-template'); classes.push('tag-' + this.tag.slug); @@ -49,19 +40,6 @@ body_class = function (options) { if (_.includes(context, 'paged')) { classes.push('paged'); - // To be removed from pages by #2597 when we're ready to deprecate this - classes.push('archive-template'); - } - - if (post && page) { - view = template.single(activeTheme, post).split('-'); - - if (view[0] === 'page' && view.length > 1) { - classes.push(view.join('-')); - // To be removed by #2597 when we're ready to deprecate this - view.splice(1, 0, 'template'); - classes.push(view.join('-')); - } } classes = _.reduce(classes, function (memo, item) { return memo + ' ' + item; }, ''); diff --git a/core/test/unit/server_helpers/body_class_spec.js b/core/test/unit/server_helpers/body_class_spec.js index 4792c359fc..5de265bdb1 100644 --- a/core/test/unit/server_helpers/body_class_spec.js +++ b/core/test/unit/server_helpers/body_class_spec.js @@ -86,7 +86,7 @@ describe('{{body_class}} helper', function () { {relativeUrl: '/page/4'} ); - rendered.string.should.equal('paged archive-template'); + rendered.string.should.equal('paged'); }); it('tag page', function () { @@ -104,7 +104,7 @@ describe('{{body_class}} helper', function () { {relativeUrl: '/tag/foo/page/2', tag: {slug: 'foo'}} ); - rendered.string.should.equal('tag-template tag-foo paged archive-template'); + rendered.string.should.equal('tag-template tag-foo paged'); }); it('author page', function () { @@ -122,7 +122,7 @@ describe('{{body_class}} helper', function () { {relativeUrl: '/author/bar/page/2', author: {slug: 'bar'}} ); - rendered.string.should.equal('author-template author-bar paged archive-template'); + rendered.string.should.equal('author-template author-bar paged'); }); it('private route for password protection', function () { @@ -146,19 +146,19 @@ describe('{{body_class}} helper', function () { it('a static page', function () { var rendered = callBodyClassWithContext( ['page'], - {relativeUrl: '/about', post: {page: true}} + {relativeUrl: '/about', post: {page: true, slug: 'about'}} ); - rendered.string.should.equal('post-template page-template page'); + rendered.string.should.equal('page-template page-about'); }); - it('a static page with custom template', function () { + it('a static page with custom template (is now the same as one without)', function () { var rendered = callBodyClassWithContext( ['page'], {relativeUrl: '/about', post: {page: true, slug: 'about'}} ); - rendered.string.should.equal('post-template page-template page page-about page-template-about'); + rendered.string.should.equal('page-template page-about'); }); }); });