|
| 1 | +const markdownIt = require("markdown-it"); |
| 2 | + |
| 3 | +module.exports = function (eleventyConfig) { |
| 4 | + const md = markdownIt({ |
| 5 | + html: true, |
| 6 | + breaks: false, |
| 7 | + linkify: true |
| 8 | + }); |
| 9 | + |
| 10 | + eleventyConfig.setLibrary("md", md); |
| 11 | + |
| 12 | + eleventyConfig.addPassthroughCopy({ "assets/img": "img" }); |
| 13 | + eleventyConfig.addPassthroughCopy({ "assets/css": "css" }); |
| 14 | + eleventyConfig.addPassthroughCopy("CNAME"); |
| 15 | + eleventyConfig.addPassthroughCopy(".nojekyll"); |
| 16 | + eleventyConfig.addPassthroughCopy({ "assets/img/favicon.png": "favicon.png" }); |
| 17 | + |
| 18 | + eleventyConfig.addFilter("htmlDateString", (dateObj) => { |
| 19 | + return new Date(dateObj).toISOString().split('T')[0]; |
| 20 | + }); |
| 21 | + |
| 22 | + eleventyConfig.addFilter("urlencode", function (str) { |
| 23 | + return encodeURIComponent(str); |
| 24 | + }); |
| 25 | + |
| 26 | + eleventyConfig.addFilter("getTutorialNav", function (tutorials, currentUrl) { |
| 27 | + if (!Array.isArray(tutorials) || !currentUrl) { |
| 28 | + return { first: null, prev: null, next: null }; |
| 29 | + } |
| 30 | + |
| 31 | + const currentIndex = tutorials.findIndex((item) => item.url === currentUrl); |
| 32 | + const first = tutorials.length > 0 ? tutorials[0] : null; |
| 33 | + const prev = currentIndex > 0 ? tutorials[currentIndex - 1] : null; |
| 34 | + const next = currentIndex >= 0 && currentIndex < tutorials.length - 1 |
| 35 | + ? tutorials[currentIndex + 1] |
| 36 | + : null; |
| 37 | + |
| 38 | + return { first, prev, next }; |
| 39 | + }); |
| 40 | + |
| 41 | + eleventyConfig.addCollection("tutorials", function (collectionApi) { |
| 42 | + return collectionApi.getFilteredByGlob("tutorial/**/*.md").sort((a, b) => { |
| 43 | + return (a.data.order || 0) - (b.data.order || 0); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + eleventyConfig.addCollection("tools", function (collectionApi) { |
| 48 | + return collectionApi.getFilteredByGlob("tools/*.njk"); |
| 49 | + }); |
| 50 | + |
| 51 | + eleventyConfig.addWatchTarget("./assets/css/"); |
| 52 | + eleventyConfig.addWatchTarget("./tailwind.css"); |
| 53 | + |
| 54 | + eleventyConfig.setServerOptions({ |
| 55 | + watch: ["_site/css/**/*.css"], |
| 56 | + liveReload: true, |
| 57 | + }); |
| 58 | + |
| 59 | + return { |
| 60 | + dir: { |
| 61 | + input: ".", |
| 62 | + output: "_site", |
| 63 | + includes: "_includes", |
| 64 | + layouts: "_layouts", |
| 65 | + data: "_data" |
| 66 | + }, |
| 67 | + templateFormats: ["md", "njk", "html"], |
| 68 | + markdownTemplateEngine: "njk", |
| 69 | + htmlTemplateEngine: "njk", |
| 70 | + passthroughFileCopy: true |
| 71 | + }; |
| 72 | +}; |
0 commit comments