-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reuse local communes.json, aides-collectivities.json files
Also, update miniatures generation by fetching images from github instead of using git submodules
- Loading branch information
1 parent
cbbea0b
commit f70d3bb
Showing
15 changed files
with
82 additions
and
123 deletions.
There are no files selected for viewing
Submodule aides-jeunes-repo
deleted from
553945
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,44 @@ | ||
/** | ||
* Download the images from github (aides-jeune repo) and create the miniatures | ||
* from them. | ||
*/ | ||
import fs from 'fs'; | ||
import { data } from '@betagouv/aides-velo'; | ||
import sharp from 'sharp'; | ||
import { join } from 'path'; | ||
|
||
import { writeJsonData } from '../scripts/writeData.js'; | ||
import aidesWithCollectivities from '../lib/data/aides-collectivities.json' assert { type: 'json' }; | ||
|
||
const currentPath = new URL('./', import.meta.url).pathname; | ||
const rootPath = join(currentPath, '../../'); | ||
|
||
const miniatureDirectory = join(rootPath, 'static/miniatures/'); | ||
if (fs.existsSync(miniatureDirectory)) { | ||
fs.rmSync(miniatureDirectory, { recursive: true }); | ||
} | ||
fs.mkdirSync(miniatureDirectory, { recursive: true }); | ||
|
||
const thumbnailsManifest = Object.keys(aidesWithCollectivities).reduce((acc, id) => { | ||
const imgSrc = data.miniatures[id]; | ||
|
||
if (!imgSrc) { | ||
return acc; | ||
} | ||
|
||
const imgName = imgSrc.split('/').at(-1).split('.')[0] + '.webp'; | ||
generateThumbnail(imgSrc, imgName); | ||
|
||
return { ...acc, [id]: imgName }; | ||
}, {}); | ||
|
||
async function generateThumbnail(imgSrc, imgName) { | ||
const resp = await fetch(imgSrc); | ||
const blob = await resp.blob(); | ||
const buffer = await blob.arrayBuffer(); | ||
const img = sharp(buffer); | ||
img.resize({ fit: 'inside', height: 170, width: 120 }); | ||
img.webp().toFile(join(miniatureDirectory, imgName)); | ||
} | ||
|
||
writeJsonData('miniatures.json', thumbnailsManifest); |
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,4 +1,3 @@ | ||
// TODO: to remove | ||
// await import('./transform-communes-data.js'); | ||
// await import('./associate-collectivities.js'); | ||
// await import('../../data-fetch/miniatures/extract-from-aides-jeunes.js'); | ||
await import('./transform-communes-data.js'); | ||
await import('./associate-collectivities.js'); | ||
await import('./generate-miniatures.js'); |