This repository was archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharticleList.js
60 lines (56 loc) · 1.59 KB
/
articleList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Add list container to app
const articleList = addToElementbyId('div', 'article-list', app);
// Call for a list of all articles
deliveryClient
.items()
.type('article')
.toPromise()
.then(response => {
response.data.items.forEach(item => {
// Create nodes
const card = createElement('div', 'card');
card.classList.add('card-no-link-style');
const link = createElement(
'a',
'link',
'href',
'./article.html#' + item.elements.url_pattern.value
);
// Transform image
let transformedImageUrl = null;
if (item.elements.teaser_image.value.length) {
transformedImageUrl = Kk.transformImageUrl(item.elements.teaser_image.value[0].url).withDpr(2)
.withCompression('lossless')
.withHeight(300)
.withWidth(300)
.getUrl();
}
const teaser = createElement(
'img',
'article-teaser',
'src',
item.elements.teaser_image.value && item.elements.teaser_image.value.length
? item.elements.teaser_image.value[0].url + '?w=500&h=500'
: undefined
);
const title = createElement(
'h2',
'article-title',
'innerText',
item.elements.title.value
);
const description = createElement(
'div',
'article-description',
'innerHTML',
item.elements.summary.value
);
// Add nodes to DOM
articleList.appendChild(card);
card.appendChild(link);
link.append(teaser, title, description);
});
})
.catch(err => {
reportErrors(err);
});