Skip to content

Commit 3322f9d

Browse files
authored
Telegraph article (MailOnline#22)
* Added a system to configure on a per client basis any page selectors our player can hook onto * Added telegraph article body detection and attaching to it * Add telegraph selector detection. * Separate client configuration into a separate file
1 parent abd8b7d commit 3322f9d

6 files changed

Lines changed: 147 additions & 80 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ jspm_packages
4646

4747
# Others
4848
.DS_store
49+
stats.json
50+
report.html

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"sass-loader": "^6.0.3",
6464
"script-loader": "^0.7.0",
6565
"style-loader": "^0.16.1",
66-
"webpack": "^2.3.3",
66+
"webpack": "^3.0.0",
67+
"webpack-bundle-analyzer": "^2.8.2",
6768
"webpack-dev-server": "^2.4.2"
6869
}
6970
}

src/App.jsx

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,10 @@ import throttle from 'lodash/throttle';
33
import 'whatwg-fetch';
44

55
import Player from './Player';
6+
import * as clientUtils from './client';
67

78
const Modernizr = window.suggestv.Modernizr;
8-
9-
/**
10-
* Retrieve the current client based on the current URL we are in
11-
* @returns {*}
12-
*/
13-
function getClient() {
14-
const href = window.location.href;
15-
16-
if (urlMatch('localhost')) return 'localhost';
17-
if (urlMatch(['delta.sugges.tv/test/index', 'build.suggestv.io/test/index', 'build.suggestv.io/test/cjallen'])) return 'test';
18-
if (urlMatch(['delta.sugges.tv/test', 'build.suggestv.io/test'])) return 'client-test';
19-
if (urlMatch('telegraph.co.uk')) return 'telegraph';
20-
if (urlMatch('londontheinside.com')) return 'londontheinside';
21-
if (urlMatch('beautyandthedirt.com')) return 'beautyandthedirt';
22-
if (urlMatch('bristol-sport.co.uk')) return 'bristolsport';
23-
if (urlMatch('proactiveinvestors.co.uk')) return 'proactiveinvestors';
24-
if (urlMatch('advfn.com')) return 'advfn';
25-
if (urlMatch('hospitalitytrends.net')) return 'hospitalitytrends';
26-
if (urlMatch('prospectmagazine.co.uk')) return 'prospectmagazine';
27-
if (urlMatch('spectator.co.uk')) return 'spectator';
28-
if (urlMatch('cityam.com')) return 'cityam';
29-
if (urlMatch('hitc.com')) return 'hitc';
30-
if (urlMatch('zmescience.com')) return 'sovrnus';
31-
if (urlMatch(['livingly.com', 'independent.ie'])) return 'sovrnuk';
32-
if (urlMatch('clickon.co')) return 'clickon';
33-
if (urlMatch(['lbc.co.uk', 'classicfm.com', 'capitalfm.com', 'heart.co.uk'])) return 'global-radio';
34-
35-
function urlMatch(url) {
36-
return Array.isArray(url)
37-
? url.some(u => href.indexOf(u) !== -1)
38-
: href.indexOf(url) !== -1;
39-
}
40-
41-
return 'unknown';
42-
}
43-
44-
const CLIENT = getClient();
9+
const CLIENT = clientUtils.getClient();
4510

4611
class App extends React.Component {
4712
static getVideos(url, client) {
@@ -166,26 +131,23 @@ class App extends React.Component {
166131

167132
setVideos(data) {
168133
const videos = [];
169-
const SCORE_LIMIT = 15;
170134
this.setState({ query: data.keywords });
171135

172136
if (data !== null && data.results && data.results.length > 0) {
173137

174138
data.results.forEach((video) => {
175139
const fields = video.fields;
176140

177-
if (Number(fields._score[0]) > SCORE_LIMIT) {
178-
videos.push({
179-
sources: [{
180-
src: fields.sources[0],
181-
type: 'video/mp4',
182-
}],
183-
poster: fields.poster[0],
184-
title: fields.title[0],
185-
description: fields.description[0],
186-
videoId: video.id,
187-
});
188-
}
141+
videos.push({
142+
sources: [{
143+
src: fields.sources[0],
144+
type: 'video/mp4',
145+
}],
146+
poster: fields.poster[0],
147+
title: fields.title[0],
148+
description: fields.description[0],
149+
videoId: video.id,
150+
});
189151
});
190152

191153
if (videos.length !== 0) {

src/main.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ import ReactDOM from 'react-dom';
33
import './modernizr-flash';
44

55
import App from './App';
6+
import * as clientUtils from './client';
67

78
require('./video.scss');
89
require('./telegraph-player.scss');
910

10-
const container = document.getElementById('suggestvplayer');
11+
let container = document.getElementById('suggestvplayer');
12+
let client = clientUtils.getClient();
13+
let selector = clientUtils.getPageSelector(client);
14+
15+
// Some clients rely on being appended to a special article body rather than an explicit id tag
16+
if (!container && selector) {
17+
console.log('SUGGESTV: No Suggestvplayer element');
18+
console.log('SUGGESTV: Detected client specfic selector - attaching to it');
19+
container = document.createElement('div');
20+
container.id = 'suggestvplayer';
21+
selector.appendChild(container);
22+
}
1123

1224
if (container) {
1325
const links = [
@@ -31,4 +43,3 @@ if (container) {
3143
} else {
3244
console.log('SUGGESTV: No player found');
3345
}
34-

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const webpack = require('webpack');
22
const ExtractTextPlugin = require('extract-text-webpack-plugin');
3+
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
34

45
// Set-up and create plugins
56
const videoJsProvider = new webpack.ProvidePlugin({
@@ -52,9 +53,9 @@ module.exports = {
5253
plugins: [
5354
extractSass,
5455
videoJsProvider,
56+
new BundleAnalyzerPlugin({ analyzerMode: 'disabled' })
5557
],
5658
resolve: {
5759
extensions: ['.js', '.jsx'],
5860
},
5961
};
60-

0 commit comments

Comments
 (0)