forked from PGATOUR/franklin-the-players
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dc8a9b
commit c23a3bf
Showing
3 changed files
with
119 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,80 @@ | ||
.news { | ||
margin: 64px auto; | ||
background-color: lightgray; | ||
min-height: 256px; | ||
margin: 16px; | ||
} | ||
|
||
.news > ul { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); | ||
grid-gap: 16px; | ||
} | ||
|
||
.news > ul > li { | ||
position: relative; | ||
} | ||
|
||
.news .news-item-body a:any-link { | ||
color: inherit; | ||
} | ||
|
||
.news .news-item-body { | ||
padding: 16px; | ||
aspect-ratio: 1; | ||
color: white; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
align-items: flex-end; | ||
background: linear-gradient( #0000, #0008) | ||
} | ||
|
||
.news .news-item-image { | ||
line-height: 0; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: -1; | ||
} | ||
|
||
.news .news-item-image img { | ||
height: 100%; | ||
width: 100%; | ||
object-fit: cover; | ||
} | ||
|
||
.news .news-item-play { | ||
color: white; | ||
line-height: 0; | ||
position: absolute; | ||
top: 50%; | ||
bottom: 0; | ||
left: 50%; | ||
right: 0; | ||
box-sizing: border-box; | ||
display: block; | ||
width: 100px; | ||
height: 100px; | ||
border: 2px solid; | ||
border-radius: 100px; | ||
transform: translate(-50%, -50%) | ||
} | ||
|
||
.news-item-play::before { | ||
content: ""; | ||
display: block; | ||
box-sizing: border-box; | ||
position: absolute; | ||
width: 0; | ||
height: 50px; | ||
border-top: 25px solid transparent; | ||
border-bottom: 25px solid transparent; | ||
border-left: 36px solid; | ||
top: 24px; | ||
left: 38px; | ||
} | ||
|
||
.news .news-item-body > *:first-child { | ||
margin-top: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
export default function decorate(block) { | ||
const newsURL = block.querySelector('a').href; | ||
console.log('news URL:', newsURL); | ||
block.innerHTML = `<a href="${newsURL}">News from ${newsURL}</a>`; | ||
import { readBlockConfig } from '../../scripts/scripts.js'; | ||
|
||
export default async function decorate(block) { | ||
const videoPrefix = 'https://pga-tour-res.cloudinary.com/image/upload/c_fill,f_auto,g_face,h_311,q_auto,w_425/v1/'; | ||
const damPrefix = 'https://www.pgatour.com'; | ||
const config = readBlockConfig(block); | ||
const newsURL = config.source; | ||
const limit = config.limit || 12; | ||
block.textContent = ''; | ||
/* add CORS header, to be replaced with direct API */ | ||
const directURL = `${newsURL}/lang=LANG_NOT_DEFINED&path=/content&tags=PGATOUR:Tournaments/2018/r011+PGATOUR:Tournaments/2020/r011+PGATOUR:Tournaments/2019/r011+PGATOUR:Tournaments/2021/r011+PGATOUR:Tournaments/2022/r011&size=${limit}`; | ||
const resp = await fetch(`https://little-forest-58aa.david8603.workers.dev/?url=${encodeURIComponent(directURL)}`); | ||
const json = await resp.json(); | ||
const ul = document.createElement('ul'); | ||
json.items.forEach((item) => { | ||
const prefix = item.image.startsWith('brightcove') ? videoPrefix : damPrefix; | ||
const li = document.createElement('li'); | ||
li.className = 'news-item'; | ||
const video = item.videoId ? '<div class="news-item-play"></div>' : ''; | ||
li.innerHTML = ` | ||
<div class="news-item-image"><img src="${prefix}${item.image}"></div> | ||
<div class="news-item-body"><a href="${item.link}">${item.title}</a></div> | ||
${video} | ||
`; | ||
ul.append(li); | ||
}); | ||
block.append(ul); | ||
} |