@@ -15,6 +15,7 @@ import fs from 'fs';
1515import unirest from 'unirest' ;
1616import cheerio from 'cheerio' ;
1717import schedule from 'node-schedule' ;
18+ import { cleanTitle , defaultPluginSiteTitle , pluginSiteTitleSuffix } from './app/commons/helper' ;
1819
1920const app = express ( ) ;
2021const port = 5000 ;
@@ -35,6 +36,10 @@ app.use(jsPath, express.static('./dist/client'));
3536app . engine ( 'hbs' , exphbs ( { extname : '.hbs' } ) ) ;
3637app . set ( 'view engine' , 'hbs' ) ;
3738
39+
40+ const defaultPluginSiteDescription = 'Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software' ;
41+ const defaultPluginOpenGraphImage = 'https://jenkins.io/images/logo-title-opengraph.png'
42+
3843const downloadHeader = ( ) => {
3944 var headerFile = __HEADER_FILE__ ;
4045 if ( headerFile !== null && headerFile !== undefined ) {
@@ -57,6 +62,8 @@ const downloadHeader = () => {
5762 $ ( 'head' ) . prepend ( '{{> header }}' ) ;
5863 // Even though we're supplying our own this one still causes a conflict.
5964 $ ( 'link[href="https://jenkins.io/css/font-icons.css"]' ) . remove ( ) ;
65+ // 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.
66+ $ ( 'link[href="https://jenkins.io/site.webmanifest"]' ) . remove ( ) ;
6067 $ ( 'head' ) . append ( '<script>window.__REDUX_STATE__ = {{{reduxState}}};</script>' ) ;
6168 $ ( '#grid-box' ) . append ( '{{{rendered}}}' ) ;
6269 $ ( '#grid-box' ) . after ( '<script type="text/javascript" src="{{jsPath}}/main.js"></script>' ) ;
@@ -113,15 +120,22 @@ app.get('*', (req, res, next) => {
113120 const pluginSiteApiVersion = store . getState ( ) . data . info . commit . substring ( 0 , 7 ) ;
114121 const reduxState = JSON . stringify ( store . getState ( ) ) . replace ( / < / g, '\\x3c' ) ;
115122 const pluginNotFound = req . url !== '/' && store . getState ( ) . ui . plugin === null ;
123+ const title = store . getState ( ) . ui . plugin && store . getState ( ) . ui . plugin . title ? `${ cleanTitle ( store . getState ( ) . ui . plugin . title ) } - ${ pluginSiteTitleSuffix } ` : defaultPluginSiteTitle ;
124+ const description = store . getState ( ) . ui . plugin && store . getState ( ) . ui . plugin . excerpt ? store . getState ( ) . ui . plugin . excerpt : defaultPluginSiteDescription ;
125+ const opengraphImage = defaultPluginOpenGraphImage ; // TODO WEBSITE-645 add support for plugins to provide their own OG imag
126+
116127 res . status ( pluginNotFound ? 404 : 200 ) . render ( 'index' , {
117128 rendered,
129+ title,
130+ description,
118131 reduxState,
132+ opengraphImage,
119133 jsPath,
120134 pluginSiteVersion,
121135 pluginSiteApiVersion
122136 } ) ;
123137 } ) . catch ( ( err ) => {
124- console . error ( chalk . red ( error ) ) ;
138+ console . error ( chalk . red ( err ) ) ;
125139 res . sendStatus ( 404 ) ;
126140 } ) ;
127141 }
0 commit comments