Skip to content
Snippets Groups Projects
next.config.mjs 2.76 KiB
Newer Older
Tim Bastin's avatar
Tim Bastin committed
// Copyright 2025 Zentrum für Digitale Souveränität der Öffentlichen Verwaltung (ZenDiS) GmbH.
// SPDX-License-Identifier: MIT

Sebastian Kawelke's avatar
Sebastian Kawelke committed
import nextra from 'nextra'
import { visit } from 'unist-util-visit'
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'

var transformer = function (ast) {
    const glossaryPath = path.join(process.cwd(), '/.glossary.yaml')
    var acronyms = {}

    try {
        const fileContents = fs.readFileSync(glossaryPath, 'utf8')
        acronyms = yaml.load(fileContents)
    } catch (error) {
        console.error('Error loading glossary:', error)
    }

    var acronymsRegExp = new RegExp(
        '\\b('.concat(Object.keys(acronyms).join('|'), ')\\b'),
        'g',
    )

    visit(ast, 'paragraph', function (node) {
        // Replace acronyms in text nodes
        node.children = node.children
            .map(function (child) {
                if (child.type === 'text') {
                    // check if the text node contains an acronym
                    // if so, we return multiple new abbrev and text nodes
                    const newChildren = child.value
                        .split(acronymsRegExp)
                        .map(function (part) {
                            if (acronyms[part]) {
                                return {
                                    type: 'abbr',
                                    data: {
                                        hName: 'abbr',
                                        hChildren: [
                                            {
                                                type: 'text',
                                                value: part,
                                            },
                                        ],
                                        hProperties: {
                                            title: acronyms[part],
                                        },
                                    },
                                }
                            } else {
                                return {
                                    type: 'text',
                                    value: part,
                                }
                            }
                        })
                    return newChildren
                }

                return [child]
            })
            .flat()
    })

    return ast
}

const remarkAbbrev = function () {
    return transformer
}
const nextConfig = {
    output: 'export',
    images: {
        unoptimized: true, // mandatory, otherwise won't export
    },
}
Sebastian Kawelke's avatar
Sebastian Kawelke committed
const withNextra = nextra({
    theme: 'nextra-theme-docs',
    themeConfig: './theme.config.tsx',
    mdxOptions: {
        remarkPlugins: [remarkAbbrev],
    },
export default withNextra(nextConfig)

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.