Skip to main content


I'm playing with Eleventy, I've got markdown files with tags within the text (as hashtags, like here), and I would like to extract them, to add them to the tags that are recognized by Eleventy, for display and collections. I think I haven't the right words to search on the net, because I found nothing… Is my problem solvable or have I no other way than modify all my files and put tags in the frontmatter?

#eleventy #11ty #webdev

in reply to Lamecarlate

if you use `tags` in your front matter, it will populate them into Eleventy collections! Or are you trying to avoid that?
in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy Yes, I'm aware, but I'm trying to reduce the writing friction 🥲 I want to publish a digital garden and my tags are on the bottom of each article, it's my workflow. I could change my workflow, of course! But if I could avoid rewriting old articles and modifying my writing templates… well I would love it!
in reply to Lamecarlate

HMM. I’m not sure this is doable (yet). I experimented with Computed Data 11ty.dev/docs/data-computed/ (note the warning about `tags`), the Preprocessor API 11ty.dev/docs/config-preproces… and the collections API 11ty.dev/docs/collections/#adv… using page.rawInput 11ty.dev/docs/data-eleventy-su… and I just don’t think the timing is there for any of them to accommodate this use case—sorry!

The best way forward is to file an enhancement request on GitHub to allow Computed Data to populate tags, I think.

in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy as I already told @lamecarlate , I tried but failed, so an official solution would be great.

This doesn't work:
github.com/nhoizey/nicolas-hoi…

in reply to Nicolas Hoizey

@nhoizey you _could_ add your own preprocessing step to achieve this, fwiw (which I think we’re all trying to avoid).

btw just making sure you’re aware of `page.rawInput`: 11ty.dev/docs/data-eleventy-su…

in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy my code dates from Eleventy 0.x, so I'm sure there are better ways now, such as `page.rawInput`… 😅

I guess preprocessing would be too much, indeed.

@lamecarlate

in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy @nhoizey I'm reading this page, it's really interesting! Still I'm confused by the amount of data (not your fault). Can I access `page.rawInput` in a directory data file, like `posts/posts.11tydata.js`? It seems to return `undefined` when in

eleventyComputed: {
insideTags: function (data) {
console.log(data.page.rawInput);
},
}

in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy @nhoizey OH. That's… indeed not the case. I'm using eleventy-base-blog as a starter. Tried to upgrade to 3.0 in order to use eleventyImageTransformPlugin but it was a disaster so I figured I'll wait for a stable version (not really the adventurous type here ;___; ). Maybe I could just wait, and focus on other parts of the website (the CSS, for example), and come back to it later…
in reply to Lamecarlate

@nhoizey finishing the last docs for the 3.0 stable release now but the eleventy-base-blog has a `v9` branch that has the v3 version in it!
in reply to Lamecarlate

@eleventy @nhoizey And it works!! The regex is /(?<=\s#)((?!#)\S\S*)/g if you're interested: it grabs any hashtag in the content, without capturing the "#". It still recognize hexadecimal colours in code, but I'm not sure a regex can differentiate, so maybe I'll use an exclude list (I write in french so there's not many hexawords that could be false positives). Thanks a lot!
in reply to Lamecarlate

great!

Were you able to add these hashtags to the standard tags collection built automatically by @eleventy ?

in reply to Nicolas Hoizey

@nhoizey @eleventy Nope, not yet. Now they're just merged with the displayed tags on the article (which is half the work!). I didn't find a method like "addToCollection", to feed with the results. Still searching.
in reply to Lamecarlate

I think it’s unfortunately not possible (yet?) as @eleventy said in fosstodon.org/@eleventy/113193…


HMM. I’m not sure this is doable (yet). I experimented with Computed Data 11ty.dev/docs/data-computed/ (note the warning about `tags`), the Preprocessor API 11ty.dev/docs/config-preproces… and the collections API 11ty.dev/docs/collections/#adv… using page.rawInput 11ty.dev/docs/data-eleventy-su… and I just don’t think the timing is there for any of them to accommodate this use case—sorry!

The best way forward is to file an enhancement request on GitHub to allow Computed Data to populate tags, I think.


in reply to Eleventy 🎈 v3.0.0-beta.2

@eleventy @nhoizey Oh, I think I misread this:

> The best way forward is to file an enhancement request on GitHub to allow Computed Data to populate tags, I think.

Sooooo, putting this little tag-in-content project in standby for now ^^' I did learn much when tinkering with rawData (regex, yay), it's obviously not for nothing. Thanks a lot for your help, it was really nice!