mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-13 08:12:54 -07:00
Add canonical URLs and sitemap dedup for docs homepage indexability
- Emit self-referential canonical `<link>` tags on every VitePress page - Filter duplicate /README entry from generated sitemap - Extract DOCS_HOSTNAME constant; update Plausible test to match - Add seo.test.ts covering canonical generation and sitemap filtering
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import type { TransformContext } from 'vitepress';
|
||||
import docsConfig from './.vitepress/config';
|
||||
|
||||
function makeTransformContext(page: string): TransformContext {
|
||||
return {
|
||||
page,
|
||||
siteConfig: {} as TransformContext['siteConfig'],
|
||||
siteData: {} as TransformContext['siteData'],
|
||||
pageData: {} as TransformContext['pageData'],
|
||||
title: 'SubMiner',
|
||||
description: 'SubMiner docs',
|
||||
head: [],
|
||||
content: '',
|
||||
assets: [],
|
||||
};
|
||||
}
|
||||
|
||||
test('docs pages emit stable self-referential canonical URLs', async () => {
|
||||
const rootHead = await docsConfig.transformHead?.(makeTransformContext('index.md'));
|
||||
const usageHead = await docsConfig.transformHead?.(makeTransformContext('usage.md'));
|
||||
|
||||
expect(rootHead).toContainEqual([
|
||||
'link',
|
||||
{ rel: 'canonical', href: 'https://docs.subminer.moe/' },
|
||||
]);
|
||||
expect(usageHead).toContainEqual([
|
||||
'link',
|
||||
{ rel: 'canonical', href: 'https://docs.subminer.moe/usage' },
|
||||
]);
|
||||
expect(JSON.stringify(rootHead).toLowerCase()).not.toContain('noindex');
|
||||
});
|
||||
|
||||
test('docs sitemap excludes duplicate README page from indexable URLs', async () => {
|
||||
const items = [{ url: '' }, { url: 'README' }, { url: 'usage' }];
|
||||
|
||||
const transformedItems = await docsConfig.sitemap?.transformItems?.(items);
|
||||
|
||||
expect(transformedItems?.map((item) => item.url)).toEqual(['', 'usage']);
|
||||
});
|
||||
Reference in New Issue
Block a user