11ty / eleventy-plugin-webc

Adds support for WebC *.webc files to Eleventy
https://www.11ty.dev/docs/languages/webc/
120 stars 10 forks source link

Dynamic permalinks and WebC #27

Closed voxpelli closed 2 years ago

voxpelli commented 2 years ago

When using liquid I had a news.11tydata.json containing:

{
  "layout": "layouts/post",
  "tags": ["news"],
  "permalink": "{{ page.date | date: '%Y/%m' }}/{{ title | slug }}/index.html"
}

When using WebC I should instead be using WebC for that? Feels like a challenge? I would preferably use eg. liquid for my permalinks and only WebC for my actual HTML

You may use data variables here (and template syntax, too). These will be parsed with the current template’s rendering engine.

This plugin could provide a custom behavior by setting permalink in compilerOptions to a function or false: https://github.com/11ty/eleventy-plugin-webc/blob/f7bc146888a15f7e057570ffa40bc1c65daf1a09/src/eleventyWebcTemplate.js#L84-L90

I think it should done of:

  1. Have an example of a dynamic permalink in WebC
  2. Provide an alternative renderer for permalinks
  3. Disable permalink link rendering if its not feasible with WebC
voxpelli commented 2 years ago

Some progress on 1.:

  "permalink": "<div webc:nokeep @text='`subdir/${slugify(title)}/index.html`'></div>"
zachleat commented 2 years ago

Yeahhhhhh… this is a hefty bug—sorry. But easily fixable. I just need to map the dynamic attribute JavaScript parsing code to the Eleventy Custom template permalink stuff: https://www.11ty.dev/docs/languages/custom/#compileoptions.permalink-to-override-permalink-compilation

zachleat commented 2 years ago

This will ship with Eleventy WebC 0.7.0

rijkvanzanten commented 2 years ago

Glad to see my workaround for https://github.com/11ty/eleventy-plugin-webc/issues/36 is no longer needed 😄