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
5 changes: 5 additions & 0 deletions .changeset/witty-carrots-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": minor
---

feat: add algolia search support
1 change: 1 addition & 0 deletions docs/public/Robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Algolia-Crawler-Verif: 7A640E13F04C80C2
15 changes: 10 additions & 5 deletions doom.config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
lang: zh
title: Doom
logoText: Doom
themeConfig:
socialLinks:
- icon: github
mode: link
content: https://github.com/alauda/doom

api:
crds:
- docs/shared/crds/*.yaml
Expand All @@ -25,8 +31,7 @@ lint:
cspell:
words:
- katanomi
themeConfig:
socialLinks:
- icon: github
mode: link
content: https://github.com/alauda/doom
algolia:
appId:
apiKey:
indexName:
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"./package.json": "./package.json",
"./config": "./lib/config.js",
"./runtime": "./lib/runtime/index.js",
"./theme": "./lib/theme.js",
"./types": "./lib/types.js"
},
"files": [
Expand Down Expand Up @@ -64,6 +65,7 @@
"@rsbuild/plugin-sass": "^1.3.1",
"@rsbuild/plugin-yaml": "^1.0.2",
"@rspress/core": "2.0.0-beta.8",
"@rspress/plugin-algolia": "2.0.0-beta.8",
"@shikijs/transformers": "^3.4.2",
"chokidar": "^4.0.3",
"cli-progress": "^3.12.0",
Expand Down Expand Up @@ -96,7 +98,7 @@
"swagger2openapi": "^7.0.8",
"tinyglobby": "^0.2.14",
"type-fest": "^4.41.0",
"typescript-eslint": "^8.32.1",
"typescript-eslint": "^8.33.0",
"x-fetch": "^0.2.6",
"yaml": "^2.8.0",
"yoctocolors": "^2.1.1"
Expand All @@ -110,7 +112,7 @@
"@total-typescript/ts-reset": "^0.6.1",
"@types/cli-progress": "^3.11.6",
"@types/ejs": "^3.1.5",
"@types/node": "^22.15.21",
"@types/node": "^22.15.23",
"@types/picomatch": "^4.0.0",
"@types/react": "^19.1.6",
"@types/react-dom": "^19.1.5",
Expand Down
6 changes: 6 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ program
FALSY_VALUES.has(value) ? false : TRUTHY_VALUES.has(value) || value,
false,
)
.option(
'-a, --algolia',
'Whether to enable Algolia search',
parseBoolean,
false,
)
.option(
'-n, --no-open [boolean]',
'Do not open the browser after starting the server',
Expand Down
32 changes: 27 additions & 5 deletions src/cli/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const getCommonConfig = async ({
exclude,
redirect,
editRepo,
algolia,
}: {
config: UserConfig
configFilePath?: string
Expand All @@ -130,6 +131,7 @@ const getCommonConfig = async ({
exclude?: string[]
redirect?: 'auto' | 'never' | 'only-default-lang'
editRepo?: boolean | string
algolia?: boolean
}): Promise<UserConfig> => {
const fallbackToZh = 'lang' in config && !config.lang
root = resolveDocRoot(CWD, root, config.root)
Expand Down Expand Up @@ -285,12 +287,30 @@ const getCommonConfig = async ({
open,
},
tools: {
rspack: {
resolve: {
extensionAlias: {
'.js': ['.ts', '.tsx', '.js'],
rspack(rspackConfig, { mergeConfig, rspack }) {
return mergeConfig(rspackConfig, {
resolve: {
extensionAlias: {
'.js': ['.ts', '.tsx', '.js'],
},
},
},
plugins:
algolia && config.algolia
? [
new rspack.DefinePlugin({
'process.env.ALGOLIA_APP_ID': JSON.stringify(
config.algolia.appId,
),
'process.env.ALGOLIA_API_KEY': JSON.stringify(
config.algolia.apiKey,
),
'process.env.ALGOLIA_INDEX_NAME': JSON.stringify(
config.algolia.indexName,
),
}),
]
: undefined,
})
},
},
},
Expand Down Expand Up @@ -323,6 +343,7 @@ export async function loadConfig(
outDir,
redirect,
editRepo,
algolia,
}: GlobalCliOptions = {},
): Promise<{
config: UserConfig
Expand Down Expand Up @@ -402,6 +423,7 @@ export async function loadConfig(
exclude,
redirect,
editRepo,
algolia,
})

base = commonConfig.base!
Expand Down
22 changes: 22 additions & 0 deletions src/theme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Search as OriginalSearch } from '@rspress/core/theme'
import { Search as AlgoliaSearch } from '@rspress/plugin-algolia/runtime'

const Search =
process.env.ALGOLIA_APP_ID &&
process.env.ALGOLIA_API_KEY &&
process.env.ALGOLIA_INDEX_NAME
? () => (
<AlgoliaSearch
docSearchProps={{
appId: process.env.ALGOLIA_APP_ID!,
apiKey: process.env.ALGOLIA_API_KEY!,
indexName: process.env.ALGOLIA_INDEX_NAME!,
}}
/>
)
: OriginalSearch

// eslint-disable-next-line import-x/export
export * from '@rspress/core/theme'
// eslint-disable-next-line import-x/export
export { Search }
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface GlobalCliOptions {
outDir?: string
redirect?: 'auto' | 'never' | 'only-default-lang'
editRepo?: boolean | string
algolia?: boolean
}

export interface TranslateOptions {
Expand All @@ -41,6 +42,12 @@ export interface LintOptions {
cspellOptions?: Partial<Options>
}

export interface AlgoliaOptions {
appId: string
apiKey: string
indexName: string
}

declare module '@rspress/shared' {
interface UserConfig {
prefix?: string
Expand All @@ -56,6 +63,7 @@ declare module '@rspress/shared' {
translate?: TranslateOptions
editRepoBaseUrl?: string
lint?: LintOptions
algolia?: AlgoliaOptions
}

interface SiteData {
Expand Down
1 change: 1 addition & 0 deletions theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@alauda/doom/theme'
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"target": "ESNext",
"paths": {
"@alauda/doom/config": ["./src/config.ts"],
"@alauda/doom/runtime": ["./src/runtime/index.ts"]
"@alauda/doom/runtime": ["./src/runtime/index.ts"],
"@alauda/doom/theme": ["./src/theme.tsx"]
},
"stripInternal": true,
"verbatimModuleSyntax": true
Expand Down
Loading