Skip to content

Commit

Permalink
images.json generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementCariou committed Jan 31, 2021
1 parent b6f32db commit 815877e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ dist

# Build file
build.html
images/images.json
11 changes: 11 additions & 0 deletions images/generateList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs');

fs.readdir('./images', (err, files) => {
files = files.filter(file => !file.endsWith(".js") && !file.endsWith(".json"));
const list = files.map(file => ({
title: file.split('.').slice(0, -1).join('.'),
file,
}));
let json = JSON.stringify({images:list}, null, 4);
fs.writeFileSync('./images/images.json', json);
});
24 changes: 0 additions & 24 deletions images/images.json

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"version": "1.0.0",
"scripts": {
"start": "budo src/index.js",
"build": "browserify -p tinyify src/index.js | htmlify > build.html"
"build": "browserify -p tinyify src/index.js | htmlify > build.html",
"genList": "node images/generateList.js",
"prestart": "npm run genList",
"prebuild": "npm run genList"
},
"license": "MIT",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ npm build

## Using it with [local images](https://clementcariou.github.io/virtual-art-gallery/build?api=local)

You can access the local api using this URI params: ```?api=local```. You can change the displayed images and title modifying [images/images.json](images/images.json) and placing your images in the folder [images](images). You need to build the project apply changes on [images/images.json](images/images.json).
The local api is accessible using this URI params in the address bar: ```?api=local``` (it's possible to load automatically this API by changing the default API in the [api.js](api/api.js) file). You can change the displayed images in the folder [images](images), you will need to rebuild the project (or relauch the dev server) to apply the modifications.

## Evolutions

Expand Down

0 comments on commit 815877e

Please sign in to comment.