-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
159 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ yarn-error.log* | |
# others | ||
.env*.local | ||
.vercel | ||
next-env.d.ts | ||
next-env.d.ts | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
import { source } from '@/lib/source'; | ||
import { createFromSource } from 'fumadocs-core/search/server'; | ||
import { sync } from 'fumadocs-core/search/orama-cloud'; | ||
import * as fs from 'node:fs/promises'; | ||
import { CloudManager } from '@oramacloud/client'; | ||
|
||
// it should be cached forever | ||
export const revalidate = false; | ||
export const dynamic = 'force-static'; | ||
|
||
export const { staticGET: GET } = createFromSource(source); | ||
const updateSearchIndexes = async (): Promise<void> => { | ||
const apiKey = process.env.ORAMA_PRIVATE_API_KEY; | ||
const indexId = 'k2hnq39jnt7u8l41bfv0ezhd'; | ||
|
||
if (!apiKey) { | ||
console.log('未找到 Orama 私钥, 跳过索引更新'); | ||
return; | ||
} | ||
|
||
try { | ||
const content = await fs.readFile('.next/server/app/static.json.body'); | ||
const records = JSON.parse(content.toString()); | ||
|
||
const manager = new CloudManager({ api_key: apiKey }); | ||
|
||
await sync(manager, { | ||
index: indexId, | ||
documents: records, | ||
}); | ||
|
||
console.log(`搜索索引更新完成: ${records.length} 条记录`); | ||
} catch (error) { | ||
console.error('更新搜索索引时发生错误:', error); | ||
} | ||
} | ||
|
||
void updateSearchIndexes(); | ||
|
||
export async function GET(request: Request) { | ||
// ... GET处理逻辑 ... | ||
} | ||
|
||
export async function POST(request: Request) { | ||
// ... POST处理逻辑 ... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use client'; | ||
import { RootProvider } from 'fumadocs-ui/provider'; | ||
import dynamic from 'next/dynamic'; | ||
import type { ReactNode } from 'react'; | ||
|
||
const SearchDialog = dynamic(() => import('@/app/components/search')); // lazy load | ||
|
||
export function Provider({ children }: { children: ReactNode }) { | ||
return ( | ||
<RootProvider | ||
search={{ | ||
SearchDialog, | ||
}} | ||
> | ||
{children} | ||
</RootProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use client'; | ||
|
||
import { OramaClient } from '@oramacloud/client'; | ||
import type { SharedProps } from 'fumadocs-ui/components/dialog/search'; | ||
import SearchDialog from 'fumadocs-ui/components/dialog/search-orama'; | ||
|
||
const client = new OramaClient({ | ||
endpoint: 'https://cloud.orama.run/v1/indexes/mxspace-no50lj', | ||
api_key: 'HHIpRwosmxFfAs7l2gsJv5m5A3ew2PRB', | ||
}); | ||
|
||
export default function CustomSearchDialog(props: SharedProps) { | ||
return <SearchDialog {...props} client={client} showOrama />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NextResponse } from 'next/server'; | ||
import { source } from '@/lib/source'; | ||
import type { OramaDocument } from 'fumadocs-core/search/orama-cloud'; | ||
|
||
export const revalidate = false; | ||
|
||
export async function GET(): Promise<Response> { | ||
const pages = source.getPages(); | ||
const results = await Promise.all( | ||
pages.map(async (page) => { | ||
const { structuredData } = await page.data; | ||
|
||
return { | ||
id: page.url, | ||
structured: structuredData, | ||
tag: page.slugs[0], | ||
url: page.url, | ||
title: page.data.title, | ||
description: page.data.description, | ||
} satisfies OramaDocument; | ||
}), | ||
); | ||
|
||
return NextResponse.json(results); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { sync } from 'fumadocs-core/search/orama-cloud'; | ||
import * as fs from 'node:fs/promises'; | ||
import { CloudManager } from '@oramacloud/client'; | ||
import * as path from 'path'; | ||
import * as dotenv from 'dotenv'; | ||
|
||
// 加载 .env 文件 | ||
dotenv.config(); | ||
|
||
export async function updateSearchIndexes() { | ||
const apiKey = process.env.ORAMA_PRIVATE_API_KEY; | ||
const indexId = 'k2hnq39jnt7u8l41bfv0ezhd'; // 你的索引 ID | ||
|
||
if (!apiKey) { | ||
console.log('未找到 Orama 私钥, 跳过索引更新'); | ||
return; | ||
} | ||
|
||
try { | ||
// 使用绝对路径 | ||
const staticJsonPath = path.join(process.cwd(), '.next/server/app/static.json.body'); | ||
|
||
try { | ||
await fs.access(staticJsonPath); | ||
} catch { | ||
console.error('static.json.body 文件不存在,请先运行 next build'); | ||
process.exit(1); | ||
} | ||
|
||
const content = await fs.readFile(staticJsonPath); | ||
const records = JSON.parse(content.toString()); | ||
|
||
const manager = new CloudManager({ api_key: apiKey }); | ||
|
||
await sync(manager, { | ||
index: indexId, | ||
documents: records, | ||
}); | ||
|
||
console.log(`搜索索引更新完成: ${records.length} 条记录`); | ||
} catch (error) { | ||
console.error('更新搜索索引时发生错误:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
void updateSearchIndexes(); |