Skip to content

Commit 4d3362d

Browse files
committed
fix: stay on page
1 parent ecf042e commit 4d3362d

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

hooks/stay_on_page.py

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
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="/en/" hreflang="en" class="md-select__link">
10-
English
11-
</a>
12-
</li>
13-
14-
<li class="md-select__item">
15-
<a href="/" 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("/en/", "/")
25-
en_url = cn_url + "en/"
26-
support_en_lang = not cn_url.startswith("/lcof") and not cn_url.startswith(
27-
"/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
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="/en/" hreflang="en" class="md-select__link">
10+
English
11+
</a>
12+
</li>
13+
14+
<li class="md-select__item">
15+
<a href="/" 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("/en/", "/")
25+
en_url = "/en" + cn_url
26+
support_en_lang = not cn_url.startswith("/lcof") and not cn_url.startswith("/lcof2")
27+
patterns = {
28+
"zh": r'(<a\s+[^>]*href=["\'])[^"\']*(["\'][^>]*hreflang=["\']zh["\'][^>]*>)',
29+
"en": r'(<a\s+[^>]*href=["\'])[^"\']*(["\'][^>]*hreflang=["\']en["\'][^>]*>)',
30+
}
31+
output = re.sub(patterns["zh"], r"\1" + cn_url + r"\2", output)
32+
if support_en_lang:
33+
output = re.sub(patterns["en"], r"\1" + en_url + r"\2", output)
34+
return output

0 commit comments

Comments
 (0)