feat: removed watch command, replaced it by eleventyConfig
This commit is contained in:
parent
4156211eb9
commit
ef731a495c
90
.eleventy.js
90
.eleventy.js
|
@ -1,57 +1,71 @@
|
||||||
const pluginNavigation = require('@11ty/eleventy-navigation')
|
const pluginNavigation = require("@11ty/eleventy-navigation");
|
||||||
const markdownItAttrs = require('markdown-it-attrs')
|
const markdownItAttrs = require("markdown-it-attrs");
|
||||||
const markdownIt = require('markdown-it')
|
const markdownIt = require("markdown-it");
|
||||||
const htmlmin = require('html-minifier')
|
const htmlmin = require("html-minifier");
|
||||||
const yaml = require("js-yaml");
|
const yaml = require("js-yaml");
|
||||||
const options = {
|
const sass = require("sass");
|
||||||
|
const fs = require("fs");
|
||||||
|
const markdownLib = markdownIt({
|
||||||
html: true,
|
html: true,
|
||||||
breaks: true,
|
breaks: true,
|
||||||
linkify: true
|
linkify: true,
|
||||||
}
|
}).use(markdownItAttrs);
|
||||||
const markdownLib = markdownIt(options).use(markdownItAttrs)
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (eleventyConfig) {
|
module.exports = function (eleventyConfig) {
|
||||||
eleventyConfig.addDataExtension("yml", contents => yaml.load(contents));
|
eleventyConfig.addDataExtension("yml", (contents) => yaml.load(contents));
|
||||||
eleventyConfig.addGlobalData('username', 'Laureηt')
|
eleventyConfig.addGlobalData("username", "Laureηt");
|
||||||
eleventyConfig.addWatchTarget('./src/scss/')
|
eleventyConfig.addWatchTarget("./src/scss/");
|
||||||
eleventyConfig.setLibrary('md', markdownLib)
|
eleventyConfig.setLibrary("md", markdownLib);
|
||||||
eleventyConfig.addPlugin(pluginNavigation)
|
eleventyConfig.addPlugin(pluginNavigation);
|
||||||
|
eleventyConfig.setUseGitIgnore(false);
|
||||||
eleventyConfig.addPassthroughCopy({
|
eleventyConfig.addPassthroughCopy({
|
||||||
'assets/': './'
|
"assets/": "./",
|
||||||
})
|
});
|
||||||
|
|
||||||
if (process.env.ELEVENTY_ENV === 'prod') {
|
eleventyConfig.on("eleventy.before", () => {
|
||||||
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
|
let files = fs.readdirSync("./src/scss/");
|
||||||
// Eleventy 1.0+: use this.inputPath and this.outputPath instead
|
files.forEach((file) => {
|
||||||
if (outputPath && outputPath.endsWith('.html')) {
|
// Compile SASS
|
||||||
|
let result = sass.compile("./src/scss/".concat(file), {
|
||||||
|
style: "compressed",
|
||||||
|
sourceMap: false,
|
||||||
|
});
|
||||||
|
console.log(`[SCSS] ${file} compiled`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
eleventyConfig.addTransform("htmlmin", function (content, outputPath) {
|
||||||
|
if (
|
||||||
|
process.env.NODE_ENV === "production" &&
|
||||||
|
outputPath &&
|
||||||
|
outputPath.endsWith(".html")
|
||||||
|
) {
|
||||||
const minified = htmlmin.minify(content, {
|
const minified = htmlmin.minify(content, {
|
||||||
collapseWhitespace: true,
|
collapseWhitespace: true,
|
||||||
useShortDoctype: true,
|
useShortDoctype: true,
|
||||||
removeComments: true,
|
removeComments: true,
|
||||||
minifyCSS: true,
|
minifyCSS: true,
|
||||||
minifyJS: true
|
minifyJS: true,
|
||||||
})
|
});
|
||||||
return minified
|
return minified;
|
||||||
} else {
|
} else {
|
||||||
return content
|
return content;
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
eleventyConfig.addShortcode('year', () => {
|
eleventyConfig.addShortcode("year", () => {
|
||||||
const year = new Date().getFullYear()
|
const year = new Date().getFullYear();
|
||||||
return year.toString()
|
return year.toString();
|
||||||
})
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
markdownTemplateEngine: 'njk',
|
markdownTemplateEngine: "njk",
|
||||||
passthroughFileCopy: true,
|
passthroughFileCopy: true,
|
||||||
dir: {
|
dir: {
|
||||||
includes: '_includes',
|
includes: "_includes",
|
||||||
output: '_site',
|
output: "_site",
|
||||||
data: '_data',
|
data: "_data",
|
||||||
input: 'src'
|
input: "src",
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -4,12 +4,8 @@
|
||||||
"author": "Laureηt <laurentfainsin@protonmail.com>",
|
"author": "Laureηt <laurentfainsin@protonmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch:sass": "sass --no-source-map --watch src/scss:src/_includes/css",
|
"dev": "eleventy --serve",
|
||||||
"watch:eleventy": "eleventy --serve",
|
"build": "NODE_ENV=production eleventy"
|
||||||
"build:sass": "sass --no-source-map --style compressed src/scss:src/_includes/css",
|
|
||||||
"build:eleventy": "ELEVENTY_ENV=prod eleventy",
|
|
||||||
"start": "npm-run-all build:sass --parallel watch:*",
|
|
||||||
"build": "npm-run-all build:sass build:eleventy"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@11ty/eleventy": "^1.0.0",
|
"@11ty/eleventy": "^1.0.0",
|
||||||
|
|
Reference in a new issue