我正在使用 gatsby-theme-blog,并且想使用“Wordpress 2016”主题附带的默认“Montserrat”以外的字体。
如果可能,我想将字体更改为“Work Sans”,“ fairyGate ”主题用于标题。
从盖茨比主题中的阴影中,我知道如何在我的项目下创建文件以替换原始文件。但是,所有方法都失败了,帖子页面中的标题仍然存在Montserrat
。
这是我尝试过的:
- 安装主题及其依赖字体:
// package.json
{
"dependencies": {
"@theme-ui/typography": "^0.3.0", // to use `toTheme` method
"typeface-work-sans": "^0.0.72", // the font I'd like to use
"typography-theme-fairy-gates": "^0.16.19"
}
}
- 创建文件以隐藏原始排版:
// my-project/src/gatsby-theme-blog/gatsby-plugin-theme-ui/typography.ts
import "typeface-work-sans"
import { toTheme } from "@theme-ui/typography"
import fairyGates from "typography-theme-fairy-gates"
export default toTheme(fairyGates)
// my-project/src/gatsby-theme-blog/gatsby-plugin-theme-ui/index.ts
/* I duplicate most codes in original gatsby-plugin-theme-ui/index.js
intentionally to avoid other possible failing factors */
import merge from "deepmerge"
import typography from "gatsby-theme-blog/src/gatsby-plugin-theme-ui/typography"
import colors from "gatsby-theme-blog/src/gatsby-plugin-theme-ui/colors"
import styles from "gatsby-theme-blog/src/gatsby-plugin-theme-ui/styles"
import prism from "gatsby-theme-blog/src/gatsby-plugin-theme-ui/prism"
export default merge(typography, {
initialColorMode: `light`,
colors,
fonts: {
heading: `Work Sans, sans-serif`, // <- Changing font here doesn't work as expected!
monospace: `Consolas, Menlo, Monaco, source-code-pro, Courier New, monospace`,
},
sizes: {
container: 672,
},
styles,
prism,
})
任何建议表示赞赏!