This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
64 lines (58 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const path = require("path");
const pkg = require("./package.json");
const { createConfig } = require("./utils");
const EleventyLoad = require("./EleventyLoad");
module.exports = function (config, options) {
try {
config.versionCheck(pkg["11ty"].compatibility);
} catch (e) {
console.warn(
`WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}`
);
}
// Return and warn if no rules are given
if (!(options.rules instanceof Array)) {
console.warn(`[${pkg.name}] Try giving me some rules!`);
return;
}
const cache = {};
// Create new EleventyLoad instance in transform
config.addTransform(
"eleventy-load",
function (content, deprecatedOutputPath) {
// [email protected] does not expose _config but inputPath should be relative to
// the project route so we can use the node cwd.
const inputDir = process.cwd();
// outputPath argument is deprecated in [email protected]
const outputPath = deprecatedOutputPath || this.outputPath;
const resource = path.relative(inputDir, this.inputPath);
return new EleventyLoad(
options,
cache,
resource,
content,
createConfig("transform", config, this),
outputPath
);
}
);
// Create new EleventyLoad instance in shortcode
config.addShortcode("load", function (resource) {
return new EleventyLoad(
options,
cache,
resource,
null,
createConfig("shortcode", config, this),
null
);
});
// Clear cache on re-runs
// TODO: update deprecated event name v0.11.0
// https://www.11ty.dev/docs/events/#eleventy.beforewatch
config.on("beforeWatch", () => {
for (const resource in cache) {
delete cache[resource];
}
});
};