From 2b19bf28d1cc0d598e9cf3ee8b8b71b5124f1b55 Mon Sep 17 00:00:00 2001 From: Elias Perez Date: Sat, 17 Aug 2024 13:49:39 -0400 Subject: [PATCH] Add VitePress configuration for Crystal project docs Introduced a VitePress configuration file to set up documentation for the Crystal project: - Configured project title and description - Implemented MiniSearch for enhanced search functionality - Dynamically generated sidebar and navigation based on sidebar content - Added custom theme settings, including search and outline preferences This configuration aids in maintaining organized and easily navigable documentation. --- vitepress/docs/.vitepress/config.js | 98 +++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 vitepress/docs/.vitepress/config.js diff --git a/vitepress/docs/.vitepress/config.js b/vitepress/docs/.vitepress/config.js new file mode 100644 index 0000000..ba346e7 --- /dev/null +++ b/vitepress/docs/.vitepress/config.js @@ -0,0 +1,98 @@ +import { fileURLToPath } from 'url' +import { dirname, join, parse } from 'path'; +import { readdirSync, readFileSync } from "fs" +import { defineConfig } from 'vitepress' +import MiniSearch from 'minisearch' + +const splitter = "+++" +const sidebar_folder = join(dirname(fileURLToPath(import.meta.url)), "crystal") +const sidebars = readdirSync(sidebar_folder) +const sidebars_json = {} + +sidebars.forEach(x => { + let [name, version] = x.split(splitter) + version = parse(version).name + + const raw = readFileSync(join(sidebar_folder, x), { encoding: "utf-8" }) + + sidebars_json[version] = { + name, + json: JSON.parse(raw) + } +}) +// NOTE: Above code imports all sidebars. + +export default defineConfig({ + title: 'Cql Documentation', + // TODO: Change me. + description: 'My awesome Crystal project!', + lastUpdated: true, + ignoreDeadLinks: true, + base: '/cql/', + themeConfig: { + search: { + provider: 'minisearch', + options: { + // MiniSearch-specific options + fields: ['title', 'description', 'content'], // fields to index + storeFields: ['title', 'description'], // fields to store for display + searchOptions: { + boost: { title: 2 }, // boost title relevance in search + prefix: true, // allow matching by prefix + fuzzy: 0.2 // set fuzzy search tolerance + } + } + }, + outline: { + level: [2, 6], // Specifies which header levels to include in the TOC (e.g., from

to

) + label: 'On this page' // Custom label for the outline + }, + nav: [ + nav() + ], + sidebar: sidebar(), + socialLinks: [ + { icon: 'github', link: 'https://github.com/azutoolkit/cql' } + ] + } +}) + +// NOTE: below code creates the sidebar and navbar +// based on the amount of sidebars and their contents. +function sidebar() { + result = {} + + for (const [key, value] of Object.entries(sidebars_json)) { + result[key] = [ + { + text: "Cql API", + items: value.json + } + ] + } + + return result +} + +function nav() { + if (Object.keys(sidebars_json).length === 1) { + return { + text: 'Cql API', + link: `${Object.values(sidebars_json)[0].json[0].link}` + } + } + + result = { + text: 'Version', + items: [] + } + + for (const [key, value] of Object.entries(sidebars_json)) { + result.items.push({ + text: `${key}`, + link: `${value.json[0].link}` + }) + } + + return result +}