-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eleventy): provide the url filter in the visual editor
`{{ "/url" | url }}` will now work in the visual editor, provided you pass a `pathPrefix` option to the `pluginBookshop()` function inside your `.eleventy.js`.
- Loading branch information
Showing
10 changed files
with
170 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
javascript-modules/engines/eleventy-engine/lib/plugins/url.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export default (meta) => function (Liquid) { | ||
this.registerFilter('url', (url) => { | ||
url = url || ""; | ||
|
||
// Intentionally less-accurate than 11ty implementation. Works in most cases. | ||
if (url.startsWith('/') && !url.startsWith('//')) { | ||
if (meta.pathPrefix === undefined || typeof meta.pathPrefix !== "string") { | ||
// When you retrieve this with config.getFilter("url") it | ||
// grabs the pathPrefix argument from your config for you. | ||
console.error([ | ||
`The Eleventy Bookshop plugin needs to be supplied a pathPrefix in order to use the url filter.`, | ||
`e.g. in .eleventy.js:`, | ||
``, | ||
`eleventyConfig.addPlugin(pluginBookshop({`, | ||
` bookshopLocations: <. . .>,`, | ||
` pathPrefix: "/documentation/"`, | ||
` }));`, | ||
].join('\n')) | ||
throw new Error("pathPrefix (String) is required in the `url` filter. This should be supplied "); | ||
} | ||
|
||
const baseurl = meta.pathPrefix || ''; | ||
return `${baseurl}${url}`.replace(/\/\//g, '/'); | ||
} | ||
return url; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters