Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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}.`);

Expand Down
Loading