feat: add postcss filter
All CSS processing is handled by the filter, and is now inlined into the HTML
This commit is contained in:
parent
6a84af0c37
commit
2aa912399c
14 changed files with 53 additions and 60 deletions
1
config/constants/paths.js
Normal file
1
config/constants/paths.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const ASSETS_FONTS_PATH = "/assets/fonts";
|
30
config/filters/postcss/postcss.js
Normal file
30
config/filters/postcss/postcss.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Implementation sourced from eleventyone starter kit
|
||||||
|
* https://github.com/philhawksworth/eleventyone
|
||||||
|
* ---
|
||||||
|
* https://github.com/philhawksworth/eleventyone/blob/master/src/site/css/styles.11ty.js
|
||||||
|
*/
|
||||||
|
import postcss from "postcss";
|
||||||
|
import postcssImport from "postcss-import";
|
||||||
|
import postcssImportExtGlob from "postcss-import-ext-glob";
|
||||||
|
import autoprefixer from "autoprefixer";
|
||||||
|
import cssnano from "cssnano";
|
||||||
|
|
||||||
|
import colors from "./utils/colors.js";
|
||||||
|
import fontFamily from "./utils/font-family.js";
|
||||||
|
import fontVariables from "./utils/font-variables.js";
|
||||||
|
import spacing from "./utils/spacing.js";
|
||||||
|
|
||||||
|
const postCss = async (rawCss) => {
|
||||||
|
const css = `${rawCss}${fontFamily}${fontVariables}${colors}${spacing}`;
|
||||||
|
return await postcss([
|
||||||
|
postcssImportExtGlob,
|
||||||
|
postcssImport,
|
||||||
|
autoprefixer,
|
||||||
|
cssnano,
|
||||||
|
])
|
||||||
|
.process(css, { from: "src/includes/css/styles.css" })
|
||||||
|
.then((result) => result.css);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default postCss;
|
|
@ -1,4 +1,4 @@
|
||||||
import colorSchemes from "../../config/design-tokens/colors.js";
|
import colorSchemes from "../../../design-tokens/colors.js";
|
||||||
import { helperClassesToCss } from "./helper-classes.js";
|
import { helperClassesToCss } from "./helper-classes.js";
|
||||||
|
|
||||||
const lightScheme = colorSchemes.light;
|
const lightScheme = colorSchemes.light;
|
|
@ -1,5 +1,9 @@
|
||||||
import { getFontUrl } from "../utils/fonts.js";
|
import path from "path";
|
||||||
import fonts from "../../config/design-tokens/fonts.js";
|
|
||||||
|
import { ASSETS_FONTS_PATH } from "../../../constants/paths.js";
|
||||||
|
import fonts from "../../../design-tokens/fonts.js";
|
||||||
|
|
||||||
|
const getFontUrl = (src) => path.join(ASSETS_FONTS_PATH, src);
|
||||||
|
|
||||||
const fontsToCss = (fonts) => {
|
const fontsToCss = (fonts) => {
|
||||||
return Object.entries(fonts).reduce((css, [, fontProperties]) => {
|
return Object.entries(fonts).reduce((css, [, fontProperties]) => {
|
|
@ -1,4 +1,4 @@
|
||||||
import fonts from "../../config/design-tokens/fonts.js";
|
import fonts from "../../../design-tokens/fonts.js";
|
||||||
|
|
||||||
const fallbacks = [
|
const fallbacks = [
|
||||||
"-apple-system",
|
"-apple-system",
|
|
@ -1,4 +1,4 @@
|
||||||
import spacing from "../../config/design-tokens/spacing.js";
|
import spacing from "../../../design-tokens/spacing.js";
|
||||||
import { helperClassesToCss } from "./helper-classes.js";
|
import { helperClassesToCss } from "./helper-classes.js";
|
||||||
|
|
||||||
const spacingToCss = (variant, value) =>
|
const spacingToCss = (variant, value) =>
|
|
@ -8,7 +8,7 @@ export default function (eleventyConfig) {
|
||||||
collapseWhitespace: true,
|
collapseWhitespace: true,
|
||||||
decodeEntities: true,
|
decodeEntities: true,
|
||||||
includeAutoGeneratedTags: false,
|
includeAutoGeneratedTags: false,
|
||||||
minifyCSS: true,
|
minifyCSS: false, // Disabled because of clean-css' lack of nested CSS support
|
||||||
minifyJS: true,
|
minifyJS: true,
|
||||||
minifyURLs: true,
|
minifyURLs: true,
|
||||||
removeComments: true,
|
removeComments: true,
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
pluralize,
|
pluralize,
|
||||||
values,
|
values,
|
||||||
} from "./config/filters/index.js";
|
} from "./config/filters/index.js";
|
||||||
|
import postcss from "./config/filters/postcss/postcss.js";
|
||||||
import markdown from "./config/plugins/markdown.js";
|
import markdown from "./config/plugins/markdown.js";
|
||||||
import liteYoutube from "./config/shortcodes/youtube.js";
|
import liteYoutube from "./config/shortcodes/youtube.js";
|
||||||
|
|
||||||
|
@ -60,6 +61,8 @@ export default function (eleventyConfig) {
|
||||||
eleventyConfig.addFilter("values", values);
|
eleventyConfig.addFilter("values", values);
|
||||||
eleventyConfig.addFilter("pluralize", pluralize);
|
eleventyConfig.addFilter("pluralize", pluralize);
|
||||||
|
|
||||||
|
eleventyConfig.addFilter("postcss", postcss);
|
||||||
|
|
||||||
// --------------------- Custom Transforms -----------------------
|
// --------------------- Custom Transforms -----------------------
|
||||||
eleventyConfig.addPlugin(htmlConfigTransform);
|
eleventyConfig.addPlugin(htmlConfigTransform);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { getFontUrl } from "../utils/fonts.js";
|
import path from "path";
|
||||||
|
|
||||||
|
import { ASSETS_FONTS_PATH } from "../../config/constants/paths.js";
|
||||||
import fonts from "../../config/design-tokens/fonts.js";
|
import fonts from "../../config/design-tokens/fonts.js";
|
||||||
|
|
||||||
|
const getFontUrl = (src) => path.join(ASSETS_FONTS_PATH, src);
|
||||||
|
|
||||||
const preloads = [
|
const preloads = [
|
||||||
{
|
{
|
||||||
as: "font",
|
as: "font",
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* Implementation sourced from eleventyone starter kit
|
|
||||||
* https://github.com/philhawksworth/eleventyone
|
|
||||||
* ---
|
|
||||||
* https://github.com/philhawksworth/eleventyone/blob/master/src/site/css/styles.11ty.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
import fs from "fs";
|
|
||||||
import postcss from "postcss";
|
|
||||||
import postcssImport from "postcss-import";
|
|
||||||
import postcssImportExtGlob from "postcss-import-ext-glob";
|
|
||||||
import autoprefixer from "autoprefixer";
|
|
||||||
import cssnano from "cssnano";
|
|
||||||
import { posix as path } from "path";
|
|
||||||
import { fileURLToPath } from "url";
|
|
||||||
|
|
||||||
import colors from "../../css-utils/colors.js";
|
|
||||||
import fontFamily from "../../css-utils/font-family.js";
|
|
||||||
import fontVariables from "../../css-utils/font-variables.js";
|
|
||||||
import spacing from "../../css-utils/spacing.js";
|
|
||||||
|
|
||||||
export default class {
|
|
||||||
async data() {
|
|
||||||
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
||||||
const rawFilepath = path.join(dirname, "./global.css");
|
|
||||||
const rawCss = fs.readFileSync(rawFilepath);
|
|
||||||
|
|
||||||
const css = `${rawCss}${fontFamily}${fontVariables}${colors}${spacing}`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
permalink: `css/styles.css`,
|
|
||||||
excludeFromSitemap: true,
|
|
||||||
eleventyExcludeFromCollections: true,
|
|
||||||
rawFilepath,
|
|
||||||
rawCss: css,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async render({ rawCss, rawFilepath }) {
|
|
||||||
return await postcss([
|
|
||||||
postcssImportExtGlob,
|
|
||||||
postcssImport,
|
|
||||||
autoprefixer,
|
|
||||||
cssnano,
|
|
||||||
])
|
|
||||||
.process(rawCss, { from: rawFilepath })
|
|
||||||
.then((result) => result.css);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@
|
||||||
{% if title %}{{ title }} •{% endif %}
|
{% if title %}{{ title }} •{% endif %}
|
||||||
{{ meta.siteName }}
|
{{ meta.siteName }}
|
||||||
</title>
|
</title>
|
||||||
<link rel="stylesheet" href="/css/styles.css" />
|
|
||||||
{% include "partials/meta.html" %}
|
{% include "partials/meta.html" %}
|
||||||
{% for preload in preloads %}
|
{% for preload in preloads %}
|
||||||
<link rel="preload"
|
<link rel="preload"
|
||||||
|
@ -21,6 +20,10 @@
|
||||||
<script type="module"
|
<script type="module"
|
||||||
src="https://cdn.jsdelivr.net/npm/@justinribeiro/lite-youtube@1.4.0/lite-youtube.min.js"></script>
|
src="https://cdn.jsdelivr.net/npm/@justinribeiro/lite-youtube@1.4.0/lite-youtube.min.js"></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% set css %}
|
||||||
|
{% include "css/styles.css" %}
|
||||||
|
{% endset %}
|
||||||
|
<style>{{ css | postcss | safe }}</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="flex-col">
|
<body class="flex-col">
|
||||||
{% noRobots %}
|
{% noRobots %}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
export const getFontUrl = (src) => path.join("/assets/fonts", src);
|
|
Loading…
Add table
Add a link
Reference in a new issue