Docusaurus Custom Plugin Development

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1230
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1167
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    863
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1077
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    829
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    843

Docusaurus Custom Plugin Development

Docusaurus plugins are functions that extend build lifecycle, add new pages, modify webpack config, or inject data from external sources.

Plugin Structure

// plugins/my-plugin/index.ts
import type { LoadContext, Plugin } from '@docusaurus/types';

interface PluginOptions {
  apiUrl: string;
  cacheTime?: number;
}

export default function myPlugin(
  context: LoadContext,
  options: PluginOptions
): Plugin<{ apiData: any[] }> {
  return {
    name: 'my-docusaurus-plugin',

    // Loading data from external source
    async loadContent() {
      const res = await fetch(options.apiUrl);
      return { apiData: await res.json() };
    },

    // Creating pages based on data
    async contentLoaded({ content, actions }) {
      const { createData, addRoute } = actions;

      for (const item of content.apiData) {
        const dataPath = await createData(
          `api-item-${item.id}.json`,
          JSON.stringify(item)
        );

        addRoute({
          path: `/api-reference/${item.slug}`,
          component: '@site/src/components/ApiItemPage',
          modules: { apiData: dataPath },
          exact: true,
        });
      }

      // Index page
      const allDataPath = await createData('all-api-items.json', JSON.stringify(content.apiData));
      addRoute({
        path: '/api-reference',
        component: '@site/src/components/ApiIndexPage',
        modules: { allItems: allDataPath },
        exact: true,
      });
    },

    // Webpack config modification
    configureWebpack(config, isServer) {
      return {
        module: {
          rules: [
            {
              test: /\.ya?ml$/,
              use: 'yaml-loader',
            },
          ],
        },
      };
    },

    // HTML injection into <head> of all pages
    injectHtmlTags() {
      return {
        headTags: [
          {
            tagName: 'script',
            attributes: {
              defer: true,
              src: 'https://analytics.mysite.com/script.js',
              'data-site': 'MYSITE_ID',
            },
          },
        ],
      };
    },
  };
}

// Options validation
export function validateOptions({ validate, options }) {
  const ValidatedOptions = validate({
    apiUrl: Joi.string().uri().required(),
    cacheTime: Joi.number().default(3600),
  }, options);
  return ValidatedOptions;
}

Plugin Registration

// docusaurus.config.ts
plugins: [
  [
    './plugins/my-plugin',
    {
      apiUrl: 'https://api.myproject.com/endpoints',
      cacheTime: 7200,
    },
  ],
  // Local plugin without options
  './plugins/generate-sitemap-extras',
],

Plugin for Loading Changelog from GitHub

// plugins/github-changelog/index.ts
import { Octokit } from '@octokit/rest';

export default function githubChangelogPlugin(context, options) {
  return {
    name: 'github-changelog-plugin',

    async loadContent() {
      const octokit = new Octokit({ auth: options.token });
      const { data: releases } = await octokit.repos.listReleases({
        owner: options.owner,
        repo:  options.repo,
        per_page: 50,
      });
      return { releases };
    },

    async contentLoaded({ content, actions }) {
      const { createData, addRoute } = actions;
      const dataPath = await createData(
        'releases.json',
        JSON.stringify(content.releases)
      );
      addRoute({
        path: '/changelog',
        component: '@site/src/pages/Changelog',
        modules: { releases: dataPath },
        exact: true,
      });
    },
  };
}

Remark/Rehype Plugins for MDX

// plugins/remark-custom-directives.ts
import type { Plugin } from 'unified';
import { visit } from 'unist-util-visit';

const remarkCustomDirectives: Plugin = () => (tree) => {
  visit(tree, 'containerDirective', (node) => {
    if (node.name === 'api-endpoint') {
      // Transform custom directive into JSX
      node.data = {
        hName: 'div',
        hProperties: { className: ['api-endpoint', `method-${node.attributes?.method}`] },
      };
    }
  });
};

export default remarkCustomDirectives;
// docusaurus.config.ts
presets: [['classic', {
  docs: {
    remarkPlugins: [
      require('./plugins/remark-custom-directives'),
      require('remark-math'),
    ],
    rehypePlugins: [require('rehype-katex')],
  },
}]],

Plugin development for loading external data and creating pages — 2–4 days.