#内置图标 theme-only
Rspress 内置使用图标时,会使用一个 SvgWrapper 组件来渲染图标。支持 icon 为 url 或者 svgr 的 React 组件:
type Icon = React.FC<React.SVGProps<SVGSVGElement>> | string;下面的代码是一个 Rspress 如何使用 IconGithub 的示例:
import { SvgWrapper, IconGithub } from '@rspress/core/theme';
<SvgWrapper icon={IconGithub} width={24} height={24} />#用法
当你想更换 Rspress 内置图标时,使用 自定义主题 - 重导出 进行替换。
theme/index.tsx
export { IconGithub, IconCodeTypeScript } from './my-icons';
export * from '@rspress/core/theme-original';所有 Rspress 使用到的图标如下:
品牌图标
界面图标
代码块文件图标
import {
SvgWrapper,
IconGithub,
IconGitlab,
IconAnthropic,
IconOpenAI,
IconMarkdown,
IconNpm,
IconYarn,
IconPnpm,
IconBun,
IconDeno,
IconVlt,
IconJsdelivr,
IconUnpkg,
IconArrowDown,
IconArrowRight,
IconClose,
IconCopy,
IconDeprecated,
IconDown,
IconEdit,
IconEmpty,
IconExperimental,
IconExternalLink,
IconFile,
IconHeader,
IconJump,
IconLink,
IconLoading,
IconMenu,
IconMoon,
IconOpenInChat,
IconScrollToTop,
IconSearch,
IconSmallMenu,
IconSuccess,
IconSun,
IconTitle,
IconWrap,
IconWrapped,
IconCodeAstro,
IconCodeBiome,
IconCodeC,
IconCodeCpp,
IconCodeCss,
IconCodeDocker,
IconCodeEnv,
IconCodeEslint,
IconCodeFile,
IconCodeGit,
IconCodeGo,
IconCodeGraphql,
IconCodeHtml,
IconCodeJava,
IconCodeJavaScript,
IconCodeJson,
IconCodeLess,
IconCodeMarkdown,
IconCodeMdx,
IconCodeNode,
IconCodePrettier,
IconCodePython,
IconCodeReact,
IconCodeReactTs,
IconCodeRstack,
IconCodeRust,
IconCodeSass,
IconCodeShell,
IconCodeSql,
IconCodeSvelte,
IconCodeSvg,
IconCodeTailwind,
IconCodeToml,
IconCodeTsConfig,
IconCodeTypeScript,
IconCodeTypeScriptDef,
IconCodeVite,
IconCodeVue,
IconCodeWebpack,
IconCodeXml,
IconCodeYaml,
} from '@rspress/core/theme';
export default () => {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
{[
{
label: '品牌图标',
icons: [
IconGithub,
IconGitlab,
IconAnthropic,
IconOpenAI,
IconMarkdown,
IconNpm,
IconYarn,
IconPnpm,
IconBun,
IconDeno,
IconVlt,
IconJsdelivr,
IconUnpkg,
],
},
{
label: '界面图标',
icons: [
IconArrowDown,
IconArrowRight,
IconClose,
IconCopy,
IconDeprecated,
IconDown,
IconEdit,
IconEmpty,
IconExperimental,
IconExternalLink,
IconFile,
IconHeader,
IconJump,
IconLink,
IconLoading,
IconMenu,
IconMoon,
IconOpenInChat,
IconScrollToTop,
IconSearch,
IconSmallMenu,
IconSuccess,
IconSun,
IconTitle,
IconWrap,
IconWrapped,
],
},
{
label: '代码块文件图标',
icons: [
IconCodeFile,
IconCodeTypeScript,
IconCodeTypeScriptDef,
IconCodeJavaScript,
IconCodeReact,
IconCodeReactTs,
IconCodeJson,
IconCodeNode,
IconCodeTsConfig,
IconCodeRstack,
IconCodeHtml,
IconCodeCss,
IconCodeSass,
IconCodeLess,
IconCodeMarkdown,
IconCodeMdx,
IconCodeVue,
IconCodeSvelte,
IconCodeAstro,
IconCodeVite,
IconCodeWebpack,
IconCodeTailwind,
IconCodeEslint,
IconCodeBiome,
IconCodePrettier,
IconCodeYaml,
IconCodeToml,
IconCodeShell,
IconCodeRust,
IconCodeGo,
IconCodePython,
IconCodeJava,
IconCodeC,
IconCodeCpp,
IconCodeDocker,
IconCodeGit,
IconCodeEnv,
IconCodeSvg,
IconCodeGraphql,
IconCodeSql,
IconCodeXml,
],
},
].map(({ label, icons }) => (
<div key={label}>
<div style={{ fontSize: 12, fontWeight: 500, marginBottom: 8 }}>
{label}
</div>
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
{icons.map((Icon, idx) => (
<SvgWrapper icon={Icon} key={idx} width={24} height={24} />
))}
</div>
</div>
))}
</div>
);
};#新增更多文件名或后缀对应的图标
使用 filename 时,如果 Rspress 没有为某个文件名或后缀提供专用图标,可以在 theme/index.tsx 中导出 codeBlockIcons 来添加。例如,justfile 匹配使用 filename="justfile" 的代码块,.zig 则匹配文件名以 .zig 结尾的代码块,如 main.zig。
theme/index.tsx
import IconJust from './assets/just.svg';
import IconZig from './assets/zig.svg';
export * from '@rspress/core/theme-original';
export const codeBlockIcons = {
justfile: IconJust,
'.zig': IconZig,
};