Skip to content

Commit

Permalink
✨ feat: Update theme config
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Nov 24, 2024
1 parent bfd6691 commit 736c3ea
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 18 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,23 @@ Usage After installation, start the site with `dumi`, and the theme will be auto

```ts
interface SiteThemeConfig {
actions: HeroProps['actions'];
actions?: HeroProps['actions'];
analytics?: {
clarity?: {
projectId: string;
};
googleAnalytics?: {
measurementId: string;
};
plausible?: {
domain: string;
scriptBaseUrl: string;
};
};
apiHeader?: ApiHeaderConfig | false;
description?: string;
docStyle?: 'block' | 'pure';
features: FeaturesProps['items'];
features?: FeaturesProps['items'];
footer?: string | false;
footerConfig?: FooterConfig;
giscus?: {
Expand All @@ -100,6 +112,28 @@ interface SiteThemeConfig {
hideHomeNav?: boolean;
logo?: string;
logoType?: LogoProps['type'];
metadata?: {
description?: string;
icons?: {
apple?: string;
icon?: string;
shortcut?: string;
};
manifest?: string;
openGraph?: {
description?: string;
image?: string;
siteName?: string;
title?: string;
};
title?: string;
twitter?: {
description?: string;
image?: string;
site?: string;
title?: string;
};
};
name?: string;
siteToken?: SiteConfigToken;
socialLinks?: {
Expand Down
3 changes: 0 additions & 3 deletions src/config.ts

This file was deleted.

6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export { defineThemeConfig } from './config';
import { SiteThemeConfig } from '@/types';

export { siteSelectors, type SiteStore, useSiteStore } from './store';
export * from './types';
export { styles } from '@/store/initialState';

export const defineThemeConfig = (config: SiteThemeConfig) => config;
5 changes: 3 additions & 2 deletions src/layouts/DocLayout/Head/Og.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { memo } from 'react';
import { siteSelectors, useSiteStore } from '@/store';

const Og = memo(() => {
const [title, desc, logo] = useSiteStore((s) => [
const [title, desc, logo, hostname] = useSiteStore((s) => [
siteSelectors.siteTitle(s),
siteSelectors.siteDesc(s),
siteSelectors.logo(s),
siteSelectors.hostname(s),
]);
const metadata = useSiteStore(siteSelectors.metadata, isEqual);
return (
Expand All @@ -17,7 +18,7 @@ const Og = memo(() => {
<meta content={metadata?.description || desc} name="description" />
<meta content={metadata?.openGraph?.title || title} property="og:title" />
<meta content={metadata?.openGraph?.description || desc} property="og:description" />
<meta content={location.origin} property="og:url" />
<meta content={hostname || location.origin} property="og:url" />
<meta content={metadata?.openGraph?.siteName} property="og:site_name" />
<meta content="en" property="og:locale" />
<meta content={metadata?.openGraph?.title || title} property="og:image:alt" />
Expand Down
11 changes: 10 additions & 1 deletion src/store/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface SiteStore {
tabMeta?: NonNullable<IRouteMeta['tabs']>[0]['meta'];
}

export const initialThemeConfig: SiteThemeConfig = {
export const initialThemeConfig: Partial<SiteThemeConfig> = {
footer: 'Made with 🤯 by <a href="https://lobehub.com" target="_blank">LobeHub</a>',
metadata: {
icons: {
Expand All @@ -63,6 +63,14 @@ export const initialThemeConfig: SiteThemeConfig = {
},
};

export const styles = [
`html, body { background: transparent; }
@media (prefers-color-scheme: dark) {
html, body { background: #000; }
}`,
];

export const initialState: SiteStore = {
locale: { id: 'en-US', name: 'English', suffix: '' },
location: {
Expand Down Expand Up @@ -93,6 +101,7 @@ export const initialState: SiteStore = {
pkg: {},
// @ts-ignore
setLoading: undefined,
styles: styles,
// @ts-ignore
themeConfig: initialThemeConfig,
},
Expand Down
3 changes: 3 additions & 0 deletions src/store/selectors/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const contentBottom = (s: SiteStore) => {
return { currentIndex, next: dataFlatten[currentIndex + 1], prev: dataFlatten[currentIndex - 1] };
};

const hostname = (s: SiteStore) => s.siteData.hostname;

export const siteSelectors = {
activePath,
analytics,
Expand All @@ -90,6 +92,7 @@ export const siteSelectors = {
flattenSidebar,
giscus,
github,
hostname,
logo,
metadata,
siteDesc,
Expand Down
10 changes: 2 additions & 8 deletions src/store/useSiteStore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import type { ISiteContext } from 'dumi/dist/client/theme-api/context';
import {
ILocale,
INavItem,
IRouteMeta,
ISidebarGroup,
IThemeConfig,
} from 'dumi/dist/client/theme-api/types';
import { ILocale, INavItem, IRouteMeta, ISidebarGroup } from 'dumi/dist/client/theme-api/types';
import type { Location } from 'history';
import { StoreApi } from 'zustand';
import { createContext } from 'zustand-utils';
Expand All @@ -18,7 +12,7 @@ import { SiteThemeConfig } from '@/types';
export type NavData = (INavItem & { children?: INavItem[] | undefined })[];

export type ISiteData = ISiteContext & {
themeConfig: IThemeConfig & SiteThemeConfig;
themeConfig: SiteThemeConfig;
};

export interface SiteStore {
Expand Down
3 changes: 2 additions & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { FeaturesProps, FooterProps, HeroProps, LogoProps } from '@lobehub/ui';
import { IThemeConfig } from 'dumi/dist/client/theme-api/types';
import { FooterColumn } from 'rc-footer/es/column';

import type { SiteCustomToken } from '@/styles/customToken';
Expand All @@ -20,7 +21,7 @@ export interface FooterConfig {
resources?: FooterColumn;
}

export interface SiteThemeConfig {
export interface SiteThemeConfig extends IThemeConfig {
actions?: HeroProps['actions'];
analytics?: {
clarity?: {
Expand Down

0 comments on commit 736c3ea

Please sign in to comment.