From b94c33faaae7685311abc5caced47ffe3c4985f5 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 5 Nov 2022 23:01:28 +0100 Subject: [PATCH] chore: refactor config Signed-off-by: Matej Focko --- docusaurus.config.js | 97 +++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 56 deletions(-) diff --git a/docusaurus.config.js b/docusaurus.config.js index b7d751a..88f8ae3 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -9,21 +9,47 @@ const katex = require("rehype-katex"); require("dotenv").config(); -function constructDocs(subject) { - return [ - "@docusaurus/plugin-content-docs", - { - id: subject, - path: subject, - routeBasePath: subject, - sidebarPath: require.resolve("./sidebars.js"), - editUrl: "https://gitlab.fi.muni.cz/xfocko/kb/tree/main", - remarkPlugins: [math], - rehypePlugins: [katex], - }, - ]; +class Subject { + constructor(subject, description) { + this.subject = subject; + this.description = description; + } + + docs() { + return [ + "@docusaurus/plugin-content-docs", + { + id: this.subject, + path: this.subject, + routeBasePath: this.subject, + sidebarPath: require.resolve("./sidebars.js"), + editUrl: "https://gitlab.fi.muni.cz/xfocko/kb/tree/main", + remarkPlugins: [math], + rehypePlugins: [katex], + }, + ]; + } + + navbar() { + return { + type: "doc", + docId: `${this.subject}-intro`, + docsPluginId: this.subject, + position: "left", + label: `${this.subject.toUpperCase()}: ${this.description}`, + }; + } } +const subjects = [ + new Subject("ib002", "Algorithms"), + // new Subject("ib015", "Non-imperative programming"), + // new Subject("ib110", "Introduction to informatics"), + // new Subject("ib111", "Foundations of programming"), + new Subject("pb071", "C"), + new Subject("pb161", "C++"), +]; + /** @type {import('@docusaurus/types').Config} */ const config = { title: "Additional materials by mf", @@ -53,7 +79,7 @@ const config = { ], ], - plugins: ["ib002", "ib015", "ib110", "ib111", "pb071", "pb161"].map(constructDocs), + plugins: subjects.map(s => s.docs()), stylesheets: [ { @@ -71,48 +97,7 @@ const config = { navbar: { title: "Additional materials by mf", items: [ - { - type: "doc", - docId: "ib002-intro", - docsPluginId: "ib002", - position: "left", - label: "IB002: Algorithms", - }, - // { - // type: "doc", - // docId: "ib015-intro", - // docsPluginId: "ib015", - // position: "left", - // label: "IB015: Non-imperative programming", - // }, - // { - // type: "doc", - // docId: "ib110-intro", - // docsPluginId: "ib110", - // position: "left", - // label: "IB110: Introduction to informatics", - // }, - // { - // type: "doc", - // docId: "ib111-intro", - // docsPluginId: "ib111", - // position: "left", - // label: "IB111: Foundations of programming", - // }, - { - type: "doc", - docId: "pb071-intro", - docsPluginId: "pb071", - position: "left", - label: "PB071: C", - }, - { - type: "doc", - docId: "pb161-intro", - docsPluginId: "pb161", - position: "left", - label: "PB161: C++", - }, + ...subjects.map(s => s.navbar()), { href: "https://gitlab.fi.muni.cz/xfocko/fi", label: "GitLab",