eleventy-plugin-uncharted 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eleventy.config.js +31 -8
- package/package.json +1 -1
package/eleventy.config.js
CHANGED
|
@@ -11,7 +11,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
11
11
|
* Uncharted - Eleventy CSS Charts Plugin
|
|
12
12
|
* @param {Object} eleventyConfig - Eleventy configuration object
|
|
13
13
|
* @param {Object} [options] - Plugin options
|
|
14
|
-
* @param {string} [options.dataDir] - Data directory path (
|
|
14
|
+
* @param {string} [options.dataDir] - Data directory path (overrides Eleventy's dir.data if set)
|
|
15
15
|
* @param {boolean} [options.animate] - Enable animations globally (individual charts can override)
|
|
16
16
|
* @param {string} [options.cssPath] - Output path for stylesheet (default: '/css/uncharted.css')
|
|
17
17
|
* @param {boolean} [options.injectCss] - Automatically copy and inject CSS (default: true)
|
|
@@ -20,7 +20,28 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
20
20
|
* @param {boolean|string} [options.downloadData] - Enable download links globally (individual charts can override)
|
|
21
21
|
*/
|
|
22
22
|
export default function(eleventyConfig, options = {}) {
|
|
23
|
-
|
|
23
|
+
// Directory config from Eleventy (populated by eleventy.directories event)
|
|
24
|
+
let eleventyDirs = null;
|
|
25
|
+
|
|
26
|
+
// Listen for Eleventy's directory configuration
|
|
27
|
+
eleventyConfig.on('eleventy.directories', (dirs) => {
|
|
28
|
+
eleventyDirs = dirs;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Helper to resolve data directory
|
|
32
|
+
function getDataDir() {
|
|
33
|
+
// Plugin option takes precedence if explicitly set
|
|
34
|
+
if (options.dataDir) {
|
|
35
|
+
return path.resolve(process.cwd(), options.dataDir);
|
|
36
|
+
}
|
|
37
|
+
// Use Eleventy's directory configuration (already includes full path)
|
|
38
|
+
if (eleventyDirs?.data) {
|
|
39
|
+
return path.resolve(process.cwd(), eleventyDirs.data);
|
|
40
|
+
}
|
|
41
|
+
// Fallback to default
|
|
42
|
+
return path.resolve(process.cwd(), '_data');
|
|
43
|
+
}
|
|
44
|
+
|
|
24
45
|
const globalAnimate = options.animate ?? false;
|
|
25
46
|
const cssPath = options.cssPath || '/css/uncharted.css';
|
|
26
47
|
const injectCss = options.injectCss ?? true;
|
|
@@ -67,17 +88,19 @@ export default function(eleventyConfig, options = {}) {
|
|
|
67
88
|
});
|
|
68
89
|
}
|
|
69
90
|
|
|
70
|
-
// CSV data passthrough for download links
|
|
91
|
+
// CSV data passthrough for download links (set up after directories are known)
|
|
71
92
|
if (dataPassthrough) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
eleventyConfig.on('eleventy.directories', () => {
|
|
94
|
+
const resolvedDataDir = getDataDir();
|
|
95
|
+
eleventyConfig.addPassthroughCopy({
|
|
96
|
+
[resolvedDataDir]: dataPath.replace(/^\//, '').replace(/\/$/, '')
|
|
97
|
+
});
|
|
75
98
|
});
|
|
76
99
|
}
|
|
77
100
|
|
|
78
101
|
eleventyConfig.addShortcode('chart', function(chartId) {
|
|
79
|
-
//
|
|
80
|
-
const resolvedDataDir =
|
|
102
|
+
// Get resolved data directory (from Eleventy config or plugin options)
|
|
103
|
+
const resolvedDataDir = getDataDir();
|
|
81
104
|
|
|
82
105
|
// Look up chart config from page data or global data
|
|
83
106
|
// In Eleventy 3.x, data is available directly on `this` context
|