Skip to content

Commit

Permalink
Fixes for webc upgrades.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Apr 30, 2024
1 parent 41c49f2 commit 680c03d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions eleventy.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ function eleventyBundlePlugin(eleventyConfig, pluginOptions = {}) {
if(Array.isArray(pluginOptions.bundles)) {
debug("Adding bundles via `addPlugin`: %o", pluginOptions.bundles)
pluginOptions.bundles.forEach(name => {
let hoist = Array.isArray(pluginOptions.hoistDuplicateBundlesFor) && pluginOptions.hoistDuplicateBundlesFor.includes(name);
let isHoisting = Array.isArray(pluginOptions.hoistDuplicateBundlesFor) && pluginOptions.hoistDuplicateBundlesFor.includes(name);

eleventyConfig.addBundle(name, {
hoist,
hoist: isHoisting,
outputFileExtension: name, // default as `name`
shortcodeName: name, // `false` will skip shortcode
transforms: pluginOptions.transforms,
Expand Down
8 changes: 5 additions & 3 deletions eleventy.bundleManagers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ module.exports = function(eleventyConfig, pluginOptions = {}) {

// e.g. `css` shortcode to add code to page bundle
// These shortcode names are not configurable on purpose (for wider plugin compatibility)
eleventyConfig.addPairedShortcode(shortcodeName, function addContent(content, bucket, urlOverride) {
let url = urlOverride || this.page.url;
managers[name].addToPage(url, content, bucket);
eleventyConfig.addPairedShortcode(shortcodeName, function addContent(content, bucket, explicitUrl) {
let url = explicitUrl || this.page?.url;
if(url) { // don’t add if a file doesn’t have an output URL
managers[name].addToPage(url, content, bucket);
}
return "";
});
}
Expand Down
14 changes: 8 additions & 6 deletions eleventy.shortcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,29 @@ module.exports = function(eleventyConfig, pluginOptions = {}) {
// e.g. `getBundle` shortcode to get code in current page bundle
// bucket can be an array
// This shortcode name is not configurable on purpose (for wider plugin compatibility)
eleventyConfig.addShortcode("getBundle", function getContent(type, bucket) {
eleventyConfig.addShortcode("getBundle", function getContent(type, bucket, explicitUrl) {
if(!type || !(type in managers) || Object.keys(managers).length === 0) {
throw new Error(`Invalid bundle type: ${type}. Available options: ${Object.keys(managers)}`);
}

if(this.page.url) {
pagesUsingBundles[this.page.url] = true;
let url = explicitUrl || this.page?.url;
if(url) {
pagesUsingBundles[url] = true;
}

return OutOfOrderRender.getAssetKey("get", type, bucket);
});

// write a bundle to the file system
// This shortcode name is not configurable on purpose (for wider plugin compatibility)
eleventyConfig.addShortcode("getBundleFileUrl", function(type, bucket) {
eleventyConfig.addShortcode("getBundleFileUrl", function(type, bucket, explicitUrl) {
if(!type || !(type in managers) || Object.keys(managers).length === 0) {
throw new Error(`Invalid bundle type: ${type}. Available options: ${Object.keys(managers)}`);
}

if(this.page.url) {
pagesUsingBundles[this.page.url] = true;
let url = explicitUrl || this.page?.url;
if(url) {
pagesUsingBundles[url] = true;
}

return OutOfOrderRender.getAssetKey("file", type, bucket);
Expand Down

0 comments on commit 680c03d

Please sign in to comment.