Skip to content

Commit

Permalink
support crosswalk absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtantay committed Jun 12, 2024
1 parent 5b448af commit e7aad5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/bake.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const defaultConfig = {
output: '_dist',
pathPrefix: '/',
staticRoot: '',
crosswalkPath: undefined,
};

function getDefaultFromConfig(module) {
Expand Down Expand Up @@ -94,6 +95,7 @@ async function prepareConfig(inputOptions) {
options.pathPrefix = resolver('pathPrefix');
options.staticRoot = resolver('staticRoot');
options.svelteCompilerOptions = resolver('svelteCompilerOptions');
options.crosswalkPath = resolver('crosswalkPath');

return options;
}
Expand Down
30 changes: 29 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { SassEngine } from './engines/sass.js';
* @property {string} output
* @property {string} pathPrefix
* @property {string} staticRoot
* @property {string} [crosswalkPath]
* @property {import('svelte/types/compiler/interfaces').CompileOptions} [svelteCompilerOptions]
*/

Expand All @@ -72,6 +73,7 @@ export class Baker extends EventEmitter {
output,
pathPrefix,
staticRoot,
crosswalkPath,
svelteCompilerOptions,
}) {
super();
Expand Down Expand Up @@ -206,7 +208,12 @@ export class Baker extends EventEmitter {

// if an object of custom nunjucks filters was provided, add them now
if (nunjucksFilters) {
this.nunjucks.addCustomFilters(nunjucksFilters);
// Use prepareCrosswalk from nunjucksFilters if available, otherwise check for crosswalkPath
if (nunjucksFilters.prepareCrosswalk) {
this.nunjucks.addCustomFilters(nunjucksFilters);
} else if (crosswalkPath) {
this.nunjucks.addCustomFilter('prepareCrosswalk', this.prepareCrosswalk(crosswalkPath));
}
}

// if an object of custom nunjucks tags was provided, add them now
Expand Down Expand Up @@ -466,4 +473,25 @@ export class Baker extends EventEmitter {
// emit event that a bake has completed
this.emit('bake:end');
}

prepareCrosswalk(
/** @type {string} */ path
) {
return function(
/** @type {Object.<string, string>[]} */ data
) {
return data.map((d) => {
if (d.img) {
return {
...d,
img: join(
process.env.BAKER_URL ?? '',
this.getStaticPath(join(path, d.img))
),
};
}
return { ...d };
});
}
}
}

0 comments on commit e7aad5e

Please sign in to comment.