-
|
Hi, was wondering if someone might be able to help... I have a bunch of data files in this structure: _data/seasons/s2022.json Each data file outputs an object containing 2 football players' stats in each competition for that season, so goals, assists, appearances, and a few more. Ideally, I was thinking in another data file (e.g. _data/all_time.js), I could calculate the totals for each stat. So get the goals total for each competition from each season and then find the sum for each (the all time totals). There are 9 competitions and 7 different stats for each one. Is there a way to make the data from those season data files available in another global JS data file so I can do all the calculations using JavaScript? I did try doing these calculations in the template file (.njk) but it doesn't seem possible to do in a nice way. It is technically possible but would be hundreds of lines of the least DRY code imaginable. I thought I had it with the following concept, but it seems you can't update object data in Nunjucks... Can anyone help or suggest an alternative approach? This is my first Eleventy project so there may be a much more sensible way to go about this! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
|
I'd probably do something like _data/all_time.js or _data/seasons/all_time.js and have that file do a |
Beta Was this translation helpful? Give feedback.
I'd probably do something like _data/all_time.js or _data/seasons/all_time.js and have that file do a
const s2022 = require("./s2022.json")(or maybe even something w/ https://www.npmjs.com/package/require-dir) and then do all your calculations in Node (instead of Nunjucks).Then your final export is just the calculated data which you can loop over.