text: const path = require('path');
  const {
    flattenMarkdownData,
    cssClassesFromFilePath,
    cssClassesFromUrlPath,
    urlPathFromFilePath,
    setEnvironmentVariables
  } = require('@watheia/api.stackbit');
  
  const isDev = process.env.NODE_ENV !== 'production';
  
  function matchPages(getUrl) {
    return (obj) => {
      const { __metadata, ...restProps } = obj;
      const urlPath = getUrl(obj);
      return {
        __metadata: {
          ...__metadata,
          urlPath,
          pageCssClasses: cssClassesFromUrlPath(urlPath)
        },
        ...restProps
      };
    };
  }
  
  module.exports = {
    plugins: [
      /**
       * The `sourcebit-source-filesystem` plugin reads content files from the provided `options.sources`,
       * and generates array of objects that are passed to subsequent plugins.
       */
      {
        module: require('sourcebit-source-filesystem'),
        options: {
          watch: isDev,
          sources: [
            { name: 'pages', path: path.join(__dirname, 'content/pages') },
            { name: 'data', path: path.join(__dirname, 'content/data') }
          ]
        }
      },
  
      /**
       * converts { __metadata, frontmatter, markdown }
       * to { __metadata, ...frontmater, markdown_content: markdown }
       */
      flattenMarkdownData(),
  
      /**
       * The `sourcebit-target-next` plugin receives objects generated by `sourcebit-source-filesystem` plugin,
       * and generates new data that is consumed by Next.js `getStaticPaths` and `getStaticProps` methods.
       * The generated data is cached and stored inside `.sourcebit-nextjs-cache.json` file.
       *
       * The generated data is an object with three properties:
       * - objects: Array of objects representing all content files loaded by the `sourcebit-source-filesystem` plugin.
       * - pages: Array of objects representing site pages props. This array is generated by the `pages()` method.
       * - props: Object with common props that will be merged with props of every page. This object is generated by
       *          the `commonProps()` method.
       */
      {
        module: require('sourcebit-target-next'),
        options: {
          liveUpdate: isDev,
          flattenAssetUrls: true,
          commonProps: (objects) => {
            const site = objects.find(
              (page) => page.__metadata.id === 'content/data/config.json'
            );
            site.env = setEnvironmentVariables();
            return { site };
          },
          pages: (objects) => {
            const personObjects = objects.filter(
              (object) =>
                object.__metadata.relProjectPath?.startsWith('content/data/team/') &&
                !!object.slug
            );
            const personPages = personObjects.map(matchPages((it) => `/blog/author/${it.slug}`));
  
            const categoryObjects = objects.filter(
              (object) =>
                object.__metadata.relProjectPath?.startsWith('content/data/category/') &&
                !!object.slug
            );
            const categoryPages = categoryObjects.map(
              matchPages((it) => `/blog/category/${it.slug}`)
            );
  
            const pageObjects = objects.filter((page) => page.__metadata.sourceName === 'pages');
            const pages = pageObjects.map((page) => {
              const { __metadata, ...restProps } = page;
              const urlPath = urlPathFromFilePath(page.__metadata.relSourcePath);
              return {
                __metadata: {
                  ...__metadata,
                  urlPath,
                  pageCssClasses: cssClassesFromFilePath(page.__metadata.relSourcePath)
                },
                ...restProps
              };
            });
  
            return [...pages, ...categoryPages, ...personPages];
          }
        }
      }
    ]
  };
  