Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
cjtantay committed Jul 1, 2024
1 parent 2b470dd commit 05ab43b
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions 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} layouts
* @property {{[key: string]: (...args) => unknown}} [nunjucksVariables]
* @property {{[key: string]: (...args) => unknown}} [nunjucksFilters]
* @property {function(string): function(Object.<string, string>[]): Object.<string, string>[]} nunjucksFilters.prepareCrosswalk
* @property {{[key: string]: (...args) => unknown}} [nunjucksTags]
* @property {{[key: string]: (...args) => unknown}} [minifyOptions]
* @property {string} output
Expand Down Expand Up @@ -213,15 +214,15 @@ export class Baker extends EventEmitter {

// if an object of custom nunjucks filters was provided, add them now
if (nunjucksFilters) {
if (crosswalkPath && nunjucksFilters.prepareCrosswalk) {
throw new Error('crosswalkPath and prepareCrosswalk cannot both be defined in 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 (crosswalkPath && !nunjucksFilters.prepareCrosswalk) {
nunjucksFilters.prepareCrosswalk = this.prepareCrosswalk(crosswalkPath);
}

this.nunjucks.addCustomFilters(nunjucksFilters);
}

Expand Down Expand Up @@ -483,11 +484,21 @@ export class Baker extends EventEmitter {
this.emit('bake:end');
}

/**
* Prepares a function to process crosswalk image paths.
* @param {string} crosswalkPath - The base path for crosswalk images.
* @returns {Function} A function that maps over data entries to update image paths.
*/
prepareCrosswalk(/** @type {string} */ crosswalkPath) {
// set absolute path for crosswalk images
/**
* Processes data entries to set appropriate paths for images.
* @param {Object.<string, string>[]} data - Array of objects, each containing image references.
* @returns {Object.<string, string>[]} The data with updated image paths.
*/
return function setCrosswalkPath(
/** @type {Object.<string, string>[]} */ data
) {
/** @type {Object.<string, string>[]} */ data
return data.map((d) => {
const relativeStaticPath = this.getStaticPath(
join(crosswalkPath, d.img)
Expand Down

0 comments on commit 05ab43b

Please sign in to comment.