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

Error for dynamic permalink in JS #49

Closed
solution-loisir opened this issue Feb 4, 2023 · 3 comments
Closed

Error for dynamic permalink in JS #49

solution-loisir opened this issue Feb 4, 2023 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@solution-loisir
Copy link

          You could also use a JS function for this as well (with JS front matter) and bypass the webc parsing altogether:
---js
{
  permalink: function(data) {
    return "`/${this.slugify(data.item.title)}/`";
  }
}
---

https://www.11ty.dev/docs/data-frontmatter/#javascript-front-matter

Originally posted by @zachleat in #42 (comment)

@solution-loisir
Copy link
Author

I'm getting a syntax error when defining dynamic permalink in JS frontmatter like above or in JS data file (see also the comments in #32).

For this frontmatter:

---js
{
  title: "About",
  description: "This page explains what WebC is all about!",
  lang: "en",
  permalink: function(data) {
    return "`/${this.slugify(data.title)}/`";
  }
}
---

I get this error:

Function statements require a function name (via SyntaxError)
[11ty] Original error stack trace: evalmachine.<anonymous>:1
[11ty] function(data) {
[11ty] ^^^^^^^^
[11ty] 
[11ty] SyntaxError: Function statements require a function name
[11ty]     at new Script (node:vm:100:7)
[11ty]     at createScript (node:vm:257:10)
[11ty]     at Object.runInNewContext (node:vm:298:10)
[11ty]     at Function.evaluateScript (/home/mathieu/webc-starter-kit/node_modules/@11ty/webc/src/moduleScript.cjs:62:25)
[11ty]     at Object.<anonymous> (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy-plugin-webc/src/eleventyWebcTemplate.js:70:26)
[11ty]     at Template._renderFunction (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy/src/TemplateContent.js:398:27)
[11ty]     at Template.renderPermalink (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy/src/TemplateContent.js:447:19)
[11ty]     at async Template._getLink (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy/src/Template.js:252:24)
[11ty]     at async Template.getOutputLocations (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy/src/Template.js:302:16)
[11ty]     at async Template.addComputedData (/home/mathieu/webc-starter-kit/node_modules/@11ty/eleventy/src/Template.js:614:28)
[11ty] Wrote 0 files in 0.23 seconds (v2.0.0-beta.2)

Maybe I doing something wrong. As stated in #42, using dynamic attribute syntax in YAML frontmatter does work ex.

permalink: "`/${page.fileSlug}/`"

It just doesn't seem to work in JS for me.

@solution-loisir
Copy link
Author

Seems to be the same issue as #50, and especially to this comment.

@zachleat
Copy link
Member

Duplicate of #32, please subscribe over there!

Related: #47 #52

@zachleat zachleat added bug Something isn't working duplicate This issue or pull request already exists labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants