File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ import re
2
+
3
+
4
+ def on_post_page (output , page , config ):
5
+ """
6
+ <ul class="md-select__list">
7
+
8
+ <li class="md-select__item">
9
+ <a href="/leetcode/en/" hreflang="en" class="md-select__link">
10
+ English
11
+ </a>
12
+ </li>
13
+
14
+ <li class="md-select__item">
15
+ <a href="/leetcode/" hreflang="zh" class="md-select__link">
16
+ 中文
17
+ </a>
18
+ </li>
19
+
20
+ </ul>
21
+ """
22
+
23
+ url = page .abs_url
24
+ cn_url = url .replace ("/leetcode/en/" , "/leetcode/" )
25
+ en_url = cn_url .replace ("/leetcode/" , "/leetcode/en/" )
26
+ support_en_lang = not cn_url .startswith ("/leetcode/lcof" ) and not cn_url .startswith (
27
+ "/leetcode/lcof2"
28
+ )
29
+ patterns = {
30
+ "zh" : r'(<a\s+[^>]*href=["\'])[^"\']*(["\'][^>]*hreflang=["\']zh["\'][^>]*>)' ,
31
+ "en" : r'(<a\s+[^>]*href=["\'])[^"\']*(["\'][^>]*hreflang=["\']en["\'][^>]*>)' ,
32
+ }
33
+ output = re .sub (patterns ["zh" ], r"\1" + cn_url + r"\2" , output )
34
+ if support_en_lang :
35
+ output = re .sub (patterns ["en" ], r"\1" + en_url + r"\2" , output )
36
+ return output
Original file line number Diff line number Diff line change 86
86
- hooks/fix_markdown_block.py
87
87
- hooks/ext_info.py
88
88
- hooks/tags.py
89
+ - hooks/stay_on_page.py
89
90
90
91
markdown_extensions :
91
92
- admonition
You can’t perform that action at this time.
0 commit comments