Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use pug options in v3 #16

Closed
peekxc opened this issue Aug 19, 2024 · 2 comments
Closed

How to use pug options in v3 #16

peekxc opened this issue Aug 19, 2024 · 2 comments

Comments

@peekxc
Copy link

peekxc commented Aug 19, 2024

To add arbitrary JS functions in V2 to pug, e.g.

eleventyConfig.addFilter("readingTime", (content) => {
    const stats = readingTime(content, { 'wordsPerMinute': 400 });
    return stats.text + ", " + stats.words + " words";
});

It was sufficient to add:

global.filters = eleventyConfig.javascriptFunctions; 
eleventyConfig.setPugOptions({ 
  globals: ['filters'],
  debug: false
});

This seems to no longer work. How can I add filters to use with pug in v3 (beta)?

So far my best attempt was:

import pugPlugin from "@11ty/eleventy-plugin-pug";
....
export default function (config) {
....
pugPlugin.options = { 
    globals: ['filters'],
    debug: false, 
    filters: { "readingTime" : readingTime }
}
config.addPlugin(pugPlugin);
...

But this did not work. Based on these docs is this just not supported yet?

@peekxc
Copy link
Author

peekxc commented Aug 20, 2024

(this might be a question for @Zearin)

@peekxc
Copy link
Author

peekxc commented Aug 27, 2024

Update!

From scanning the source, I've figured out that the following works in v3:

eleventyConfig.addPlugin(pugPlugin, { 
    globals: ['filters'],
    debug: false, 
    filters: eleventyConfig.getFilters({ type: "sync" }),
});

Presumeably, this needs to be done after filters have been added, a la:

eleventyConfig.addFilter("readingTime", reading_time);

Usage is now identical to the globals trick from v2 mentioned in #1

@peekxc peekxc closed this as completed Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant