Skip to content

Commit af86e91

Browse files
committed
fix: custom sort tag
1 parent 6d11b79 commit af86e91

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

hooks/tags.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
from bs4 import BeautifulSoup
3+
4+
5+
def on_post_page(output, page, config):
6+
is_cn_tag_page = page.abs_url == "/leetcode/tags/"
7+
is_en_tag_page = page.abs_url == "/leetcode/en/tags/"
8+
if not is_cn_tag_page and not is_en_tag_page:
9+
return output
10+
soup = BeautifulSoup(output, "html.parser")
11+
tags = soup.find_all("span", class_="md-tag")
12+
for tag in tags:
13+
tag_li = tag.find_next("ul").find_all("li")
14+
tag_li.sort(key=lambda x: int(re.search(r"\d+", x.a.text).group()))
15+
tag.find_next("ul").clear()
16+
for li in tag_li:
17+
tag.find_next("ul").append(li)
18+
return str(soup)

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ hooks:
8585
- hooks/committer.py
8686
- hooks/fix_markdown_block.py
8787
- hooks/ext_info.py
88+
- hooks/tags.py
8889

8990
markdown_extensions:
9091
- admonition

0 commit comments

Comments
 (0)