Closed LYK-love closed 1 year ago
你对 custom_file_path 的使用可能存在一些误解,custom_file_path 并不是替换主题中原本的内容,而是往特定位置添加内容。根据你的描述,你的博客中可能会有两个重复的 head。
你对 custom_file_path 的使用可能存在一些误解,custom_file_path 并不是替换主题中原本的内容,而是往特定位置添加内容。根据你的描述,你的博客中可能会有两个重复的 head。
So you mean I need to delete themes/next/layout/_partials/head/head.njk
?
不要把问题弄复杂了,如果只是设置 Noto Serif SC 字体,用 font 设置就行,不需要动任何 custom file。具体用法看文档。
不要把问题弄复杂了,如果只是设置 Noto Serif SC 字体,用 font 设置就行,不需要动任何 custom file。具体用法看文档。
我看了文档, 可是我要同时改中英文字体. 我在Next配置文件中改了英文字体, 因此只能在样式文件中改中文字体. 请问要如何避免Hexo Next关于source/_data
下文件的报错?
我想我明白了custom files的逻辑. 它只会给Next引入新的配置, 但不会覆盖已有的配置. 对于配置中文字体'Noto Serif SC'来说, 我需要:
<hexo>/source/_data/head.njk
, 向其中写入: <link href="https://fonts.googleapis.com/css?family=Noto+Serif+SC|Roboto&display=swap" rel="stylesheet">
<hexo>/themes/next/source/css/_variables/base.styl
, 注释掉原本的$font-family-chinese
的内容, 添加:
$font-family-chinese = 'Noto Serif SC', Monaco, Consolas, Ubuntu Mono, monospace;
<hexo>/_config.yml
:
custom_file_path:
head: source/_data/head.njk # Used to config font.
这样就不会出现之前所说的文件冲突的情况. 但是, 这样做需要修改Next目录下的文件, 并不能和版本管理很好的结合. 有没有更好的, 能在Hexo目录下覆盖掉<hexo>/themes/next/source/css/_variables/base.styl
的方法. 或者以后的Next能否更改custom file机制, 允许用户自定义的变量覆盖Next目录下定义的变量?
https://theme-next.js.org/docs/getting-started/configuration.html#config-name-yml
这个我的方法没有关系. 事实上我已经用了<hexo>/_config.hext.yaml
. 问题在于要添加字体必须更改<hexo>/themes/next/source/css/_variables/base.styl
中的$font-family-chinese
变量. 目前的custom file机制只能添加变量, 但无法覆盖变量, 因此我没法用custom file来更改$font-family-chinese
.
你可以参考 https://theme-next.js.org/docs/advanced-settings/custom-files.html#Tagcloud-Color 文档里的例子是覆盖 $tag-cloud-start,你改为覆盖 $font-family-chinese 就行了
你可以参考 https://theme-next.js.org/docs/advanced-settings/custom-files.html#Tagcloud-Color 文档里的例子是覆盖 $tag-cloud-start,你改为覆盖 $font-family-chinese 就行了
我这么做了, 但是没有用. 我的source/_data/variables.styl
的内容如下:
font-family-chinese = 'Noto Serif SC', Monaco, Consolas, Ubuntu Mono, monospace;
并且我也在配置文件中开启了variables的custom file. 然而, 这样做不会生效. chrome开发者模式显示, 我的字体依然是base.styl
中的.
还需要多覆盖几个变量
$font-family-chinese = 'Noto Serif SC', Monaco, Consolas, Ubuntu Mono, monospace;
$font-family-base = $font-family-chinese, sans-serif;
$font-family-base = get_font_family('global'), $font-family-chinese, sans-serif if get_font_family('global');
$font-family-logo = $font-family-base;
$font-family-logo = get_font_family('title'), $font-family-base if get_font_family('title');
$font-family-headings = $font-family-base;
$font-family-headings = get_font_family('headings'), $font-family-base if get_font_family('headings');
$font-family-posts = $font-family-base;
$font-family-posts = get_font_family('posts'), $font-family-base if get_font_family('posts');
$font-family-monospace = consolas, Menlo, monospace, $font-family-chinese;
$font-family-monospace = get_font_family('codes'), consolas, Menlo, monospace, $font-family-chinese if get_font_family('codes');
另外需要加载 Noto Serif SC 的字体文件,不然浏览器会使用 fallback font
还需要多覆盖几个变量
$font-family-chinese = 'Noto Serif SC', Monaco, Consolas, Ubuntu Mono, monospace; $font-family-base = $font-family-chinese, sans-serif; $font-family-base = get_font_family('global'), $font-family-chinese, sans-serif if get_font_family('global'); $font-family-logo = $font-family-base; $font-family-logo = get_font_family('title'), $font-family-base if get_font_family('title'); $font-family-headings = $font-family-base; $font-family-headings = get_font_family('headings'), $font-family-base if get_font_family('headings'); $font-family-posts = $font-family-base; $font-family-posts = get_font_family('posts'), $font-family-base if get_font_family('posts'); $font-family-monospace = consolas, Menlo, monospace, $font-family-chinese; $font-family-monospace = get_font_family('codes'), consolas, Menlo, monospace, $font-family-chinese if get_font_family('codes');
另外需要加载 Noto Serif SC 的字体文件,不然浏览器会使用 fallback font
That works for me. Can you add this practice example to hexo's documentation of font customization?
This thread has been automatically locked since there has not been any recent activity after it was closed. It is possible issue was solved or at least outdated. Feel free to open new for related bugs.
Issue Checklist
Expected behavior
I want to modify my Chinese font config to suport Noto Serif SC. So I use "Data Files"and "Custom Files" features to let my Hexo Next use my "source/_data/head.njk" as data file.
It works for me and my website shows correct font. However, it seems Next fails to identify the "data file" feature and report it as an ERROR.
Actual behavior
The data file is properly used and it shouldn't be reported as a failure. Note that even I comment my custom file config in Next config file, as soon as the data file exists, Next will report this failure. So the problem may be related with "data file" feature, not "custom file".
Steps to reproduce the behavior
Copy
themes/next/layout/_partials/head/head.njk
tosource/_data/head.njk
.Edit the latter file , add
<link rel="stylesheet" href="{{ url_for(theme.css) }}/main.css">
.Change the config file to use
source/_data/head.njk
as my custom file for "head":hexo clean && hexo g && hexo s
Node.js and NPM Information
Package dependencies Information
Hexo Configuration
NexT Configuration
Other Information
No response