forked from codegouvfr/eleventy-dsfr
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically update cards on home page
For sill random software and awesome random project
- Loading branch information
Showing
6 changed files
with
67 additions
and
25 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
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
permalink: /data/awesome.json | ||
--- | ||
{{ awesome | dump | safe }} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
permalink: /data/sill.json | ||
--- | ||
{{ sill | dump | safe }} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(() => { | ||
const random = (items) => { | ||
return items[Math.floor(Math.random() * items.length)]; | ||
} | ||
|
||
const logoAltTemplate = (strings, name) => `Logo de ${name}`; | ||
|
||
const sillSoftwareTitleLink = document.querySelector(".sill .fr-card__title a"); | ||
const sillSoftwareImg = document.querySelector(".sill .fr-card__header img"); | ||
|
||
const getSill = async () => { | ||
const response = await fetch(`${window.location.origin}/data/sill.json`); | ||
return await response.json(); | ||
} | ||
|
||
getSill().then(softwareList => { | ||
const randomSoftware= random(softwareList); | ||
sillSoftwareTitleLink.textContent = randomSoftware.name; | ||
sillSoftwareTitleLink.href = `https://code.gouv.fr/sill/detail?name=${randomSoftware.name}`; | ||
sillSoftwareImg.src = randomSoftware.logoUrl || randomSoftware.comptoirDuLibreSoftware?.logoUrl; | ||
sillSoftwareImg.alt = logoAltTemplate`${randomSoftware.name}`; | ||
}); | ||
|
||
const awesomeProjectTitleLink = document.querySelector(".awesome .fr-card__title a"); | ||
const awesomeProjectImg = document.querySelector(".awesome .fr-card__header img"); | ||
|
||
const getAwesome = async () => { | ||
const response = await fetch(`${window.location.origin}/data/awesome.json`); | ||
return await response.json(); | ||
} | ||
|
||
getAwesome().then(awesomeProjects => { | ||
const randomProject= random(awesomeProjects); | ||
awesomeProjectTitleLink.textContent = randomProject.name; | ||
awesomeProjectTitleLink.href = `${window.location.origin}/fr/awesome`; | ||
awesomeProjectImg.src = randomProject.logo; | ||
awesomeProjectImg.alt = logoAltTemplate`${randomProject.name}`; | ||
}); | ||
})(); |