Skip to content

Commit

Permalink
Make data files preserve dots in keys instead of using them as paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Dermah committed Jun 9, 2020
1 parent d3dfcec commit 4b24835
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/TemplateData.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ class TemplateData {
let paths = [
`${dir}/**/*.json`, // covers .11tydata.json too
`${dir}/**/*${this.config.jsDataFileSuffix}.cjs`,
`${dir}/**/*${this.config.jsDataFileSuffix}.js`
`${dir}/**/*${this.config.jsDataFileSuffix}.js`,
];

if (this.hasUserDataExtensions()) {
let userPaths = this.getUserDataExtensions().map(
extension => `${dir}/**/*.${extension}` // covers .11tydata.{extension} too
(extension) => `${dir}/**/*.${extension}` // covers .11tydata.{extension} too
);
paths = userPaths.concat(paths);
}
Expand All @@ -146,7 +146,7 @@ class TemplateData {
async getTemplateJavaScriptDataFileGlob() {
let dir = await this.getInputDir();
return TemplatePath.addLeadingDotSlashArray([
`${dir}/**/*${this.config.jsDataFileSuffix}.js`
`${dir}/**/*${this.config.jsDataFileSuffix}.js`,
]);
}

Expand Down Expand Up @@ -182,7 +182,7 @@ class TemplateData {
fsBench.before();
let paths = await fastglob(await this.getGlobalDataGlob(), {
caseSensitiveMatch: false,
dot: true
dot: true,
});
fsBench.after();

Expand Down Expand Up @@ -211,7 +211,12 @@ class TemplateData {
let folders = parsed.dir ? parsed.dir.split("/") : [];
folders.push(parsed.name);

return folders.join(".");
// Folders reduce to `folder["subfolder"]["subsubfolder"]`...
const reduction = folders.reduce((acc, cur, i) =>
i === 0 ? cur : `${acc}["${cur}"]`
);

return reduction;
}

async getAllGlobalData() {
Expand Down

0 comments on commit 4b24835

Please sign in to comment.