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

Better way to consume global data build on shortcodes #3628

Open
jeremenichelli opened this issue Jan 21, 2025 · 0 comments
Open

Better way to consume global data build on shortcodes #3628

jeremenichelli opened this issue Jan 21, 2025 · 0 comments

Comments

@jeremenichelli
Copy link

Is your feature request related to a problem? Please describe.

Currently, if I declare global data in my config, for example...

export default function eleventy(config) {
  config.addGlobalData('buildTimestamp', () => {
    return new Date().toISOString();
  });
}

When I wanted to consume this single point of data inside a shortcode I had to do a really deep debugging around context of execution, and I reached to this:

function shortcode() {
  const buildTimestamp = this.ctx.environments.buildTimestamp;
}

It feels that I am in unsafe territory consuming something like this.

Describe the solution you'd like

I think the developer experience could be improved by two things:

  1. Exposing a better namespace for this, my suggestion would be no acronyms, better naming: this.context.data.
  2. Documenting this context object so there are clear expectations on how it will behave, plus it feels I am consuming this data in the way is intended and is safe for future upgrades of the package.

Describe alternatives you've considered

No response

Additional context

You can see this working in my personal site repository:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant