Skip to content

Commit

Permalink
[add] plugin control
Browse files Browse the repository at this point in the history
  • Loading branch information
AIboy996 committed May 18, 2024
1 parent ef760ff commit 9362f38
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 241 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/issueMySite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
with:
python-version: "3.11.5"
- run: python3 -m pip install -r requirements.txt
- run: python3 -m pip install -e plugins
- run: mkdocs gh-deploy --force -b publishment
- run: PLUGIN="./plugins_full.yml" mkdocs gh-deploy --force -b publishment
deployment-cloudfare-pages:
needs: build
runs-on: ubuntu-latest
Expand Down
40 changes: 38 additions & 2 deletions docs/Note/mkdocs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,42 @@ tags:
- mkdocs
---

# 自定义插件
# 控制插件加载

随着本站的内容越来越多,每次编译的速度越来越慢。
随着本站的内容越来越多,每次编译的速度越来越慢。为了提高写文的体验,决定在开发的时候禁用一些插件。


可以使用环境变量单独控制特定的插件是否启用:

```yml
plugins:
- git-revision-date-localized:
enabled: !ENV [DEPLOY, true]
```
但并非所有插件都支持`enabled`这个变量。


也可以使用官方的`group`插件,来批量控制插件的开启:
```yml
plugins:
- group:
enabled: !ENV [DEPLOY, true]
plugins:
- optimize
- minify
```
但是这个插件和我用的mkdocs-static-i18n插件不兼容。

于是我只能采用第三种方法,在配置文件中使用环境变量来控制是否加载插件列表:
```yml
INHERIT: !ENV [PLUGIN, ./plugins_simplify.yml]
```

如果需要全部的插件,就传递`PLUGIN`环境变量即可:
```bash
PLUGIN="./plugins_full.yml" mkdocs serve
```


结果这番操作,原本需要30秒的编译,现在只需要2秒了,不得不说 mkdocs 真是慢啊!
2 changes: 1 addition & 1 deletion docs/Note/mkdocs/practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags:
include:
- math
---
# 实践
# mkdocs实践

!!! info "演示的环境"
本次演示在HyperV创建的windows 10虚拟机中进行,提前没有安装任何软件,面向小白,从零开始,可以放心食用。
Expand Down
2 changes: 1 addition & 1 deletion docs/Note/mkdocs/theory.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ tags:
include:
- math
---
# 理论
# mkdocs介绍

!!! info "注意"
如果要学怎么搭建网站,推荐看下一篇文章[《实践》](../../../Note/mkdocs/practice/),这里写的内容比较杂乱,仅供我个人备忘。
Expand Down
56 changes: 0 additions & 56 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,62 +93,6 @@ extra:
link: https://yangzhang.site/feed_rss_updated.xml
name: RSS

plugins:
- i18n:
docs_structure: suffix
languages:
- locale: zh
default: true
name: 简体中文
build: true
- locale: en
name: English
build: true
nav_translations:
正式的简历: Resume
## jupyter文件支持 ########## 暂时移除此功能
#- mkdocs-jupyter
- group:
# 在开发的时候设置环境变量DEPLOY=false来加快编译速度
# 编译时间从 30秒 减少到 4秒
# 立竿见影啊!
enabled: !ENV [DEPLOY, true]
plugins:
- tags
# 视频插件
- mkdocs-video:
is_video: true
video_muted: false
video_controls: true
video_autoplay: false
css_style:
width: "80%"
display: block;
margin-left: auto;
margin-right: auto;
# 图片放大插件
- glightbox:
effect: zoom
zoomable: true
draggable: true
skip_classes:
- nonzoom
## 文章日期插件
- git-revision-date-localized:
timezone: Asia/Irkutsk
enable_creation_date: true
type: iso_datetime
## 搜索插件
- search:
lang:
- en
# 日语搜索汉字
- ja
- zh
- minify:
minify_html: true
- rss

markdown_extensions:
- md_in_html
- attr_list # 给图片后面添加{width="300"}设置大小
Expand Down
1 change: 1 addition & 0 deletions nav.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
INHERIT: !ENV [PLUGIN, ./plugins_simplify.yml]
nav:
- About:
- About/index.md
Expand Down
Empty file removed plugins/local_plugins/__init__.py
Empty file.
166 changes: 0 additions & 166 deletions plugins/local_plugins/group_plugin.py

This file was deleted.

12 changes: 0 additions & 12 deletions plugins/setup.py

This file was deleted.

49 changes: 49 additions & 0 deletions plugins_full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins:
- i18n:
docs_structure: suffix
languages:
- locale: zh
default: true
name: 简体中文
build: true
- locale: en
name: English
build: true
nav_translations:
正式的简历: Resume
## jupyter文件支持 ########## 暂时移除此功能
#- mkdocs-jupyter
- tags
# 视频插件
- mkdocs-video:
is_video: true
video_muted: false
video_controls: true
video_autoplay: false
css_style:
width: "80%"
display: block;
margin-left: auto;
margin-right: auto;
# 图片放大插件
- glightbox:
effect: zoom
zoomable: true
draggable: true
skip_classes:
- nonzoom
## 文章日期插件
- git-revision-date-localized:
timezone: Asia/Irkutsk
enable_creation_date: true
type: iso_datetime
## 搜索插件
- search:
lang:
- en
# 日语搜索汉字
- ja
- zh
- minify:
minify_html: true
- rss
3 changes: 3 additions & 0 deletions plugins_simplify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 只加载一个插件,提高编译速度
plugins:
- tags
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mkdocs-material==8.5.11
mkdocs-material-extensions==1.1.1
mkdocs-minify-plugin==0.6.2
mkdocs-rss-plugin==1.7.0
mkdocs-static-i18n==1.2.0
mkdocs-static-i18n==1.2.3
mkdocs-video==1.5.0
# mkdocs-jupyter==0.22.0

0 comments on commit 9362f38

Please sign in to comment.