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/new-numbers-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

feat: bump rspress to v2.0.0-beta.20
2 changes: 1 addition & 1 deletion .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:
run: yarn format

- name: Apply autofix.ci
uses: autofix-ci/action@2891949f3779a1cafafae1523058501de3d4e944 # v1
uses: autofix-ci/action@635ffb0c9798bd160680f18fd73371e355b85f27 # v1.3.2
with:
fail-fast: false
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
rm -rf $tempdir

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default config(
'doom-@global-virtual',
'doom-@permission-functionResourcesMap',
'doom-@permission-roleTemplatesMap',
'virtual-runtime-config',
],
},
],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
"@rsbuild/plugin-sass": "^1.3.3",
"@rsbuild/plugin-svgr": "^1.2.1",
"@rsbuild/plugin-yaml": "^1.0.2",
"@rspress/core": "2.0.0-beta.14",
"@rspress/plugin-algolia": "2.0.0-beta.14",
"@rspress/plugin-llms": "2.0.0-beta.14",
"@rspress/core": "2.0.0-beta.20",
"@rspress/plugin-algolia": "2.0.0-beta.20",
"@rspress/plugin-llms": "2.0.0-beta.20",
"@shikijs/transformers": "^3.7.0",
"@total-typescript/ts-reset": "^0.6.1",
"chokidar": "^4.0.3",
Expand Down
6 changes: 6 additions & 0 deletions shim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ declare module 'doom-@permission-roleTemplatesMap' {
export default roleTemplatesMap
}

declare module 'virtual-runtime-config' {
import type { NormalizedRuntimeConfig } from '@rspress/shared'

export const base: NormalizedRuntimeConfig['base']
}

declare module 'md-attr-parser' {
const parseAttrs: (value?: string | null) => {
prop: Record<string, string>
Expand Down
4 changes: 2 additions & 2 deletions src/cli/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const exportCommand = new Command('export')
ServeOptions & GlobalCliOptions
>()

let { config } = await loadConfig(root, {
let { config, configFilePath } = await loadConfig(root, {
...globalOptions,
export: true,
})
Expand All @@ -84,7 +84,7 @@ export const exportCommand = new Command('export')

logger.start('Serving...')

await serve({ config, host, port })
await serve({ config, configFilePath, host, port })

const tempDir = path.resolve(outDir, '.doom')

Expand Down
14 changes: 8 additions & 6 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,14 @@ program
>()

const startDevServer = async () => {
const { config, filepath } = await loadConfig(root, globalOptions)
const { config, configFilePath } = await loadConfig(root, globalOptions)

const docDirectory = config.root!

try {
devServer = await dev({
config,
configFilePath,
appDirectory: CWD,
docDirectory,
extraBuilderConfig: {
Expand All @@ -156,8 +157,8 @@ program
}

cliWatcher = watch(
filepath
? [filepath, config.i18nSourcePath!, docDirectory, SITES_FILE]
configFilePath
? [configFilePath, config.i18nSourcePath!, docDirectory, SITES_FILE]
: [...CONFIG_FILES, docDirectory],
{
ignoreInitial: true,
Expand Down Expand Up @@ -217,7 +218,7 @@ program
.action(async function (root?: string) {
setNodeEnv('production')

const { config } = await loadConfig(
const { config, configFilePath } = await loadConfig(
root,
this.optsWithGlobals<GlobalCliOptions>(),
)
Expand All @@ -227,6 +228,7 @@ program
const runBuild = () =>
build({
config,
configFilePath,
docDirectory,
})

Expand All @@ -252,9 +254,9 @@ program
ServeOptions & GlobalCliOptions
>()

const { config } = await loadConfig(root, globalOptions)
const { config, configFilePath } = await loadConfig(root, globalOptions)

await serve({ config, host, port })
await serve({ config, configFilePath, host, port })
})

program.addCommand(newCommand)
Expand Down
13 changes: 7 additions & 6 deletions src/cli/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ const getCommonConfig = async ({
server: {
open,
},
performance: {
buildCache: {
cacheDigest: [root, configFilePath, base, version],
},
},
tools: {
rspack(rspackConfig, { mergeConfig, rspack }) {
return mergeConfig(rspackConfig, {
Expand Down Expand Up @@ -387,7 +392,7 @@ export async function loadConfig(
}: GlobalCliOptions = {},
): Promise<{
config: UserConfig
filepath?: string
configFilePath: string
}> {
let configFilePath: string | undefined

Expand Down Expand Up @@ -538,13 +543,9 @@ export async function loadConfig(
(isExplicitlyUnversioned(version) ? UNVERSIONED : outDir ? version : '')
}`

if (mergedConfig.builderConfig?.server?.open === true) {
mergedConfig.builderConfig.server.open = mergedConfig.base
}

return {
config: mergedConfig,
filepath: configFilePath,
configFilePath: configFilePath || '',
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/global/VersionsNav/NavMenuGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Tag } from '@rspress/core/theme'
import {
isExternalUrl,
matchNavbar,
type NavItem,
type NavItemWithChildren,
type NavItemWithLink,
type NavItemWithLinkAndChildren,
} from '@rspress/shared'
import { useRef, useState, type ReactNode } from 'react'

import { matchNavbar } from '../../shared/index.js'

import { Down } from './Down.js'
import {
NavMenuSingleItem,
Expand Down
7 changes: 2 additions & 5 deletions src/global/VersionsNav/NavMenuSingleItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Tag } from '@rspress/core/theme'
import {
isExternalUrl,
withoutBase,
type NavItemWithLink,
} from '@rspress/shared'
import { isExternalUrl, type NavItemWithLink } from '@rspress/shared'
import { useMemo, type ReactNode } from 'react'

import styles from '../../../styles/versions-nav.module.scss'
import { withoutBase } from '../../shared/index.js'

export interface NavMenuSingleItemProps extends Omit<NavItemWithLink, 'text'> {
base?: string
Expand Down
13 changes: 5 additions & 8 deletions src/global/VersionsNav/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
isProduction,
NoSSR,
removeTrailingSlash,
usePageData,
withBase,
} from '@rspress/core/runtime'
Expand All @@ -10,6 +9,7 @@ import virtual from 'doom-@global-virtual'
import { noop } from 'es-toolkit'
import { useEffect, useMemo, useState } from 'react'
import { createPortal } from 'react-dom'
import { base } from 'virtual-runtime-config'
import { parse } from 'yaml'

import {
Expand Down Expand Up @@ -71,13 +71,10 @@ const VersionsNav_ = () => {
return [
isExplicitlyUnversioned(virtual.version)
? undefined
: removeTrailingSlash(siteData.base).slice(
0,
-unversionedVersion.length - 1,
),
: base.slice(0, -unversionedVersion.length - 1),
unversionedVersion,
]
}, [siteData.base])
}, [])

const [navMenu, setNavMenu] = useState(getNavMenu)

Expand All @@ -91,7 +88,7 @@ const VersionsNav_ = () => {
}
} else {
const res = await fetch(
`${isProduction() ? versionsBase : ''}/versions.yaml`,
`${isProduction() ? versionsBase : base}/versions.yaml`,
)
if (!res.ok) {
return
Expand Down Expand Up @@ -170,7 +167,7 @@ const VersionsNav_ = () => {
text={version}
base={versionsBase}
items={navItems}
pathname={siteData.base}
pathname={base}
/>
)}
</>,
Expand Down
56 changes: 34 additions & 22 deletions src/runtime/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import {
isEqualPath,
normalizeHrefInRuntime as normalizeHref,
usePageData,
withBase,
} from '@rspress/runtime'
import type {
Header,
NormalizedSidebarGroup,
SidebarDivider,
SidebarItem,
SidebarSectionHeader,
} from '@rspress/shared'
import { Fragment, useCallback, useMemo } from 'react'

import classes from '../../../styles/overview.module.scss'

import { findItemByRoutePath } from './_utils.js'
import {
findItemByRoutePath,
isSidebarDivider,
isSidebarSectionHeader,
isSingleFile,
} from './_utils.js'

interface GroupItem {
text: string
Expand All @@ -30,7 +35,11 @@ interface Group {
}

const getChildLink = (
traverseItem: SidebarDivider | SidebarItem | NormalizedSidebarGroup,
traverseItem:
| SidebarDivider
| SidebarSectionHeader
| SidebarItem
| NormalizedSidebarGroup,
): string => {
if ('link' in traverseItem && traverseItem.link) {
return traverseItem.link
Expand Down Expand Up @@ -61,8 +70,8 @@ export function Overview(props: {
(link: string) =>
// sidebar items link without base path
// pages route path with base path
withBase(link).startsWith(routePath.replace(/overview$/, '')) &&
!isEqualPath(withBase(link), routePath),
link.startsWith(routePath.replace(/overview$/, '')) &&
!isEqualPath(link, routePath),
[routePath],
)

Expand All @@ -88,28 +97,31 @@ export function Overview(props: {

const normalizeSidebarItem = useCallback(
(
item: SidebarItem | SidebarDivider | NormalizedSidebarGroup,
item:
| SidebarItem
| SidebarSectionHeader
| SidebarDivider
| NormalizedSidebarGroup,
sidebarGroup?: NormalizedSidebarGroup,
frontmatter?: Record<string, unknown>,
) => {
if ('dividerType' in item) {
return item
if (isSidebarDivider(item) || isSidebarSectionHeader(item)) {
return false
}

// do not display overview title in sub pages overview
if (
withBase(item.link) === `${routePath}index` &&
frontmatter?.overview === true
) {
if (item.link === `${routePath}index` && frontmatter?.overview === true) {
return false
}

// props > frontmatter in single file > _meta.json config in a file > frontmatter in overview page > _meta.json config in sidebar
const overviewHeaders = props.overviewHeaders ??
item.overviewHeaders ??
(frontmatter?.overviewHeaders as number[] | undefined) ??
sidebarGroup?.overviewHeaders ?? [2]
// sidebar items link without base path
const pageModule = overviewModules.find((m) =>
isEqualPath(m.routePath, withBase(item.link || '')),
isEqualPath(m.routePath, item.link || ''),
)
const link = getChildLink(item)
return {
Expand All @@ -125,14 +137,14 @@ export function Overview(props: {
[overviewModules, props.overviewHeaders, routePath],
)

const isSingleFile = (
item: SidebarItem | SidebarDivider | NormalizedSidebarGroup,
): item is SidebarItem | (NormalizedSidebarGroup & { link: string }) =>
!('items' in item) && 'link' in item

const getGroup = useCallback(
(
sidebarGroups: (NormalizedSidebarGroup | SidebarItem | SidebarDivider)[],
sidebarGroups: (
| NormalizedSidebarGroup
| SidebarSectionHeader
| SidebarItem
| SidebarDivider
)[],
) => {
const group = sidebarGroups
.filter((sidebarGroup) => {
Expand All @@ -151,13 +163,13 @@ export function Overview(props: {
return false
})
.map((sidebarGroup) => {
let items: (GroupItem | SidebarDivider)[] = []
let items: GroupItem[] = []
if ('items' in sidebarGroup) {
items = sidebarGroup.items
.map((item) =>
normalizeSidebarItem(item, sidebarGroup, frontmatter),
)
.filter((_): _ is GroupItem | SidebarDivider => !!_)
.filter(Boolean)
} else if (isSingleFile(sidebarGroup)) {
items = [
normalizeSidebarItem(
Expand All @@ -171,7 +183,7 @@ export function Overview(props: {
undefined,
frontmatter,
),
].filter((_): _ is GroupItem | SidebarDivider => !!_)
].filter(Boolean)
}
return {
name: ('text' in sidebarGroup && sidebarGroup.text) || '',
Expand Down
Loading