Last active
January 27, 2021 23:33
-
-
Save karlguillotte/b947fd0fdef82cd0f2dcc2204314370d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| async function main(lang) { | |
| const name = await getSponsorName() | |
| return await getSponsorData(name, lang) | |
| } | |
| async function getSponsorName() { | |
| const date = new Date() | |
| const url = API + '/static/sponsors/' + date.toISOString().substr(0, 10) | |
| const sponsors = await get(url) | |
| return sponsors.AvQForecast | |
| } | |
| async function getSponsorData(sponsorName = 'avalanche-quebec', lang = '*') { | |
| const { refs } = await get(PRISMIC) | |
| const { ref } = refs.find(ref => ref.isMasterRef) | |
| const url = `${PRISMIC}/documents/search?page=1&${lang}&q=%5B%5B%3Ad+%3D+at%28my.sponsor.uid%2C+%22${sponsorName}%22%29%5D%5D&ref=${ref}` | |
| const { results } = await get(url) | |
| const [{ data }] = results | |
| return { | |
| name: data.name, | |
| url: data.url, | |
| description: data.description, | |
| image: data['image-229'], | |
| } | |
| } | |
| // Utils | |
| async function get(url) { | |
| const response = await fetch(url) | |
| return await response.json() | |
| } | |
| // Constants | |
| const API = 'https://avalanche.ca/api' | |
| const PRISMIC = 'https://avalancheca.cdn.prismic.io/api/v2' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Désolé, il y a 8 caractères par tab. Il doit y avoir un bogue dans gist qui m'empêche de le changer.