From 7942d040c08b4017c760de3f42fdb194d3c70d1c Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Thu, 24 May 2018 14:53:31 -0500 Subject: [PATCH] Fix blog page to use news/ prefix for CMS but not for page URLs --- src/app/pages/blog/article/article.js | 9 ++++++++- .../pages/blog/article/formatted-as/formatted-as.js | 2 +- src/app/pages/blog/blog.js | 13 ++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/pages/blog/article/article.js b/src/app/pages/blog/article/article.js index 63bdfb2f6..2ed6d4042 100644 --- a/src/app/pages/blog/article/article.js +++ b/src/app/pages/blog/article/article.js @@ -2,6 +2,13 @@ import VERSION from '~/version'; import CMSPageController from '~/controllers/cms'; import FormattedAs from './formatted-as/formatted-as'; +function slugWithNewsPrefix(slug) { + if (!(/^news\//).test(slug)) { + return `news/${slug}`; + } + return slug; +} + export default class Article extends CMSPageController { init(article, mode) { @@ -10,7 +17,7 @@ export default class Article extends CMSPageController { this.view = { classes: ['article', 'hide-until-loaded'] }; - this.slug = article.slug; + this.slug = slugWithNewsPrefix(article.slug); this.pinned = article.pin_to_top; this.preserveWrapping = true; } diff --git a/src/app/pages/blog/article/formatted-as/formatted-as.js b/src/app/pages/blog/article/formatted-as/formatted-as.js index d2d784a23..dcf1e76c8 100644 --- a/src/app/pages/blog/article/formatted-as/formatted-as.js +++ b/src/app/pages/blog/article/formatted-as/formatted-as.js @@ -11,7 +11,7 @@ export default class FormattedAs extends Controller { this.format = format; this.model = Object.assign({ coverUrl: article.article_image || 'https://placehold.it/370x240', - articleSlug: article.slug + articleSlug: article.slug.replace('news/', '') }, article); this.model.date = formatDate(article.date); this.regions = { diff --git a/src/app/pages/blog/blog.js b/src/app/pages/blog/blog.js index 5facd6aaa..180b8e945 100644 --- a/src/app/pages/blog/blog.js +++ b/src/app/pages/blog/blog.js @@ -8,14 +8,6 @@ import CMSPageController from '~/controllers/cms'; import Article from './article/article'; import {description as template} from './blog.html'; - -function slugWithNewsPrefix(slug) { - if (!(/^news\//).test(slug)) { - return `news/${slug}`; - } - return slug; -} - export default class Blog extends CMSPageController { static description = 'Stay up to date with OpenStax news and hear community '+ @@ -47,7 +39,7 @@ export default class Blog extends CMSPageController { const slugMatch = window.location.pathname.match(/\/blog\/(.+)/); if (slugMatch) { - this.model.articleSlug = slugWithNewsPrefix(slugMatch[1]); + this.model.articleSlug = slugMatch[1]; if (!this.articles[this.model.articleSlug]) { router.navigate('/404', {path: '/blog'}, true); return; @@ -107,8 +99,7 @@ export default class Blog extends CMSPageController { }); this.articles = {}; - for (const rawSlug of this.articleSlugs) { - const slug = slugWithNewsPrefix(rawSlug); + for (const slug of this.articleSlugs) { const article = Object.assign({slug}, this.pageData.articles[slug]); if (article.pin_to_top) {