Description
Operating system
macOS Sequoia 15.5
Eleventy
3.1.0
Describe the bug
Hello, I've got what I think might be a bug - Though I'm not 100% sure. The wording on the docs left me to assume it could work the way I'm expecting.
I have added a custom data format to my setup to handle .csv files. This is the code I am using to add this support:
import { parse } from "csv-parse/sync";
export const csv = eleventyConfig => {
eleventyConfig.addDataExtension("csv", (contents, filepath) => {
const records = parse(contents, {
columns: true,
skip_empty_lines: true,
delimiter: ","
});
return records;
})
}
Now this works perfectly well, when the .csv is in the /_data
directory. I can access the data, use it for pagination, etc.
I've been trying to co-locate it to the folder/page that will actually use this data; so a directory data file.
Based on the wording on this documentation page: https://www.11ty.dev/docs/data-custom/
Out of the box, Eleventy supports arbitrary JavaScript and JSON for both template and directory data files as well as global data.
Maybe you want to add support for TOML or YAML too! Any text format will do.
Reads to me like it should work. I've tried moving the file to the folder I would like, making sure to match the file name to the new directory,
From a global data file: ./_src/_data/fauna.csv
To local: ./_src/pages/fauna/fauna.csv
But like this I am unable to access the data anymore, it returns nothing, pagination breaks etc.
Perhaps I am missing a trick to target the file properly? But I assumed it would work much like a .json directory data file might; where if it has the same name, then that data would be available within the template file.
This is what what the frontmatter looks like in my .liquid file trying to access it
...
pagination:
data: fauna
size: 9
...
Which again, works if I drop the fauna.csv
into /_data
, but nowhere else.
Any help would be greatly appreciated 😊. And if it's not supposed to work this way, then sorry for the report