Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import { defineConfig } from 'vitepress';

export function resolveDocsBase(env: NodeJS.ProcessEnv = process.env): string {
const explicitBase = env.DOCS_BASE ?? env.VITEPRESS_BASE;

if (explicitBase) {
return explicitBase;
}

const repositoryName =
env.GITHUB_ACTIONS === 'true'
? env.GITHUB_REPOSITORY?.split('/')[1]
: undefined;

return repositoryName ? `/${repositoryName}/` : '/';
}

const repositoryBasePath = resolveDocsBase();

export default defineConfig({
title: '@bquery/ui',
description: 'Production-grade web component library for the bQuery project',
base: '/',
base: repositoryBasePath,
themeConfig: {
logo: '/logo.svg',
nav: [
{ text: 'Guide', link: '/guide/getting-started' },
{ text: 'Components', link: '/components/' },
Expand Down
29 changes: 29 additions & 0 deletions tests/docs-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'bun:test';
import config, { resolveDocsBase } from '../docs/.vitepress/config.ts';

describe('docs config', () => {
it('defaults to the site root outside GitHub Pages builds', () => {
expect(resolveDocsBase({})).toBe('/');
});

it('uses the repository base path for GitHub Pages assets in GitHub Actions', () => {
expect(
resolveDocsBase({
GITHUB_ACTIONS: 'true',
GITHUB_REPOSITORY: 'bQuery/ui',
})
).toBe('/ui/');
});

it('allows overriding the docs base explicitly', () => {
expect(resolveDocsBase({ DOCS_BASE: '/preview/' })).toBe('/preview/');
});

it('wires the exported config to the resolved docs base', () => {
expect(config.base).toBe(resolveDocsBase());
});

it('does not reference a missing docs logo asset', () => {
expect((config.themeConfig as { logo?: string }).logo).toBeUndefined();
});
});
Loading