|
1 |
| -const { DateTime } = require("luxon"); |
2 |
| -const CleanCSS = require("clean-css"); |
3 |
| -const UglifyJS = require("uglify-es"); |
4 |
| -const htmlmin = require("html-minifier"); |
5 | 1 | const eleventyNavigationPlugin = require("@11ty/eleventy-navigation");
|
6 |
| -const slugify = require('slugify'); |
7 |
| - |
8 |
| -module.exports = function(eleventyConfig) { |
9 |
| - |
10 |
| - // Eleventy Navigation https://www.11ty.dev/docs/plugins/navigation/ |
11 |
| - eleventyConfig.addPlugin(eleventyNavigationPlugin); |
12 |
| - |
13 |
| - // Configuration API: use eleventyConfig.addLayoutAlias(from, to) to add |
14 |
| - // layout aliases! Say you have a bunch of existing content using |
15 |
| - // layout: post. If you don’t want to rewrite all of those values, just map |
16 |
| - // post to a new file like this: |
17 |
| - // eleventyConfig.addLayoutAlias("post", "layouts/my_new_post_layout.njk"); |
18 |
| - |
19 |
| - // Merge data instead of overriding |
20 |
| - // https://www.11ty.dev/docs/data-deep-merge/ |
21 |
| - eleventyConfig.setDataDeepMerge(true); |
22 |
| - |
23 |
| - // Add support for maintenance-free post authors |
24 |
| - // Adds an authors collection using the author key in our post frontmatter |
25 |
| - // Thanks to @pdehaan: https://github.com/pdehaan |
26 |
| - eleventyConfig.addCollection("authors", collection => { |
27 |
| - const blogs = collection.getFilteredByGlob("src/posts/*.md"); |
28 |
| - return blogs.reduce((coll, post) => { |
29 |
| - const author = slugify(post.data.author); |
30 |
| - if (!author) { |
31 |
| - return coll; |
32 |
| - } |
33 |
| - if (!coll.hasOwnProperty(author)) { |
34 |
| - coll[author] = []; |
35 |
| - } |
36 |
| - coll[author].push(post.data); |
37 |
| - return coll; |
38 |
| - }, {}); |
39 |
| - }); |
| 2 | +const eleventyDartSassPlugin = require("eleventy-plugin-dart-sass"); |
| 3 | +const path = require('path'); |
| 4 | + |
| 5 | +const helpers = require('./src/_data/helpers'); |
| 6 | +const markdownConfig = require('./src/11ty/utils/markdown'); |
| 7 | +const browserSyncConfig = require('./src/11ty/utils/browsersync'); |
| 8 | +const UserConfig = require("@11ty/eleventy/src/UserConfig"); |
| 9 | + |
| 10 | +const filters = require('./src/11ty/filters'); |
| 11 | +const filtersMethods = Object.entries(filters); |
| 12 | + |
| 13 | +const transforms = require('./src/11ty/transforms'); |
| 14 | +const transformsMethods = Object.entries(transforms); |
| 15 | + |
| 16 | +const sassConfig = { |
| 17 | + includePaths: ["**/*.{scss,sass}", "!node_modules/**"], |
| 18 | + sassIndexFile: 'main.scss', |
| 19 | + watchSass: true, |
| 20 | + sassLocation: path.normalize( |
| 21 | + path.join(__dirname, "src/_includes/assets/scss/") |
| 22 | + ), |
| 23 | + outDir: path.normalize( |
| 24 | + path.join(__dirname, 'dist/') |
| 25 | + ), |
| 26 | + outPath: "/assets/css/", |
| 27 | + domainName: helpers.url(), |
| 28 | + outFileName: 'main.css', |
| 29 | + outputStyle: 'compressed' |
| 30 | +}; |
40 | 31 |
|
41 |
| - // Date formatting (human readable) |
42 |
| - eleventyConfig.addFilter("readableDate", dateObj => { |
43 |
| - return DateTime.fromJSDate(dateObj).toFormat("dd/MM/yyyy"); |
| 32 | +const passthroughItems = [ |
| 33 | + 'src/_redirects', |
| 34 | + { |
| 35 | + "src/favicon.ico": "/favicon.ico", |
| 36 | + "src/static/img": "/static/img", |
| 37 | + "src/static/CV.pdf": "/static/CV.pdf", |
| 38 | + "src/_includes/assets/css": "/assets/css", |
| 39 | + "src/_includes/assets/js": "/assets/js" |
| 40 | + } |
| 41 | +]; |
| 42 | + |
| 43 | +/** @param {UserConfig} eleventyConfig */ |
| 44 | +module.exports = function (eleventyConfig) { |
| 45 | + filtersMethods.forEach(([name, filter]) => { |
| 46 | + eleventyConfig.addFilter(name, filter) |
44 | 47 | });
|
45 | 48 |
|
46 |
| - // Date formatting (machine readable) |
47 |
| - eleventyConfig.addFilter("machineDate", dateObj => { |
48 |
| - return DateTime.fromJSDate(dateObj).toFormat("yyyy-MM-dd"); |
| 49 | + transformsMethods.forEach(([name, filter]) => { |
| 50 | + eleventyConfig.addTransform(name, filter) |
49 | 51 | });
|
50 | 52 |
|
51 |
| - // Minify CSS |
52 |
| - eleventyConfig.addFilter("cssmin", function(code) { |
53 |
| - return new CleanCSS({}).minify(code).styles; |
54 |
| - }); |
| 53 | + eleventyConfig.addPlugin(eleventyNavigationPlugin); |
| 54 | + eleventyConfig.addPlugin(eleventyDartSassPlugin, sassConfig); |
55 | 55 |
|
56 |
| - // Minify JS |
57 |
| - eleventyConfig.addFilter("jsmin", function(code) { |
58 |
| - let minified = UglifyJS.minify(code); |
59 |
| - if (minified.error) { |
60 |
| - console.log("UglifyJS error: ", minified.error); |
61 |
| - return code; |
62 |
| - } |
63 |
| - return minified.code; |
64 |
| - }); |
| 56 | + passthroughItems.forEach(item => { |
| 57 | + eleventyConfig.addPassthroughCopy(item); |
| 58 | + }) |
65 | 59 |
|
66 |
| - // Minify HTML output |
67 |
| - eleventyConfig.addTransform("htmlmin", function(content, outputPath) { |
68 |
| - if (outputPath && outputPath.indexOf(".html") > -1) { |
69 |
| - let minified = htmlmin.minify(content, { |
70 |
| - useShortDoctype: true, |
71 |
| - removeComments: true, |
72 |
| - collapseWhitespace: true |
73 |
| - }); |
74 |
| - return minified; |
75 |
| - } |
76 |
| - return content; |
| 60 | + eleventyConfig.setBrowserSyncConfig(browserSyncConfig); |
| 61 | + eleventyConfig.setLibrary("md", markdownConfig); |
| 62 | + eleventyConfig.setDataDeepMerge(true); |
| 63 | + eleventyConfig.setFrontMatterParsingOptions({ |
| 64 | + excerpt: true, |
| 65 | + excerpt_separator: "---" |
77 | 66 | });
|
78 | 67 |
|
79 |
| - // Don't process folders with static assets e.g. images |
80 |
| - eleventyConfig.addPassthroughCopy("src/favicon.ico"); |
81 |
| - eleventyConfig.addPassthroughCopy("src/static/img"); |
82 |
| - eleventyConfig.addPassthroughCopy("src/admin"); |
83 |
| - eleventyConfig.addPassthroughCopy("src/_includes/assets/"); |
84 |
| - |
85 |
| - /* Markdown Plugins */ |
86 |
| - let markdownIt = require("markdown-it"); |
87 |
| - let markdownItAnchor = require("markdown-it-anchor"); |
88 |
| - let options = { |
89 |
| - html: true, |
90 |
| - breaks: true, |
91 |
| - linkify: true |
92 |
| - }; |
93 |
| - let opts = { |
94 |
| - permalink: false |
95 |
| - }; |
96 |
| - |
97 |
| - eleventyConfig.setLibrary("md", markdownIt(options) |
98 |
| - .use(markdownItAnchor, opts) |
99 |
| - ); |
100 |
| - |
101 | 68 | return {
|
102 |
| - templateFormats: ["md", "njk", "html", "liquid"], |
103 |
| - |
104 |
| - // If your site lives in a different subdirectory, change this. |
105 |
| - // Leading or trailing slashes are all normalized away, so don’t worry about it. |
106 |
| - // If you don’t have a subdirectory, use "" or "/" (they do the same thing) |
107 |
| - // This is only used for URLs (it does not affect your file structure) |
| 69 | + templateFormats: ["md", "njk", "html"], |
108 | 70 | pathPrefix: "/",
|
109 |
| - |
110 |
| - markdownTemplateEngine: "liquid", |
| 71 | + passthroughFileCopy: true, |
| 72 | + markdownTemplateEngine: "njk", |
111 | 73 | htmlTemplateEngine: "njk",
|
112 | 74 | dataTemplateEngine: "njk",
|
113 | 75 | dir: {
|
|
0 commit comments