Files
xo-stack/packages/docs/src/.vitepress/config.ts
T
2025-01-15 03:05:53 +00:00

234 lines
5.9 KiB
TypeScript

import { defineConfig } from 'vitepress';
import typedocSidebar from '../api/typedoc-sidebar.json';
// Special cases map for acronyms and exceptions
const SPECIAL_CASES = {
hd: 'HD',
indexeddb: 'IndexedDB',
inmemory: 'InMemory',
json: 'JSON',
p2p: 'P2P',
p2pkh: 'P2PKH',
p2sh: 'P2SH',
p2sh20: 'P2SH20',
p2sh32: 'P2SH32',
sse: 'SSE',
utxo: 'UTXO',
};
function toPascalCase(str: string) {
// Handle special cases first
const lowerStr = str.toLowerCase();
if (lowerStr.startsWith('@')) {
return str;
}
// Split by common delimiters (hyphen, space, underscore)
return str
.split(/[-\s_]/)
.map((word) => {
if (word.length === 0) return '';
if (SPECIAL_CASES[word]) {
return SPECIAL_CASES[word];
}
// Capitalize first letter, lowercase rest
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join('');
}
function convertNavToPascalCase(nav: Array<any>) {
console.log(nav);
return nav.map((item) => {
const result = { ...item };
// Convert the text field
if (result.text) {
// If there was a @ prefix, preserve it
result.text = item.text.startsWith('@')
? result.text
: toPascalCase(result.text);
}
// Recursively process nested items
if (result.items && Array.isArray(result.items)) {
result.items = convertNavToPascalCase(result.items);
}
return result;
});
}
// https://vitepress.dev/reference/site-config
export default defineConfig({
outDir: '../dist',
title: 'Stack',
description:
'XO Stack: Building smart applications on the Bitcoin Cash Network',
themeConfig: {
// Set the logo
logo: {
light: '/logo-light.svg',
dark: '/logo-dark.svg',
},
// Enable search functionality.
// TODO: Re-enable once we release documentation.
/*
search: {
provider: 'local',
},
*/
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
// TODO: Re-enable once we release documentation
// { text: 'Documentation', link: '/quick-start' },
{ text: 'Tools', link: '/tools/primitives' },
],
sidebar: {
// Default Side Menu.
'/': [
{
text: 'Guide',
items: [
{ text: 'Quick Start', link: '/quick-start' },
{ text: 'Best Practices', link: '/api-examples' },
],
},
{
text: 'Frameworks',
items: [
{ text: 'Vue', link: '/frameworks/vue' },
{ text: 'React', link: '/frameworks/react' },
{ text: 'Svelte', link: '/frameworks/svelte' },
],
},
{
text: 'API',
items: convertNavToPascalCase(typedocSidebar),
},
],
// Side-menu for all routes under /tools/
'/tools/': [
{
text: 'XO Tools',
items: [
{
text: 'Primitives',
link: '/tools/primitives',
collapsed: false,
items: [
{ text: 'Address', link: '/tools/primitives#address' },
{
text: 'Block Header',
link: '/tools/primitives#block-header',
},
{ text: 'Bytes', link: '/tools/primitives#bytes' },
{
text: 'HD Private Node',
link: '/tools/primitives#hd-private-node',
},
{
text: 'HD Public Node',
link: '/tools/primitives#hd-public-node',
},
{
text: 'Mnemonic',
link: '/tools/primitives#mnemonic',
},
{
text: 'Private Key',
link: '/tools/primitives#private-key',
},
{
text: 'Public Key',
link: '/tools/primitives#public-key',
},
{
text: 'Satoshis',
link: '/tools/primitives#satoshis',
},
{
text: 'Script',
link: '/tools/primitives#script',
},
{
text: 'Transaction',
link: '/tools/primitives#transaction',
},
],
},
{
text: 'Stack',
collapsed: false,
items: [
/*
{
text: 'Blockchain',
link: '/tools/stack/blockchain',
items: [
{
text: 'Electrum',
link: '/tools/stack/blockchain#encryption',
},
],
},
*/
{
text: 'Utils',
link: '/tools/stack/utils',
items: [
{
text: 'Encrypter',
link: '/tools/stack/utils#encrypter',
},
{ text: 'Hasher', link: '/tools/stack/utils#hasher' },
],
},
],
},
],
},
],
},
/*
*/
socialLinks: [
{ icon: 'github', link: 'https://gitlab.com/GeneralProtocols/xo/stack' },
],
// This is the outline on the right-hand side of the page.
outline: {
level: [2, 4],
label: 'On this page',
},
},
head: [['link', { rel: 'icon', href: '/favicon.png' }]],
// Set the dev and build targets to "esnext"
// NOTE: We do this so that we can support top-level-await.
vite: {
esbuild: {
target: 'esnext',
},
build: {
target: 'esnext',
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
},
},
});