From 145bb161943f536c50c28713ceb57e4db1cba125 Mon Sep 17 00:00:00 2001 From: Zhanghao Date: Sun, 24 Mar 2024 16:58:55 +0800 Subject: [PATCH] feat: support logo text config (#855) --- .changeset/wet-ears-suffer.md | 8 ++++++++ .../core/src/node/runtimeModule/siteData/index.ts | 1 + .../document/docs/en/api/config/config-basic.mdx | 15 +++++++++++++++ .../document/docs/zh/api/config/config-basic.mdx | 15 +++++++++++++++ packages/shared/src/types/index.ts | 5 +++++ .../src/components/Nav/NavBarTitle.tsx | 8 ++++---- 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .changeset/wet-ears-suffer.md diff --git a/.changeset/wet-ears-suffer.md b/.changeset/wet-ears-suffer.md new file mode 100644 index 000000000..da2f49a83 --- /dev/null +++ b/.changeset/wet-ears-suffer.md @@ -0,0 +1,8 @@ +--- +"@rspress/theme-default": patch +"@rspress/docs": patch +"@rspress/shared": patch +"@rspress/core": patch +--- + +feat: support logo text config diff --git a/packages/core/src/node/runtimeModule/siteData/index.ts b/packages/core/src/node/runtimeModule/siteData/index.ts index 832def28c..491286c7c 100644 --- a/packages/core/src/node/runtimeModule/siteData/index.ts +++ b/packages/core/src/node/runtimeModule/siteData/index.ts @@ -96,6 +96,7 @@ export async function siteDataVMPlugin(context: FactoryContext) { lang: userConfig?.lang || '', locales: userConfig?.locales || userConfig.themeConfig?.locales || [], logo: userConfig?.logo || '', + logoText: userConfig?.logoText || '', ssg: userConfig?.ssg ?? true, multiVersion: { default: userConfig?.multiVersion?.default || '', diff --git a/packages/document/docs/en/api/config/config-basic.mdx b/packages/document/docs/en/api/config/config-basic.mdx index 011f33aa2..f9a193c71 100644 --- a/packages/document/docs/en/api/config/config-basic.mdx +++ b/packages/document/docs/en/api/config/config-basic.mdx @@ -116,6 +116,21 @@ export default defineConfig({ }); ``` +## logoText + +- Type: `string` +- Default: `""` + +Site logo Text. This text will be used as the logo text in the upper left corner of the navbar. For example: + +```ts title="rspress.config.ts" +import { defineConfig } from 'rspress/config'; + +export default defineConfig({ + logoText: 'rspress', +}); +``` + ## outDir - Type: `string` diff --git a/packages/document/docs/zh/api/config/config-basic.mdx b/packages/document/docs/zh/api/config/config-basic.mdx index 166eb58a9..3c3760ee2 100644 --- a/packages/document/docs/zh/api/config/config-basic.mdx +++ b/packages/document/docs/zh/api/config/config-basic.mdx @@ -116,6 +116,21 @@ export default defineConfig({ }); ``` +## logoText + +- Type: `string` +- Default: `""` + +站点 logo 文字。这个文字将用作导航栏左上角的 logo 文字。例如: + +```ts title="rspress.config.ts" +import { defineConfig } from 'rspress/config'; + +export default defineConfig({ + logoText: 'rspress', +}); +``` + ## outDir - Type: `string` diff --git a/packages/shared/src/types/index.ts b/packages/shared/src/types/index.ts index 564756c1c..b835b66c5 100644 --- a/packages/shared/src/types/index.ts +++ b/packages/shared/src/types/index.ts @@ -58,6 +58,10 @@ export interface UserConfig { * Path to the logo file in nav bar. */ logo?: string | { dark: string; light: string }; + /** + * The text of the logo in nav bar. + */ + logoText?: string; /** * Base path of the site. */ @@ -182,6 +186,7 @@ export interface SiteData { icon: string; themeConfig: ThemeConfig; logo: string | { dark: string; light: string }; + logoText: string; pages: BaseRuntimePageInfo[]; search: SearchOptions; ssg: boolean; diff --git a/packages/theme-default/src/components/Nav/NavBarTitle.tsx b/packages/theme-default/src/components/Nav/NavBarTitle.tsx index 1a3f717d2..c4a481ec1 100644 --- a/packages/theme-default/src/components/Nav/NavBarTitle.tsx +++ b/packages/theme-default/src/components/Nav/NavBarTitle.tsx @@ -11,7 +11,7 @@ import { getLogoUrl, useLocaleSiteData } from '../../logic'; export const NavBarTitle = () => { const { siteData } = usePageData(); const localeData = useLocaleSiteData(); - const { logo: rawLogo } = siteData; + const { logo: rawLogo, logoText } = siteData; const title = localeData.title ?? siteData.title; const { theme } = useContext(ThemeContext); const [logo, setLogo] = useState(getLogoUrl(rawLogo, theme)); @@ -26,16 +26,16 @@ export const NavBarTitle = () => { href={withBase(localeData.langRoutePrefix || '/')} className="flex items-center w-full h-full text-base font-semibold transition-opacity duration-300 hover:opacity-60" > - {logo ? ( + {logo && ( - ) : ( - {title} )} + {logoText && {logoText}} + {!logo && !logoText && {title}} );