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

Change permalink check in the Pagination plugin to allow for global permalink settings to function with pagination #3639

Open
philiprenich opened this issue Jan 29, 2025 · 1 comment

Comments

@philiprenich
Copy link

philiprenich commented Jan 29, 2025

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

I am writing a eleventyComputed global data function that sets permalinks based on another piece of data from frontmatter. If a file has draft: true then the permalink is set to false and the page is unpublished. However, this breaks pagination even if the permalink value is untouched because Pagination.js plugin won't manage the page numbers if there a permalink exists, regardless of value. Therefore, it's impossible to globally manipulate permalinks.

Example code:

module.exports = {
    permalink: (data) => {
      return (data.draft)
        ? false
        : data.permalink
    },
};

Describe the solution you'd like

I would like Pagination.js to check the return value of the computed permalink function, rather than just the existence of the permalink config key.

this.data.eleventyComputed && this.data.eleventyComputed[this.config.keys.permalink],

A quick edit to my locally installed 11ty node module to that line shows this working, using undefined as the check:

    let hasComputedPermalinkField = Boolean(
      this.data.eleventyComputed && this.data.eleventyComputed[this.config.keys.permalink] && this.data.eleventyComputed[this.config.keys.permalink](this.data) !== undefined
    );

Describe alternatives you've considered

Unfortunately, I don't have enough context on how the pagination system works under the hood to try other alternatives or solutions. From my understanding of permalinks, the only way to get a page to not be published is to set permalink to false. If there is another way to do drafts that doesn't touch permalinks, I could consider that.

Additional context

Related issue: #3241

@philiprenich
Copy link
Author

It's possible that v3's Preprocesser API may be the preferred way to now do drafts. I'm currently on v2 so setting permalink to false is the recommended way there, where my issue is. Might not be worth the patch to an old version?

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