import { attrs } from "@mdit/plugin-attrs";
import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import eleventyNavigationPlugin from "@11ty/eleventy-navigation";

import pluginFilters from "./_config/filters.js";

export default async function(eleventyConfig) {
	/* Markdown HTML attribute parsing */
	eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(attrs));

	/* Bundles */
	/* CSS */
	eleventyConfig.addBundle("css", {
		toFileDirectory: "dist",
		bundleHtmlContentFromSelector: "style",
	});

	/* Javascript */
	eleventyConfig.addBundle("js", {
		toFileDirectory: "dist",
		bundleHtmlContentFromSelector: "script",
	});

	/* Passthroughs */
	eleventyConfig
		.addPassthroughCopy("./greenhouse.jpg")
		.addPassthroughCopy("./favicon.ico");

		/* Images */
	eleventyConfig.addPlugin(eleventyImageTransformPlugin, {
		// output image formats
		formats: ["auto"],

		// output image widths
		widths: ["auto"],

		// optional, attributes assigned on <img> nodes override these values
		htmlOptions: {
			imgAttributes: {
				loading: "lazy",
				decoding: "async",
			},
		},
	});

	/* Navigation */
	eleventyConfig.addPlugin(eleventyNavigationPlugin);

	/* All filters from _config/filters.js */
	eleventyConfig.addPlugin(pluginFilters);


	/* Shortcodes */
	eleventyConfig.addShortcode("currentBuildDate", () => {
		return (new Date()).toISOString();
	});

	/* Watch when serving */
	eleventyConfig.addWatchTarget("css");
}

export const config = {
  dir: {
    input: "src",
		includes: "../_includes",
		layouts: "../_includes/layouts",
		data: "../_data"
  },
	markdownTemplateEngine: "njk",
	htmlTemplateEngine: "njk",
	templateFormats: ["html", "md", "njk"],
};
