From e74f57051c646ea477a7e182be2cbab02df6b247 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 08:41:59 +0000 Subject: [PATCH 01/10] [WEBSITE-405] Use specific title and description Downstream of https://github.com/jenkins-infra/jenkins.io/pull/2674 --- server.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server.js b/server.js index 7c5af8cec..db4599c88 100644 --- a/server.js +++ b/server.js @@ -35,6 +35,10 @@ app.use(jsPath, express.static('./dist/client')); app.engine('hbs', exphbs({extname: '.hbs'})); app.set('view engine', 'hbs'); +const defaultPluginTitle = 'Jenkins Plugins'; +const defaultPluginDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software'; +const defaultPluginOpenGraphImage = 'https://jenkins.io/images/logo-title-opengraph.png' + const downloadHeader = () => { var headerFile = __HEADER_FILE__; if (headerFile !== null && headerFile !== undefined) { @@ -57,6 +61,8 @@ const downloadHeader = () => { $('head').prepend('{{> header }}'); // Even though we're supplying our own this one still causes a conflict. $('link[href="https://jenkins.io/css/font-icons.css"]').remove(); + // Prevents: Access to resource at 'https://jenkins.io/site.webmanifest' from origin 'https://plugins.jenkins.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. + $('link[href="https://jenkins.io/site.webmanifest"]').remove(); $('head').append(''); $('#grid-box').append('{{{rendered}}}'); $('#grid-box').after(''); @@ -113,9 +119,17 @@ app.get('*', (req, res, next) => { const pluginSiteApiVersion = store.getState().data.info.commit.substring(0, 7); const reduxState = JSON.stringify(store.getState()).replace(/ Date: Mon, 25 Nov 2019 08:49:01 +0000 Subject: [PATCH 02/10] Update server.js Co-Authored-By: Oleg Nenashev --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index db4599c88..7ae72c1d4 100644 --- a/server.js +++ b/server.js @@ -35,7 +35,7 @@ app.use(jsPath, express.static('./dist/client')); app.engine('hbs', exphbs({extname: '.hbs'})); app.set('view engine', 'hbs'); -const defaultPluginTitle = 'Jenkins Plugins'; +const defaultPluginSiteTitle = 'Jenkins Plugins'; const defaultPluginDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software'; const defaultPluginOpenGraphImage = 'https://jenkins.io/images/logo-title-opengraph.png' From 63590007f803ccb5c4eea712ba5e789f5071029c Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 08:50:01 +0000 Subject: [PATCH 03/10] Update server.js Co-Authored-By: Oleg Nenashev --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 7ae72c1d4..0061f7cf1 100644 --- a/server.js +++ b/server.js @@ -36,7 +36,7 @@ app.engine('hbs', exphbs({extname: '.hbs'})); app.set('view engine', 'hbs'); const defaultPluginSiteTitle = 'Jenkins Plugins'; -const defaultPluginDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software'; +const defaultPluginSiteDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software'; const defaultPluginOpenGraphImage = 'https://jenkins.io/images/logo-title-opengraph.png' const downloadHeader = () => { From 200bd524c13c7e877981857b444a6f77bf968db5 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 08:50:48 +0000 Subject: [PATCH 04/10] Update references --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 0061f7cf1..1ecdc7df9 100644 --- a/server.js +++ b/server.js @@ -120,8 +120,8 @@ app.get('*', (req, res, next) => { const reduxState = JSON.stringify(store.getState()).replace(/ Date: Mon, 25 Nov 2019 08:52:38 +0000 Subject: [PATCH 05/10] Add ticket link --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 1ecdc7df9..0107d596c 100644 --- a/server.js +++ b/server.js @@ -122,7 +122,7 @@ app.get('*', (req, res, next) => { const title = store.getState().ui.plugin && store.getState().ui.plugin.title ? `${store.getState().ui.plugin.title} - Jenkins plugin` : defaultPluginSiteTitle; const description = store.getState().ui.plugin && store.getState().ui.plugin.excerpt ? store.getState().ui.plugin.excerpt : defaultPluginSiteDescription; - const opengraphImage = defaultPluginOpenGraphImage; // TODO add support for plugins to provide their own OG imag + const opengraphImage = defaultPluginOpenGraphImage; // TODO WEBSITE-645 add support for plugins to provide their own OG imag res.status(pluginNotFound ? 404 : 200).render('index', { rendered, From 9f4776d414f76f36f76345797a1413af5cf23bf9 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 15:39:59 +0000 Subject: [PATCH 06/10] Ensure error is printed to logs --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 0107d596c..3f576e55b 100644 --- a/server.js +++ b/server.js @@ -135,7 +135,7 @@ app.get('*', (req, res, next) => { pluginSiteApiVersion }); }).catch((err) => { - console.error(chalk.red(error)); + console.error(chalk.red(err)); res.sendStatus(404); }); } From 38d128c41596d5760833ff9238c9ff53d6f9013f Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 15:46:11 +0000 Subject: [PATCH 07/10] Fix title not updating during navigation --- app/components/PluginDetail.jsx | 4 ++++ server.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/components/PluginDetail.jsx b/app/components/PluginDetail.jsx index 6bac24c12..2ae821aeb 100644 --- a/app/components/PluginDetail.jsx +++ b/app/components/PluginDetail.jsx @@ -310,6 +310,10 @@ class PluginDetail extends React.PureComponent { return ; } } + + if (typeof document !== 'undefined') { + document.title = cleanTitle(plugin.title); + } const beforeClose = this.closeDialog; return ( diff --git a/server.js b/server.js index 3f576e55b..a0a7e6152 100644 --- a/server.js +++ b/server.js @@ -15,6 +15,7 @@ import fs from 'fs'; import unirest from 'unirest'; import cheerio from 'cheerio'; import schedule from 'node-schedule'; +import { cleanTitle } from './app/commons/helper'; const app = express(); const port = 5000; @@ -119,8 +120,7 @@ app.get('*', (req, res, next) => { const pluginSiteApiVersion = store.getState().data.info.commit.substring(0, 7); const reduxState = JSON.stringify(store.getState()).replace(/ Date: Mon, 25 Nov 2019 20:53:47 +0000 Subject: [PATCH 08/10] Include full title when rendered via react --- app/components/PluginDetail.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/PluginDetail.jsx b/app/components/PluginDetail.jsx index 2ae821aeb..05d919199 100644 --- a/app/components/PluginDetail.jsx +++ b/app/components/PluginDetail.jsx @@ -312,7 +312,7 @@ class PluginDetail extends React.PureComponent { } if (typeof document !== 'undefined') { - document.title = cleanTitle(plugin.title); + document.title = `${cleanTitle(plugin.title)} - Jenkins plugin`; } const beforeClose = this.closeDialog; return ( From ae4ee5c79699f2b055919173184ba443194298fc Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Mon, 25 Nov 2019 21:03:37 +0000 Subject: [PATCH 09/10] Reset main component title --- app/components/Main.jsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/components/Main.jsx b/app/components/Main.jsx index 75cd01abd..7a8f61aa2 100644 --- a/app/components/Main.jsx +++ b/app/components/Main.jsx @@ -77,6 +77,10 @@ class Main extends React.PureComponent { } render() { + if (typeof document !== 'undefined') { + document.title = 'Jenkins Plugins'; + } + return (
Date: Mon, 25 Nov 2019 21:18:06 +0000 Subject: [PATCH 10/10] Extract fields so no duplication --- app/commons/helper.js | 3 +++ app/components/Main.jsx | 3 ++- app/components/PluginDetail.jsx | 4 ++-- server.js | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/commons/helper.js b/app/commons/helper.js index caac13b05..6106451ca 100644 --- a/app/commons/helper.js +++ b/app/commons/helper.js @@ -15,3 +15,6 @@ export function cleanTitle(title) { .replace(' for Jenkins','') .replace('Hudson ',''); } + +export const defaultPluginSiteTitle = 'Jenkins Plugins'; +export const pluginSiteTitleSuffix = 'Jenkins plugin'; diff --git a/app/components/Main.jsx b/app/components/Main.jsx index 7a8f61aa2..356ac2628 100644 --- a/app/components/Main.jsx +++ b/app/components/Main.jsx @@ -10,6 +10,7 @@ import Views from './Views'; import { actions } from '../actions'; import { isFiltered, showFilter, showResults, view } from '../selectors'; import { createSelector } from 'reselect'; +import { defaultPluginSiteTitle } from '../commons/helper'; class Main extends React.PureComponent { @@ -78,7 +79,7 @@ class Main extends React.PureComponent { render() { if (typeof document !== 'undefined') { - document.title = 'Jenkins Plugins'; + document.title = defaultPluginSiteTitle; } return ( diff --git a/app/components/PluginDetail.jsx b/app/components/PluginDetail.jsx index 05d919199..78b8b29e3 100644 --- a/app/components/PluginDetail.jsx +++ b/app/components/PluginDetail.jsx @@ -6,7 +6,7 @@ import moment from 'moment'; import LineChart from './LineChart'; import NotFound from './NotFound'; import Spinner from './Spinner'; -import { cleanTitle } from '../commons/helper'; +import { cleanTitle, pluginSiteTitleSuffix } from '../commons/helper'; import { firstVisit, isFetchingPlugin, labels, plugin } from '../selectors'; import { actions } from '../actions'; import { createSelector } from 'reselect'; @@ -312,7 +312,7 @@ class PluginDetail extends React.PureComponent { } if (typeof document !== 'undefined') { - document.title = `${cleanTitle(plugin.title)} - Jenkins plugin`; + document.title = `${cleanTitle(plugin.title)} - ${pluginSiteTitleSuffix}`; } const beforeClose = this.closeDialog; return ( diff --git a/server.js b/server.js index a0a7e6152..5086ec9d8 100644 --- a/server.js +++ b/server.js @@ -15,7 +15,7 @@ import fs from 'fs'; import unirest from 'unirest'; import cheerio from 'cheerio'; import schedule from 'node-schedule'; -import { cleanTitle } from './app/commons/helper'; +import { cleanTitle, defaultPluginSiteTitle, pluginSiteTitleSuffix } from './app/commons/helper'; const app = express(); const port = 5000; @@ -36,7 +36,7 @@ app.use(jsPath, express.static('./dist/client')); app.engine('hbs', exphbs({extname: '.hbs'})); app.set('view engine', 'hbs'); -const defaultPluginSiteTitle = 'Jenkins Plugins'; + const defaultPluginSiteDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software'; const defaultPluginOpenGraphImage = 'https://jenkins.io/images/logo-title-opengraph.png' @@ -120,7 +120,7 @@ app.get('*', (req, res, next) => { const pluginSiteApiVersion = store.getState().data.info.commit.substring(0, 7); const reduxState = JSON.stringify(store.getState()).replace(/