Skip to content

Commit a167775

Browse files
committed
feat: add ext info plugin
1 parent e324d5e commit a167775

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

docs/lc/1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/0000-0099/0001.Tw
55
tags:
66
- 数组
77
- 哈希表
8+
rating: 1234
89
---
910

1011
# [1. 两数之和](https://leetcode.cn/problems/two-sum)

docs/lc/2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ tags:
44
- 模拟
55
- 堆(优先队列)
66
edit_url: 'https://github.com/doocs/leetcode/edit/main/solution/0000-0099/0002.Add%20Two%20Numbers/README.md'
7+
rating: 1345
78
---
89

910
# [2. 两数相加](https://leetcode.cn/problems/add-two-numbers)

hooks/ext_info.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from mkdocs import plugins
2+
3+
4+
# https://www.mkdocs.org/dev-guide/plugins/#events
5+
6+
7+
@plugins.event_priority(90)
8+
def on_post_page(output, page, config):
9+
difficulty = page.meta.get('difficulty')
10+
rating = page.meta.get('rating')
11+
12+
# 在 h1 标题之后插入难度和评分信息及其样式
13+
html = str(output)
14+
# if difficulty:
15+
# # 找到 h1 标签的结束位置
16+
# h1_end = html.find('</h1>') + 5
17+
# # 在 h1 标签之后插入难度信息
18+
# html = html[:h1_end] + f'<p>Difficulty: {difficulty}</p>' + html[h1_end:]
19+
# if rating:
20+
# # 找到 h1 标签的结束位置
21+
# h1_end = html.find('</h1>') + 5
22+
# # 在 h1 标签之后插入评分信息
23+
# html = html[:h1_end] + f'<p>Rating: {rating}</p>' + html[h1_end:]
24+
return html

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ hooks:
8686
- hooks/tags.py
8787
- hooks/committer.py
8888
- hooks/fix_markdown_block.py
89+
- hooks/ext_info.py
8990

9091
markdown_extensions:
9192
- admonition

0 commit comments

Comments
 (0)