import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import mdx from '@astrojs/mdx';
import AutoImport from 'astro-auto-import';

const defaultLayoutPlugin = () => (tree, file) => {
  const path = file.history.at(-1).split('/').at(-1);
  file.data.astro.frontmatter.layout = (
    path.startsWith('index.')
      ? '../layouts/Cover.astro'
      : '../layouts/Default.astro'
  );
};

export default defineConfig({
  trailingSlash: 'never',
  output: 'static',
  build: {
    format: 'file',
  },
  compressHTML: false,
  markdown: {
    remarkPlugins: [defaultLayoutPlugin],
    extendDefaultPlugins: true,
  },
  integrations: [
    tailwind({
      applyBaseStyles: false,
    }),
    AutoImport({
      imports: [
        './src/components/Score.astro',
      ],
    }),
    mdx()
  ],
});
