const fs = require("fs");
const path = require("path");
const toml = require("@iarna/toml");

const addDateParsing = require("./_config/date");
const addFilters = require("./_config/filters");
const addPlugins = require("./_config/plugins");
const addShortcodes = require("./_config/shortcodes");

module.exports = function (eleventyConfig) {
    let siteData;
    const siteToml = fs.readFileSync(
            path.join(__dirname, "_data", "site.toml"),
            "utf-8"
        );
    siteData = toml.parse(siteToml);

    eleventyConfig.addGlobalData("site", siteData);

    eleventyConfig.setLayoutsDirectory("_layouts");

    eleventyConfig.addPassthroughCopy("img");
    eleventyConfig.addPassthroughCopy("css/fonts");
    eleventyConfig.addPassthroughCopy("js");
    eleventyConfig.addPassthroughCopy("LICENSE.txt");
    eleventyConfig.addPassthroughCopy("robots.txt");
    eleventyConfig.addPassthroughCopy("roms");

    addDateParsing(eleventyConfig, { TIME_ZONE: siteData.timezone });
    addFilters(eleventyConfig, { TIME_ZONE: siteData.timezone, defaultLanguage: siteData.default_language });
    addPlugins(eleventyConfig, { defaultLanguage: siteData.default_language });
    addShortcodes(eleventyConfig);

    return {
        markdownTemplateEngine: "njk",
        htmlTemplateEngine: "njk"
    }
};
