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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
"hastscript": "^9.0.1",
"highlight.js": "^11.11.1",
"lodash": "^4.17.21",
"mermaid": "^11.11.0",
"minisearch": "^7.1.2",
"moment": "^2.30.1",
"mui-message": "^1.1.0",
"next": "^15.4.5",
"next-international": "^1.3.1",
"next-themes": "^0.4.4",
"panzoom": "^9.4.3",
"react": "^19.0.0",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^19.0.0",
Expand Down
150 changes: 128 additions & 22 deletions scripts/generate-docs-index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,134 @@ const OUTPUT = path.join(ROOT_DIR, 'public/docs-index.json');
function extractKeywords(text, minLength = 3, maxCount = 20) {
// Common stop words
const stopWords = new Set([
'the', 'is', 'at', 'which', 'on', 'and', 'a', 'to', 'are', 'as', 'was', 'were',
'been', 'be', 'have', 'has', 'had', 'do', 'does', 'did', 'will', 'would', 'could',
'should', 'may', 'might', 'can', 'must', 'shall', 'of', 'in', 'for', 'with', 'by',
'from', 'up', 'about', 'into', 'through', 'during', 'before', 'after', 'above',
'below', 'to', 'under', 'again', 'further', 'then', 'once', 'here', 'there',
'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more',
'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same',
'so', 'than', 'too', 'very', 'can', 'just', 'now', 'also', 'if', 'this',
'that', 'these', 'those', 'i', 'me', 'my', 'myself', 'we', 'our', 'ours',
'ourselves', 'you', 'your', 'yours', 'yourself', 'yourselves', 'he', 'him',
'his', 'himself', 'she', 'her', 'hers', 'herself', 'it', 'its', 'itself',
'they', 'them', 'their', 'theirs', 'themselves'
'the',
'is',
'at',
'which',
'on',
'and',
'a',
'to',
'are',
'as',
'was',
'were',
'been',
'be',
'have',
'has',
'had',
'do',
'does',
'did',
'will',
'would',
'could',
'should',
'may',
'might',
'can',
'must',
'shall',
'of',
'in',
'for',
'with',
'by',
'from',
'up',
'about',
'into',
'through',
'during',
'before',
'after',
'above',
'below',
'to',
'under',
'again',
'further',
'then',
'once',
'here',
'there',
'when',
'where',
'why',
'how',
'all',
'any',
'both',
'each',
'few',
'more',
'most',
'other',
'some',
'such',
'no',
'nor',
'not',
'only',
'own',
'same',
'so',
'than',
'too',
'very',
'can',
'just',
'now',
'also',
'if',
'this',
'that',
'these',
'those',
'i',
'me',
'my',
'myself',
'we',
'our',
'ours',
'ourselves',
'you',
'your',
'yours',
'yourself',
'yourselves',
'he',
'him',
'his',
'himself',
'she',
'her',
'hers',
'herself',
'it',
'its',
'itself',
'they',
'them',
'their',
'theirs',
'themselves',
]);

const words = text
.toLowerCase()
.replace(/[^\w\s]/g, ' ')
.split(/\s+/)
.filter(word =>
word.length >= minLength &&
!stopWords.has(word) &&
!/^\d+$/.test(word)
.filter(
(word) =>
word.length >= minLength && !stopWords.has(word) && !/^\d+$/.test(word),
);

// Calculate word frequency
const wordCounts = {};
words.forEach(word => {
words.forEach((word) => {
wordCounts[word] = (wordCounts[word] || 0) + 1;
});

Expand Down Expand Up @@ -73,7 +174,7 @@ function generateSummary(content, maxLength = 200) {
const lastSentenceEnd = Math.max(
truncated.lastIndexOf('.'),
truncated.lastIndexOf('!'),
truncated.lastIndexOf('?')
truncated.lastIndexOf('?'),
);

if (lastSentenceEnd > maxLength * 0.7) {
Expand All @@ -96,7 +197,9 @@ function extractMetadata(filePath, frontmatter) {
docType = 'documentation';

// 从路径中提取产品类别
const productMatch = filePath.match(/docs\/en\/[^/]*\/kubeblocks-for-([^/]+)/);
const productMatch = filePath.match(
/docs\/en\/[^/]*\/kubeblocks-for-([^/]+)/,
);
if (productMatch) {
category = productMatch[1];
} else if (filePath.includes('user_docs')) {
Expand Down Expand Up @@ -129,7 +232,7 @@ async function main() {
'blogs/en/**/*.mdx',
'!docs/en/preview/**/cli/**',
'!docs/en/preview/**/release_notes/**',
'!docs/en/release-*/**', // 明确排除所有release版本目录
'!docs/en/release-*/**', // 明确排除所有release版本目录
],
{ cwd: ROOT_DIR, absolute: true },
);
Expand Down Expand Up @@ -172,7 +275,7 @@ async function main() {
const headings = [];
const headingMatches = content.match(/^#{1,6}\s+.+$/gm);
if (headingMatches) {
headingMatches.forEach(heading => {
headingMatches.forEach((heading) => {
const level = (heading.match(/^#+/) || [''])[0].length;
const text = heading.replace(/^#+\s+/, '').trim();
headings.push({ level, text });
Expand All @@ -181,7 +284,10 @@ async function main() {

return {
id: relPath.replace(/\//g, '_').replace(/\.(md|mdx)$/, ''),
title: data.title || data.sidebar_label || path.basename(file, path.extname(file)),
title:
data.title ||
data.sidebar_label ||
path.basename(file, path.extname(file)),
content: fullContent,
path: normPath,
description: data.description || summary,
Expand Down
6 changes: 4 additions & 2 deletions src/app/[locale]/ElevationScrollAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ export const ElevationScrollAppBar = (props: AppBarProps) => {
<Box sx={searchBarStyles.container}>
<TextField
size="small"
placeholder={mobile ? "Search..." : "Search docs..."}
placeholder={mobile ? 'Search...' : 'Search docs...'}
variant="outlined"
onClick={() => setShowSearch(true)}
InputProps={{
startAdornment: <SearchIcon sx={searchBarStyles.searchIcon} />,
startAdornment: (
<SearchIcon sx={searchBarStyles.searchIcon} />
),
endAdornment: !mobile && (
<Box sx={searchBarStyles.shortcutContainer}>
<Box component="kbd" sx={searchBarStyles.shortcutKey}>
Expand Down
23 changes: 12 additions & 11 deletions src/app/api/search-index/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { readFileSync, readdirSync, existsSync } from 'fs';
import { existsSync, readFileSync, readdirSync } from 'fs';
import matter from 'gray-matter';
import { NextResponse } from 'next/server';
import { join } from 'path';

export const dynamic = 'force-static'; // force-dynamic | force-static

interface SearchDocument {
id: string;
title: string;
Expand Down Expand Up @@ -68,15 +70,16 @@ function extractContent(filePath: string): SearchDocument {
.trim();

// 生成摘要
const summary = plainContent.length > 200 ?
plainContent.substring(0, 200) + '...' :
plainContent;
const summary =
plainContent.length > 200
? plainContent.substring(0, 200) + '...'
: plainContent;

// 提取关键词
const keywords = plainContent
.toLowerCase()
.split(/\s+/)
.filter(word => word.length > 3)
.filter((word) => word.length > 3)
.reduce((acc: string[], word) => {
if (!acc.includes(word)) acc.push(word);
return acc;
Expand All @@ -87,7 +90,7 @@ function extractContent(filePath: string): SearchDocument {
const headings: Array<{ level: number; text: string }> = [];
const headingMatches = markdownContent.match(/^#{1,6}\s+.+$/gm);
if (headingMatches) {
headingMatches.forEach(heading => {
headingMatches.forEach((heading) => {
const level = (heading.match(/^#+/) || [''])[0].length;
const text = heading.replace(/^#+\s+/, '').trim();
headings.push({ level, text });
Expand Down Expand Up @@ -142,19 +145,17 @@ export async function GET() {
const previewDir = join(rootDir, 'docs', 'en', 'preview');
if (existsSync(previewDir)) {
const previewFiles = getAllMdxFiles(previewDir, 'docs/en/preview');
allFiles.push(...previewFiles.map(file => join(rootDir, file)));
allFiles.push(...previewFiles.map((file) => join(rootDir, file)));
}

// 获取blogs/en下的文件
const blogsEnDir = join(rootDir, 'blogs', 'en');
if (existsSync(blogsEnDir)) {
const blogFiles = getAllMdxFiles(blogsEnDir, 'blogs/en');
allFiles.push(...blogFiles.map(file => join(rootDir, file)));
allFiles.push(...blogFiles.map((file) => join(rootDir, file)));
}

const documents = allFiles.map((filePath) =>
extractContent(filePath),
);
const documents = allFiles.map((filePath) => extractContent(filePath));

return NextResponse.json(documents);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
);

// ignore some category
if(["release_notes"].includes(category)) {
if (['release_notes'].includes(category)) {
return;
}

Expand Down
Loading