Skip to content

Commit

Permalink
feat: support logo text config (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yukiniro authored Mar 24, 2024
1 parent 7e0d6aa commit 145bb16
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .changeset/wet-ears-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@rspress/theme-default": patch
"@rspress/docs": patch
"@rspress/shared": patch
"@rspress/core": patch
---

feat: support logo text config
1 change: 1 addition & 0 deletions packages/core/src/node/runtimeModule/siteData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down
15 changes: 15 additions & 0 deletions packages/document/docs/en/api/config/config-basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
15 changes: 15 additions & 0 deletions packages/document/docs/zh/api/config/config-basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export interface UserConfig<ThemeConfig = DefaultThemeConfig> {
* 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.
*/
Expand Down Expand Up @@ -182,6 +186,7 @@ export interface SiteData<ThemeConfig = NormalizedDefaultThemeConfig> {
icon: string;
themeConfig: ThemeConfig;
logo: string | { dark: string; light: string };
logoText: string;
pages: BaseRuntimePageInfo[];
search: SearchOptions;
ssg: boolean;
Expand Down
8 changes: 4 additions & 4 deletions packages/theme-default/src/components/Nav/NavBarTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 && (
<img
src={normalizeImagePath(logo)}
alt="logo"
id="logo"
className="mr-4 rspress-logo"
/>
) : (
<span>{title}</span>
)}
{logoText && <span>{logoText}</span>}
{!logo && !logoText && <span>{title}</span>}
</a>
</div>
);
Expand Down

0 comments on commit 145bb16

Please sign in to comment.