0%

Hexo 自定义字体

Comic Neue

Comic Neue Font's Offcial Site

最初是因为 Comic Sans 而认识的它,虽然 Comic Sans 是一款很普遍的手写英文字体,但是它存在很多问题,其中灰度不均匀是我认为最严重的,具体可以参阅这里 -> Why You Hate Comic Sans

Comic Neue 解决了很多问题,成为了许多设计师的首选手写英文字体,下面我介绍如何将这个萌萌的英文字体应用在 Hexo 博客上

Download -> Unzip -> Upload

下载并解压之后,将Web目录下的字体们上传到 NexT 主题的source/fonts目录下,如图所示。

fonts

CSS

上面Web目录下的 font.css 是官方给我们写好的使用示例,我们稍作修改之后添加到 NexT 主题的source/css/_custom/custom.styl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Light.eot');
src: url('/fonts/ComicNeue-Light.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Light.woff2') format('woff2'),
url('/fonts/ComicNeue-Light.woff') format('woff'),
url('/fonts/ComicNeue-Light.ttf') format('truetype');
font-weight: 300;
}

@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Light-Oblique.eot');
src: url('/fonts/ComicNeue-Light-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Light-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Light-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Light-Oblique.ttf') format('truetype');
font-weight: 300;
font-style: oblique;
}

@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Regular.eot');
src: url('/fonts/ComicNeue-Regular.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Regular.woff2') format('woff2'),
url('/fonts/ComicNeue-Regular.woff') format('woff'),
url('/fonts/ComicNeue-Regular.ttf') format('truetype');
font-weight: 400;
}

@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Regular-Oblique.eot');
src: url('/fonts/ComicNeue-Regular-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Regular-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Regular-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Regular-Oblique.ttf') format('truetype');
font-weight: 400;
font-style: oblique;
}

@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Bold.eot');
src: url('/fonts/ComicNeue-Bold.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Bold.woff2') format('woff2'),
url('/fonts/ComicNeue-Bold.woff') format('woff'),
url('/fonts/ComicNeue-Bold.ttf') format('truetype');
font-weight: 700;
}

@font-face {
font-family: 'Comic Neue';
src: url('/fonts/ComicNeue-Bold-Oblique.eot');
src: url('/fonts/ComicNeue-Bold-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Bold-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Bold-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Bold-Oblique.ttf') format('truetype');
font-weight: 700;
font-style: oblique;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Light.eot');
src: url('/fonts/ComicNeue-Angular-Light.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Light.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Light.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Light.ttf') format('truetype');
font-weight: 300;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Light-Oblique.eot');
src: url('/fonts/ComicNeue-Angular-Light-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Light-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Light-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Light-Oblique.ttf') format('truetype');
font-weight: 300;
font-style: oblique;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Regular.eot');
src: url('/fonts/ComicNeue-Angular-Regular.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Regular.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Regular.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Regular.ttf') format('truetype');
font-weight: 400;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Regular-Oblique.eot');
src: url('/fonts/ComicNeue-Angular-Regular-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Regular-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Regular-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Regular-Oblique.ttf') format('truetype');
font-weight: 400;
font-style: oblique;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Bold.eot');
src: url('/fonts/ComicNeue-Angular-Bold.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Bold.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Bold.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Bold.ttf') format('truetype');
font-weight: 700;
}

@font-face {
font-family: 'Comic Neue Angular';
src: url('/fonts/ComicNeue-Angular-Bold-Oblique.eot');
src: url('/fonts/ComicNeue-Angular-Bold-Oblique.eot?#iefix') format('embedded-opentype'),
url('/fonts/ComicNeue-Angular-Bold-Oblique.woff2') format('woff2'),
url('/fonts/ComicNeue-Angular-Bold-Oblique.woff') format('woff'),
url('/fonts/ComicNeue-Angular-Bold-Oblique.ttf') format('truetype');
font-weight: 700;
font-style: oblique;
}

Config

在 NexT 主题的_config.yml内设置自定义字体

1
2
3
4
5
6
font:
enable: true
... ... ...
posts:
external: false
family: 'Comic Neue'

Generate

清除缓存,生成新的页面

1
hexo clean && hexo g && hexo -d

后记

看过上一篇文章的小伙伴可能觉得奇怪,明明不推荐在主题的source目录里进行修改,为什么这里就背道而行呢,在这里说一下我的理解。
NexT 主题的 source 下本存在 fonts 目录,但是内容为空,再加上_config.yml里面有 font 相关的设置,而且文档里也提到了关于自定义字体的方法,但是只适用于 Google Fonts 收录了你想要的字体的情况,所以猜测这里是用于存放自定义字体的【当然,也可能是曾经有过字体,但是后面的更新过程中删掉了但是保留了目录,的历史遗留问题】
所以这篇文章主要想介绍自定义字体的时候如何添加 Google Fonts 没有的样式。

Buy me a coffee, encourage me keep writing.