diff --git a/.gitignore b/.gitignore index e35a0405..5e98297d 100644 --- a/.gitignore +++ b/.gitignore @@ -89,6 +89,7 @@ typings/ # example directories to ignore example/_dist example/_screenshot +example/_fallbacks example/.DS_Store example-simple/_dist example-simple/.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index 4112c2e2..b3dbfc75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.47.7] - 2024-02-13 +- Added strict timestamp check to fallback image uploads and updated fallback upload step in deploy workflow + ## [0.47.6] - 2025-01-15 ### Changed diff --git a/lib/index.js b/lib/index.js index ed72a2b3..16afb8a1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,6 @@ // native import EventEmitter from 'events'; -import { readdir } from 'fs'; +import { readdir, mkdirSync } from 'fs'; import path, { join, resolve } from 'path'; // packages @@ -39,6 +39,8 @@ import { NunjucksEngine } from './engines/nunjucks.js'; import { RollupEngine } from './engines/rollup.js'; import { SassEngine } from './engines/sass.js'; +const FALLBACKS_DIR = '_fallbacks'; + const CROSSWALK_ALLOWED_ASSET_TYPES = [ 'img', 'aud', @@ -435,11 +437,15 @@ export class Baker extends EventEmitter { await page.waitForNetworkIdle(); // store the fallback image in the _dist directory - const screenshotEmbedDir = join(this.output, embedPath) - .split('/') - .slice(0, -1) - .join('/') - .replace('_screenshot', '_dist'); + const parentDir = path.dirname(this.output); + const fallbacksDir = join(parentDir, FALLBACKS_DIR); + const screenshotEmbedDir = path.join( + fallbacksDir, + path.dirname(embedPath) + ); + + mkdirSync(screenshotEmbedDir, { recursive: true }); + const screenshotStoragePath = join(screenshotEmbedDir, 'fallback.png'); console.log(`Storing the fallback image at: ${screenshotStoragePath}.`);