import { EleventyRenderPlugin, InputPathToUrlTransformPlugin } from "@11ty/eleventy";
import pluginRss from "@11ty/eleventy-plugin-rss";
import syntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight";
import pluginWebc from "@11ty/eleventy-plugin-webc";
import anchor from "markdown-it-anchor";

export default function (eleventyConfig) {
  eleventyConfig.addPlugin(EleventyRenderPlugin);
  eleventyConfig.addPlugin(InputPathToUrlTransformPlugin);
  eleventyConfig.addPlugin(pluginWebc);
  eleventyConfig.addPlugin(syntaxHighlight, {
    errorOnInvalidLanguage: true,

    init({ Prism }) {
      // Conveniently, I only have to highlight a known and fairly small amount of syntax, so I can cheat.
      Prism.languages.crowbar = {
        number: /\d+/,
        keyword: /\b(char|function|int|float|void|const)\b/,
        function: /signal/,
        operator: /\*/,
        punctuation: /[()\[\];,]/,
      };
      Prism.languages.duckscript = {
        builtin: /if|else|end|eq|echo/,
        string: /"[^"]+"/,
        function: /print_fancy/,
        operator: /\$\{|}|\./,
      };
      Prism.languages.dyon = {
        keyword: /fn|if|else/,
        function: /handle_event|print_fancy/,
        builtin: /println|typeof|str/,
        string: /"[^"]+"/,
        operator: /==|\+/,
        punctuation: /[(){};]/,
      };
      Prism.languages.ketos = {
        builtin: /do|define|type-of|println/,
        function: /handle-event|print-fancy/,
        punctuation: /[()]/,
        string: /"[^"]+"/,
      };
      Prism.languages.peg = {
        string: /'[^']+'/,
        "class-name": /BasicType|Type|Expression/,
        operator: /[←\/*]/,
        punctuation: /[()]/,
      };
      Prism.languages.rhai = {
        keyword: /fn|if|else/,
        function: /handle_event|print_fancy/,
        builtin: /print|type_of/,
        string: /"[^"]+"/,
        operator: /==|\+/,
        punctuation: /[(){};]/,
      };
      Prism.languages.rune = {
        keyword: /fn|match|if|is/,
        function: /handle_event|print_fancy/,
        builtin: /println|int/,
        string: /"[^"]+"|`[^`]+`/,
        operator: /=>/,
        punctuation: /[(){},]/,
      };
      // This may take some actual work, though.
      Prism.languages.slint = {
        keyword: /component|export|inherits|property|root/,
        "class-name": /AppWindow|VerticalBox|LineEdit/,
        builtin: /Text|\bWindow|string/,
        string: /"[^"]+"/,
        operator: /:|<=>|\./,
        punctuation: /[{}<>;]/,
        property: /label|text/,
      }
      Prism.languages.text = {};
    },
  });
  eleventyConfig.addPlugin(pluginRss);

  eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(anchor));

  eleventyConfig.addPassthroughCopy("assets");
  eleventyConfig.ignores.add("README.md");
}
