From 7161cd1ee30dfba109ff129c2201d1923a321205 Mon Sep 17 00:00:00 2001 From: glozhkovoy Date: Mon, 25 Dec 2017 11:44:04 +0200 Subject: [PATCH 1/2] Decode html characters in meta tags --- package.json | 1 + server.jsx | 10 ++++++++++ shared/Blog/Routes/BlogContainer.js | 2 +- shared/Blog/Routes/BlogRouter.js | 2 +- shared/Checkout/Routes/Checkout/Checkout.js | 2 +- shared/Contacts/Routes/ContactUs.js | 4 ++-- shared/Podcasts/Routes/Podcast.js | 2 +- shared/Proposals/Routes/Proposals.js | 2 +- shared/Proposals/Routes/ThankYou/ThankYouPage.js | 2 +- shared/components/Advertising.js | 2 +- shared/components/Analytics.js | 2 +- shared/components/Home.jsx | 2 +- shared/components/Login.js | 2 +- shared/components/Logout.js | 2 +- shared/components/Membership.jsx | 2 +- shared/components/MembershipPortal.js | 2 +- shared/components/Press.js | 2 +- shared/components/Projects.js | 2 +- shared/components/Services.jsx | 2 +- shared/components/Store.js | 2 +- 20 files changed, 30 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index fc24ddee..201446af 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "fs": "0.0.1-security", "fs-extra": "^2.0.0", "history": "^1.17.0", + "html-entities": "^1.2.1", "http-proxy-middleware": "^0.17.4", "http-server": "^0.8.5", "immutable": "^3.7.6", diff --git a/server.jsx b/server.jsx index aad739ab..1683218c 100644 --- a/server.jsx +++ b/server.jsx @@ -60,6 +60,10 @@ import { get_related_content } from 'utils/redux_loader'; import redirects_map from './redirects'; +// page meta data decoding +const Entities = require('html-entities').XmlEntities; +const entities = new Entities(); + import {reducer as formReducer} from 'redux-form' @@ -488,6 +492,12 @@ function renderView(store, renderProps, location) { activePageComponent = (activePageComponent.length > 0) ? activePageComponent[0] : null; if (activePageComponent) { meta = extend(meta, activePageComponent.getPageMeta(state)); + meta = { + title: entities.encode(meta.title), + description: entities.encode(meta.description), + author: entities.encode(meta.author), + keywoards: entities.encode(meta.keywoards), + } } return { diff --git a/shared/Blog/Routes/BlogContainer.js b/shared/Blog/Routes/BlogContainer.js index a47cb2bb..3e363761 100644 --- a/shared/Blog/Routes/BlogContainer.js +++ b/shared/Blog/Routes/BlogContainer.js @@ -37,7 +37,7 @@ class BlogContainer extends Component { static getPageMeta() { return { - title: 'Blogs | Data Skeptic' + title: `Blogs | Data Skeptic` } } diff --git a/shared/Blog/Routes/BlogRouter.js b/shared/Blog/Routes/BlogRouter.js index 226e5381..9c55b269 100644 --- a/shared/Blog/Routes/BlogRouter.js +++ b/shared/Blog/Routes/BlogRouter.js @@ -41,7 +41,7 @@ class BlogRouter extends React.Component { let meta = { //title: `${post.title} | Data Skeptic`, title: `Data Skeptic`, - description: post.desc + description: `${post.desc}` }; if (isEpisode) { diff --git a/shared/Checkout/Routes/Checkout/Checkout.js b/shared/Checkout/Routes/Checkout/Checkout.js index c139fae3..a0a26b5e 100644 --- a/shared/Checkout/Routes/Checkout/Checkout.js +++ b/shared/Checkout/Routes/Checkout/Checkout.js @@ -23,7 +23,7 @@ class Checkout extends Component { static getPageMeta() { return { - title: 'Checkout | Data Skeptic' + title: `Checkout | Data Skeptic` } } diff --git a/shared/Contacts/Routes/ContactUs.js b/shared/Contacts/Routes/ContactUs.js index e68e792f..98cd79c5 100644 --- a/shared/Contacts/Routes/ContactUs.js +++ b/shared/Contacts/Routes/ContactUs.js @@ -22,8 +22,8 @@ class ContactUs extends React.Component { static getPageMeta() { return { - title: 'Contact Us | Data Skeptic', - description: 'We hope to respond to all inquiries, but sometimes the volume of incoming questions can cause our queue to explode. We prioritize responses to Data Skeptic members first, and to those who ask questions in a public forum like Twitter, our Facebook wall (not Facebook direct message), or Slack. Many people can benefit from responses in public places.' + title: `Contact Us | Data Skeptic`, + description: `We hope to respond to all inquiries, but sometimes the volume of incoming questions can cause our queue to explode. We prioritize responses to Data Skeptic members first, and to those who ask questions in a public forum like Twitter, our Facebook wall (not Facebook direct message), or Slack. Many people can benefit from responses in public places.` } } diff --git a/shared/Podcasts/Routes/Podcast.js b/shared/Podcasts/Routes/Podcast.js index beefa306..d9cb55ae 100644 --- a/shared/Podcasts/Routes/Podcast.js +++ b/shared/Podcasts/Routes/Podcast.js @@ -34,7 +34,7 @@ class Podcast extends Component { static getPageMeta() { return { - title: 'Podcasts | Data Skeptic' + title: `Podcasts | Data Skeptic` } } diff --git a/shared/Proposals/Routes/Proposals.js b/shared/Proposals/Routes/Proposals.js index 53d97be4..27cb8c60 100644 --- a/shared/Proposals/Routes/Proposals.js +++ b/shared/Proposals/Routes/Proposals.js @@ -45,7 +45,7 @@ class Proposals extends Component { static getPageMeta() { return { - title: 'Request for Comment | Data Skeptic' + title: `Request for Comment | Data Skeptic` } } diff --git a/shared/Proposals/Routes/ThankYou/ThankYouPage.js b/shared/Proposals/Routes/ThankYou/ThankYouPage.js index 154e1974..181c9435 100644 --- a/shared/Proposals/Routes/ThankYou/ThankYouPage.js +++ b/shared/Proposals/Routes/ThankYou/ThankYouPage.js @@ -18,7 +18,7 @@ class ProposalsThankYouPage extends Component { static getPageMeta() { return { - title: 'Thank you | Data Skeptic' + title: `Thank you | Data Skeptic` } } diff --git a/shared/components/Advertising.js b/shared/components/Advertising.js index 689c6f8f..d5ec296e 100644 --- a/shared/components/Advertising.js +++ b/shared/components/Advertising.js @@ -13,7 +13,7 @@ class Advertising extends Component { static getPageMeta() { return { - title: 'Advertising | Data Skeptic' + title: `Advertising | Data Skeptic` } } diff --git a/shared/components/Analytics.js b/shared/components/Analytics.js index 9ddc7a29..d0c342cf 100644 --- a/shared/components/Analytics.js +++ b/shared/components/Analytics.js @@ -23,7 +23,7 @@ class AnalyticsPage extends Component { static getPageMeta() { return { - title: 'Analytics | Data Skeptic' + title: `Analytics | Data Skeptic` } } diff --git a/shared/components/Home.jsx b/shared/components/Home.jsx index bec57aef..aebdfb42 100644 --- a/shared/components/Home.jsx +++ b/shared/components/Home.jsx @@ -25,7 +25,7 @@ class Home extends Component { static getPageMeta() { return { - title: 'Data Skeptic' + title: `Data Skeptic` } } diff --git a/shared/components/Login.js b/shared/components/Login.js index a8bdf534..fc15b4a4 100644 --- a/shared/components/Login.js +++ b/shared/components/Login.js @@ -23,7 +23,7 @@ class Login extends Component { static getPageMeta() { return { - title: 'Login | Data Skeptic' + title: `Login | Data Skeptic` } } diff --git a/shared/components/Logout.js b/shared/components/Logout.js index f7bef4d2..86b112f3 100644 --- a/shared/components/Logout.js +++ b/shared/components/Logout.js @@ -21,7 +21,7 @@ class Logout extends Component { static getPageMeta() { return { - title: 'Logout | Data Skeptic' + title: `Logout | Data Skeptic` } } diff --git a/shared/components/Membership.jsx b/shared/components/Membership.jsx index 8d9f2d58..d0a0ddfc 100644 --- a/shared/components/Membership.jsx +++ b/shared/components/Membership.jsx @@ -28,7 +28,7 @@ class Membership extends Component { static getPageMeta() { return { - title: 'Membership | Data Skeptic' + title: `Membership | Data Skeptic` } } diff --git a/shared/components/MembershipPortal.js b/shared/components/MembershipPortal.js index 27bab237..cd2cc638 100644 --- a/shared/components/MembershipPortal.js +++ b/shared/components/MembershipPortal.js @@ -30,7 +30,7 @@ class MembershipPortal extends Component { static getPageMeta() { return { - title: 'Membership Portal | Data Skeptic' + title: `Membership Portal | Data Skeptic` } } diff --git a/shared/components/Press.js b/shared/components/Press.js index 37895253..02112158 100644 --- a/shared/components/Press.js +++ b/shared/components/Press.js @@ -14,7 +14,7 @@ class Coaching extends Component { static getPageMeta() { return { - title: 'Coaching | Data Skeptic' + title: `Coaching | Data Skeptic` } } diff --git a/shared/components/Projects.js b/shared/components/Projects.js index 527f1216..0267b419 100644 --- a/shared/components/Projects.js +++ b/shared/components/Projects.js @@ -14,7 +14,7 @@ class Projects extends Component { static getPageMeta() { return { - title: 'Projects | Data Skeptic' + title: `Projects | Data Skeptic` } } diff --git a/shared/components/Services.jsx b/shared/components/Services.jsx index c0b05bad..fb504730 100644 --- a/shared/components/Services.jsx +++ b/shared/components/Services.jsx @@ -19,7 +19,7 @@ class Services extends React.Component { static getPageMeta() { return { - title: 'Services | Data Skeptic' + title: `Services | Data Skeptic` } } diff --git a/shared/components/Store.js b/shared/components/Store.js index c2bb558b..6669182c 100644 --- a/shared/components/Store.js +++ b/shared/components/Store.js @@ -26,7 +26,7 @@ class Store extends React.Component { static getPageMeta() { return { - title: 'Store | Data Skeptic' + title: `Store | Data Skeptic` } } From d4abaebed56b89fe0c0458eafff2dec290c7e168 Mon Sep 17 00:00:00 2001 From: glozhkovoy Date: Thu, 4 Jan 2018 12:20:52 +0200 Subject: [PATCH 2/2] Trying to update meta population with the new reducer --- shared/Blog/Routes/BlogRouter.js | 36 ++++++++++++++++---------------- views/index.ejs | 5 +++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/shared/Blog/Routes/BlogRouter.js b/shared/Blog/Routes/BlogRouter.js index 44a16279..35f8ffa1 100644 --- a/shared/Blog/Routes/BlogRouter.js +++ b/shared/Blog/Routes/BlogRouter.js @@ -41,8 +41,6 @@ class BlogRouter extends React.Component { console.log(payload) dispatch({type: "CMS_LOAD_RECENT_BLOGS", payload }) } - //const {title} = BlogRouter.getPageMeta(this.props); - //dispatch(changePageTitle(title)); } componentWillReceiveProps(nextProps) { @@ -63,25 +61,27 @@ class BlogRouter extends React.Component { } static getPageMeta(state) { - const isExists = state.blogs.getIn(['blog_focus', 'blog']); - if (!isExists) { - return { - title: 'Data Skeptic', - description: '' - } - } + var ocms = state.cms.toJS() + var blogs = ocms['recent_blogs'] + + let meta = {} - const post = state.blogs.getIn(['blog_focus', 'blog']).toJS(); - const isEpisode = !isUndefined(post.guid); + if (blogs.length === 0) { + return { + title: 'Blog Not Found' + } + } - let meta = { - //title: `${post.title} | Data Skeptic`, - title: `Data Skeptic`, - description: `${post.desc}` - }; + if (blogs.length === 1) { + const post = blogs[0] + const isEpisode = !isUndefined(post.guid) - if (isEpisode) { - meta.image = post.preview; + meta.title = `Data Skeptic` + meta.description = post.desc + + if (isEpisode) { + meta.image = post.preview; + } } return meta; diff --git a/views/index.ejs b/views/index.ejs index fb8f6edd..e56eef3c 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -8,9 +8,10 @@ <%- meta.title %> - - + <% if(meta.description){ %><% } %> + <% if(meta.description){ %><% } %> + <% if(meta.image){ %><% } %> <%- env === 'prod' ? '' : '' -%>