-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.eleventy.js
More file actions
47 lines (44 loc) · 1.51 KB
/
Copy path.eleventy.js
File metadata and controls
47 lines (44 loc) · 1.51 KB
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
const { urlFor } = require("./src/sanity");
const { inspect } = require("util");
module.exports = (config) => {
config.addWatchTarget("./src/sass");
config.addPassthroughCopy("./src/sass");
config.addPassthroughCopy("./src/assets");
// Filter for cache busting. Adds a ?v=<UNIX timestamp at build time>
// query string to the URL.
// use as <img src="{{ '/path/to/file' | url | bust }}" />
config.addFilter("bust", (url) => {
const [urlPart, paramPart] = url.split("?");
const params = new URLSearchParams(paramPart || "");
params.set("v", Math.floor(Date.now() / 1000));
return `${urlPart}?${params}`;
});
// Utility filter to debug JSON objects returned from fetch requests
config.addFilter("inspectJSON", (obj) => {
return inspect(obj, { depth: 4 });
});
// Filter to build URLs for Sanity images. Supply with image _id and width.
// Usage: {{ _id | urlFor(width) }}
config.addFilter("urlFor", (source, width) => {
return urlFor(source).width(width).url();
});
// Filter to console log data
config.addFilter("console", (value) => {
console.log(inspect(value, { depth: 4 }));
return "";
});
// Filter to word wrap strings
// config.addFilter("wordWrap", (s, w) =>
// s.replace(new RegExp(`(?![^\\n]{1,${w}}$)([^\\n]{1,${w}})\\s`, "g"), "$1\n")
// );
return {
markdownTemplateEngine: "njk",
dataTemplateEngine: "njk",
htmlTemplateEngine: "njk",
dir: {
input: "src",
output: "public",
layouts: "_includes/layouts",
},
};
};