diff --git a/.github/workflows/preproduction.yml b/.github/workflows/preproduction.yml index be10ea5d..79053274 100644 --- a/.github/workflows/preproduction.yml +++ b/.github/workflows/preproduction.yml @@ -17,7 +17,7 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 cache: 'npm' - name: Build with Eleventy run: | diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 8f3fc3ce..9542615a 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -17,7 +17,7 @@ jobs: submodules: true - uses: actions/setup-node@v3 with: - node-version: 18 + node-version: 20 cache: 'npm' - name: Build with Eleventy run: | diff --git a/_data/awesome.js b/_data/awesome.js index fa1224e3..3ec78770 100644 --- a/_data/awesome.js +++ b/_data/awesome.js @@ -1,5 +1,18 @@ const EleventyFetch = require("@11ty/eleventy-fetch"); +const compareAwesomeScore = (a, b) => { + return b.awesomeScore - a.awesomeScore; +} + +const sortByAwesomeScoreOrName = (a, b) => { + const awesomeScoreDiff = compareAwesomeScore(a, b); + if (awesomeScoreDiff < 0 || awesomeScoreDiff > 0) { + return awesomeScoreDiff; + } else { + return a.name.localeCompare(b.name); + } +} + module.exports = async function () { const URL = "https://code.gouv.fr/data/awesome-codegouvfr.json"; @@ -8,5 +21,5 @@ module.exports = async function () { type: "json" }); - return awesome; + return awesome.toSorted(sortByAwesomeScoreOrName); }; \ No newline at end of file diff --git a/package.json b/package.json index 7f5bd838..5dec9fb5 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "license": "MIT", "engines": { - "node": ">=14" + "node": ">=20" }, "homepage": "https://code.gouv.fr/", "devDependencies": { diff --git a/public/js/home.js b/public/js/home.js index 50d98499..f73c860c 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -1,4 +1,6 @@ (() => { + const dataBaseUrl = `${window.location.origin}/internaldata`; + const random = (items) => { return items[Math.floor(Math.random() * items.length)]; } @@ -8,15 +10,17 @@ const sillSoftwareTitleLink = document.querySelector(".sill .fr-card__title a"); const sillSoftwareImg = document.querySelector(".sill .fr-card__header img"); + const sillDetailUrl = `https://code.gouv.fr/sill/detail`; + const getSill = async () => { - const response = await fetch(`${window.location.origin}/internaldata/sill.json`); + const response = await fetch(`${dataBaseUrl}/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}`; + sillSoftwareTitleLink.href = `${sillDetailUrl}?name=${randomSoftware.name}`; sillSoftwareImg.src = randomSoftware.logoUrl || randomSoftware.comptoirDuLibreSoftware?.logoUrl; sillSoftwareImg.alt = logoAltTemplate`${randomSoftware.name}`; }); @@ -24,15 +28,17 @@ const awesomeProjectTitleLink = document.querySelector(".awesome .fr-card__title a"); const awesomeProjectImg = document.querySelector(".awesome .fr-card__header img"); + const awesomeUrl = `${window.location.origin}/fr/awesome`; + const getAwesome = async () => { - const response = await fetch(`${window.location.origin}/internaldata/awesome.json`); + const response = await fetch(`${dataBaseUrl}/awesome.json`); return await response.json(); } getAwesome().then(awesomeProjects => { const randomProject= random(awesomeProjects); awesomeProjectTitleLink.textContent = randomProject.name; - awesomeProjectTitleLink.href = `${window.location.origin}/fr/awesome`; + awesomeProjectTitleLink.href = awesomeUrl; awesomeProjectImg.src = randomProject.logo; awesomeProjectImg.alt = logoAltTemplate`${randomProject.name}`; });