Skip to content

Commit a66bb1b

Browse files
authored
Merge pull request #15 from mcclatchy/config-cadence
Moving the story cadence into the config layer.
2 parents 7e4c910 + 71bbe1f commit a66bb1b

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

config/story.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"base": ".story-body [id^=zone-el]",
33
"ignore": ["zone-el-16"],
4+
"cadence": {
5+
"subscriber": 4,
6+
"dma": 3,
7+
"standard": 2
8+
},
49
"zones": [
510
{
611
"id": "zone-taboola-recommendations",

demo/locker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ const locker = {
4242
// user info
4343
user: {
4444
isSubscriber() {
45-
return false;
45+
return true;
4646
},
4747

4848
isLoggedIn() {
4949
return false;
5050
},
5151

5252
isInDMA() {
53-
return Promise.resolve(true);
53+
return Promise.resolve(false);
5454
}
5555
},
5656

index.js

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ function distributeZones(locker) {
1010
// Setup
1111
zones.setLocker(locker);
1212

13-
// Configs
13+
// Config files
1414
if(!locker.config) {
1515
locker.config = {
1616
homepage: "/static/hi/zones/homepage.json",
17-
section: "/static/hi/zones/section.json",
17+
sectfront: "/static/hi/zones/section.json",
1818
story: "/static/hi/zones/story.json"
1919
}
2020
}
@@ -25,33 +25,22 @@ function distributeZones(locker) {
2525
// Give the performance team a promise
2626
return new Promise((resolve, reject) => {
2727
locker.executeWhenDOMReady(async () => {
28-
switch(locker.pageType) {
29-
case "story":
30-
await config.load(locker.config.story);
31-
32-
// Set cadence for subscriber vs. nonsubscriber vs. nonsubscriber out of market in test domains
33-
const subscriber = locker.user.isSubscriber();
34-
const dma = subscriber ? true : await locker.user.isInDMA();
35-
const nonsubscriberOutOfMarket = !subscriber && !dma;
36-
const domainName = locker.getConfig('domainName');
37-
const allowedDomains = ["www.bnd.com", "www.myrtlebeachonline.com"];
38-
const cadence = allowedDomains.includes(domainName) && nonsubscriberOutOfMarket ? 2 : (subscriber ? 4 : 3);
39-
40-
zones.distribute(cadence);
41-
42-
// Temporary cleanup
43-
story.cleanup();
44-
break;
45-
case "homepage":
46-
await config.load(locker.config.homepage);
47-
break;
48-
case "sectfront":
49-
await config.load(locker.config.section);
50-
break;
51-
default:
52-
reject("not a matching page type");
28+
// Config keys match pageType coming from Yozons
29+
const file = locker.config[locker.pageType];
30+
31+
// Load config file
32+
if(file) {
33+
await config.load(file);
34+
} else {
35+
reject("not a matching page type");
5336
}
5437

38+
// Temporary cleanup
39+
if(locker.pageType == "story") {
40+
story.cleanup();
41+
}
42+
43+
// Render and resolve
5544
zones.render();
5645
resolve("zones-loaded")
5746
});

lib/config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* JSON configuration support
33
*/
44

5-
import { locker, Zone, ignore } from "./zones.js";
5+
import { locker, Zone, ignore, distribute } from "./zones.js";
66

77
/**
88
* Loads a configuration file
@@ -14,6 +14,7 @@ export function load(url) {
1414
return new Promise(async (resolve, reject) => {
1515
const res = await fetch(url);
1616
const data = await res.json();
17+
const template = locker.pageType;
1718
const subscriber = locker.user.isSubscriber();
1819
const dma = subscriber ? true : await locker.user.isInDMA();
1920

@@ -135,6 +136,24 @@ export function load(url) {
135136
}
136137
});
137138

139+
// Story page cadence distribution
140+
if(locker.pageType == "story") {
141+
let cadence;
142+
143+
switch(true) {
144+
case subscriber:
145+
cadence = data.cadence.subscriber;
146+
break;
147+
case dma:
148+
cadence = data.cadence.dma;
149+
break
150+
default:
151+
cadence = data.cadence.standard;
152+
}
153+
154+
distribute(cadence);
155+
}
156+
138157
resolve();
139158
});
140159
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mcclatchy/zones",
3-
"version": "1.6.1",
3+
"version": "1.7.0",
44
"description": "A Yozons extension to dynamically distribute or re-distribute zones on the websites.",
55
"main": "index.js",
66
"directories": {

0 commit comments

Comments
 (0)