开放的自定义块

目录

为了提升 FixIt 主题的可扩展性,我们提供了一些自定义块,你可以在你的项目中使用这些自定义块来实现更多的功能。

有何意义

通过开放自定义块,FixIt 主题的可扩展性进一步提升。

之后,我们可以充分利用主题的基础特性,构建更多上层组件,从而使博客充满无限的想象空间和创意!

主题、组件、博客 Venn 图
以 FixIt 主题为核心构建多个上层组件,最后在最上层的博客中使用。

入口文件

FixIt 0.3.7 | 新增

FixIt 主题开放了统一的自定义模板入口文件 layouts/_partials/custom.html

在这个文件中,FixIt 主题已经定义了所有开放自定义块。如果你想进一步自定义,你可以将它从主题复制到你的项目中并重写。

1
cp themes/FixIt/layouts/_partials/custom.html layouts/_partials/custom.html

自定义块

你可以通过 define 来实现这些块。

块名称描述位置
custom-head头部自定义块layouts/baseof.html
custom-menu:desktop桌面菜单自定义块layouts/_partials/layouts/header.html
custom-menu:mobile移动菜单自定义块layouts/_partials/layouts/header.html
custom-profile首页自定义块layouts/_partials/home/profile.html
custom-aside侧栏自定义块layouts/posts/single.html
custom-comment评论系统自定义块layouts/_partials/layouts/comment.html
custom-footer页脚自定义块layouts/_partials/layouts/footer.html
custom-widgets小部件自定义块layouts/_partials/layouts/widgets.html
custom-assets资源自定义块layouts/_partials/layouts/assets.html
custom-post__toc:before文章页目录前自定义块layouts/posts/single.html
custom-post__toc:after文章页目录后自定义块layouts/posts/single.html
custom-post__content:before文章页内容前自定义块layouts/posts/single.html
custom-post__content:after文章页内容后自定义块layouts/posts/single.html
custom-post__footer:before文章页脚前自定义块layouts/posts/single.html
custom-post__footer:after文章页脚后自定义块layouts/posts/single.html

主题配置

FixIt 0.3.12 | 新增

为了便于管理引入自定义模板,可以通过 params.custom_partials 参数来指定自定义模板的路径。

自定义模板必须存放在 /layouts/_partials/ 目录中。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[params.custom_partials]
head = []
menu_desktop = []
menu_mobile = []
profile = []
aside = []
comment = []
footer = []
widgets = []
assets = []
post_toc_before = []
post_toc_after = []
post_content_before = []
post_content_after = []
post_footer_before = []
post_footer_after = []

如何使用

现在我们以自定义首页的 custom-profile 块为例,来演示如何使用自定义块。

首先,在 layouts/_partials/ 目录下创建自定义文件,例如 layouts/_partials/custom/profile.html

写入任意内容:

1
The quick brown fox jumps over the lazy dog.

然后,在配置文件中指定自定义模板的路径即可。

1
2
[params.custom_partials]
profile = [ "custom/profile.html" ]

访问首页,你会看到在 profile 区域显示了模板中自定义的内容。


相关内容

Buy me a coffee
Lruihao 支付宝支付宝
Lruihao 微信微信

发现新版本

当前站点有新版本可用。