Skip to content

Commit 9afd43f

Browse files
authored
Merge pull request #8 from mcclatchy/cue-public-api
Cue public api
2 parents f34ca47 + 8a4a0f0 commit 9afd43f

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

demo/locker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ const locker = {
1414
// generic pageInfo getter
1515
getConfig(key) {
1616
switch(key) {
17+
case "domainName":
18+
return "www.kansascity.com";
19+
case "articleCredit":
20+
return "The Kansas City Star";
1721
case "marketInfo.domain":
1822
return "miamiherald";
1923
case "marketInfo.taxonomy":
2024
return "News/Sports//";
21-
case "articleCredit":
22-
return "The Kansas City Star";
2325
case "zone.carousel":
2426
return true;
2527
case "zone.zeeto":

lib/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ export function load(url) {
9191
zone.zephr(feature);
9292
}
9393

94+
// CUE connection
95+
if(config.cue) {
96+
zone.cue(config.cue);
97+
}
98+
9499
// Add classes
95100
if(config.classList) {
96101
zone.classList.add(...config.classList)

lib/zones.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ export class Zone {
101101
}
102102
}
103103

104+
/*
105+
* CUE content item functionality
106+
* @param id {string} the content id in CUE
107+
*/
108+
109+
async cue(id) {
110+
const market = locker.getConfig("domainName");
111+
const endpoint = `https://${market}/webapi-public/v2/content/${id}`
112+
113+
const req = await fetch(endpoint);
114+
const response = await req.json();
115+
const payload = response.content;
116+
117+
if(payload) {
118+
const range = document.createRange().createContextualFragment(payload);
119+
this.element.append(range);
120+
} else {
121+
this.log("CUE payload was empty");
122+
}
123+
}
124+
104125
/*
105126
* Injects this zone
106127
* @param ele {element} the injection point

0 commit comments

Comments
 (0)