diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-07-14 21:07:43 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-07-14 21:07:43 +0300 |
| commit | 93fbeff2d443d4149fc944f1df435d42cbb6bb51 (patch) | |
| tree | bc06dd5a7233842b3ca087a64c5c1dc4e63390b8 /build.js | |
| parent | a60fc265be51d77c50c75202c663e9d7ff1e0c84 (diff) | |
Rework gallery build
Diffstat (limited to 'build.js')
| -rw-r--r-- | build.js | 28 |
1 files changed, 12 insertions, 16 deletions
@@ -17,39 +17,35 @@ function transpose(matrix) { return matrix[0].map((col, i) => matrix.map(row => row[i]));
}
-const GALLERY_DIR = "_gallery";
const SITE_CONFIG_DIR = "_configuration";
const SRC_DIR = "src";
const DIST_DIR = "dist";
const HTML_TEMP_PATH = path.join(SRC_DIR, "index.html.mustache");
const HTML_OUT_PATH = path.join(DIST_DIR, "index.html");
const CONTACT_INFO_PATH = path.join(SITE_CONFIG_DIR, "contact_info.json");
+const GALLERIES_PATH = path.join(SITE_CONFIG_DIR, "galleries.json");
fs.rmSync(DIST_DIR, { recursive: true, force: true });
fs.cpSync(SRC_DIR, DIST_DIR, { recursive: true });
const htmlTemplate = fs.readFileSync(HTML_TEMP_PATH, "utf-8");
-let galleryJsonList = [];
-try {
- galleryJsonList = fs.readdirSync(GALLERY_DIR);
-} catch (err) {
- if (err.message?.includes("ENOENT")) {
- console.warn("Could not read galleries, using empty list.");
- } else {
- throw err;
- }
-}
-
-const galleryViews = galleryJsonList
- .map((fileName) => fs.readFileSync(path.join(GALLERY_DIR, fileName), "utf-8"))
- .map(JSON.parse)
+const galleriesJson = fs.readFileSync(GALLERIES_PATH, "utf-8");
+const galleriesView = JSON.parse(galleriesJson)
+const galleryViews = galleriesView["galleries"]
.map((gallery) => {
// If display_title is "-", do not render a title. Netlify CMS doesn't support optionals well.
const display_title = gallery["display_title"].trim() !== "-"
? gallery["display_title"]
: undefined;
- const rows = sliceIntoChunks(gallery["images"], gallery["column_count"]);
+
+ const images = gallery["images"];
+ const columnCount = gallery["column_count"];
+ while (images.length < columnCount) {
+ images.push(null);
+ }
+
+ const rows = sliceIntoChunks(images, columnCount);
const columns = transpose(rows);
return {
...gallery,
|
