Skip to content

Commit

Permalink
Merge pull request #1119 from openstax/fix-blog-page
Browse files Browse the repository at this point in the history
Fix blog page to use news/ prefix for CMS but not for page URLs
  • Loading branch information
mwvolo authored May 24, 2018
2 parents e9dd08d + 7942d04 commit 0af58c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/app/pages/blog/article/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/blog/article/formatted-as/formatted-as.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
13 changes: 2 additions & 11 deletions src/app/pages/blog/blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 '+
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0af58c3

Please sign in to comment.