-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Access to raw file content (before any processing) #1206
Comments
I think |
@MiloCasagrande I didn't see that anywhere, would you have an example? |
@nhoizey If you meant an example in the docs, I didn't see any in there.
|
Thanks, it works in loops indeed! 👍 But I can't make it work in a content's template. Any idea how to access it? Also, I guess it should be documented, if we want it to keep working in the future… 😅 |
@nhoizey unfortunately not, I was only able to access it from within the pagination loop. Those data structures should be documented somewhere, I also fear that they might disappear in the future. |
Ok. @zachleat can we expect this to stay in the future? Also, is there a way to access the same value in a content's template/layout? |
I agree it would be useful to access the raw Markdown for instances where you might wat to port/copy content to another system that speaks Markdown, but not HTML. |
Another vote for this here https://twitter.com/rob_dodson/status/1321554550671618048 from @robdodson |
yep, here's how we use this in web.dev to build our algolia index but I feel a little nervous using an undocumented API 😅 |
Interesting, thanks for sharing @robdodson. We are about to use the following in a custom collection for https://github.com/webwewant/webwewant.fyi: eleventyConfig.addCollection("wantsBySubmissionDate", collection => {
return collection.getAll()
.filter( item => item.inputPath.match(/\/wants\/.*\.md/) !== null )
.sort( (a, b) => b.date - a.date )
// append the raw content
.map( item => {
item.data.rawMarkdown = item.template.frontMatter.content || "";
return item;
} );
}); Note that in the |
@robdodson I didn't think about using the raw Markdown as a source for Algolia after cleaning, well done. I'm currently cleaning the rendered HTML with cheerio. I guess using I'm also using I guess having the raw Markdown everytime, in any collection, would be useful. |
|
My hacky way of achieving this: // .eleventy.js
config.setLibrary('md', { render: (markdown) => markdown }) Now Markdown files don't get automatically converted to HTML, so A downside is that if a page is rendered multiple times (e.g. once on its own and once when rendering an RSS feed), markdown-it's // eleventyComputed.js
module.exports = {
html: (data) => markdownIt.render(data.content),
} ...but it doesn't work because |
Cross link: https://fosstodon.org/@eleventy/109831381492142746 I use it to extract wikilinks, and it's not working in 2.0! 😱 I'm probably just going to stick on Issue from this file: eleventy/src/TemplateContent.js Line 127 in 05c6263
|
Shipping with Eleventy v3.0.0-alpha.1 as the |
I think we’ll add (see the rest of |
Will it be possible to read I've got a collection I want to make that is derived based on the content of existing pages. Pre-1.0 I read through the |
@edwardhorsford yeah, I think so—it should be available long before |
Docs for |
I know from the
page
object I can accesscontent
and within a collection I can usetemplateContent
to get the rendered output, but is it possible to get just the markdown input?I could just read the file from the page's
inputPath
, but then I also get the frontmatter... it's easy enough to make a quick shortcode to return what I'm after, but I wanted to make sure there wasn't something built-in that I was missing...The text was updated successfully, but these errors were encountered: