Skip to content

Commit e84aa21

Browse files
committed
docs: add language auto switch
docs: fix Chinese anchor
1 parent f5f0bed commit e84aa21

File tree

9 files changed

+112
-25
lines changed

9 files changed

+112
-25
lines changed

docs/apis/DataAPI/DataBase.zh.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
### 📄 目录
99

10-
🔑 [KVDB 键值对数据库](#🔑-键---值对-nosql数据库)
11-
📋 [SQL数据库](#📋-sql数据库)
10+
🔑 [KVDB 键值对数据库](#-键---值对-nosql数据库)
11+
📋 [SQL数据库](#-sql数据库)
1212
- 🔍 [预准备语句](#sql预准备语句)
1313

1414
附: 各SQL的官方文档
@@ -142,12 +142,12 @@ SQL数据库适用于使用SQL语句处理大量的关系型数据。接口底
142142

143143
#### 连接参数
144144

145-
|| 用途 | 可用数据库 | 示例 | 默认值 |
146-
| --------- | ------------------------ | ---------- | ----------------- | ------- |
147-
| path | 指定数据库所在路径 | `SQLite` | `plugins/test.db` | - |
148-
| create | 数据库不存在是否自动创建 | `SQLite` | `true`/`false` | `true` |
149-
| readonly | 以只读模式打开 | `SQLite` | `true`/`false` | `false` |
150-
| readwrite | 以读写模式打开 | `SQLite` | `true`/`false` | `true` |
145+
| | 用途 | 可用数据库 | 示例 | 默认值 |
146+
|-----------|--------------|----------|-------------------|---------|
147+
| path | 指定数据库所在路径 | `SQLite` | `plugins/test.db` | - |
148+
| create | 数据库不存在是否自动创建 | `SQLite` | `true`/`false` | `true` |
149+
| readonly | 以只读模式打开 | `SQLite` | `true`/`false` | `false` |
150+
| readwrite | 以读写模式打开 | `SQLite` | `true`/`false` | `true` |
151151

152152

153153

@@ -217,7 +217,7 @@ SQL数据库适用于使用SQL语句处理大量的关系型数据。接口底
217217

218218

219219
> 预准备语句(Prepared Statement)是SQL的一个重要部分。它的实现原理是:先将含有未知参数的SQL语句(发往服务端)处理、编译,再绑定参数,最终执行并返回结果。各个SQL的预准备语句实现可能不同,其预准备语句的表示方法也可能存在差异,所以请务必仔细阅读文档(直接去阅读对应SQL的官方文档则更好)。
220-
预准备语句的主要作用是防止SQL注入攻击——一种很常见的、危险的攻击。如果在未经检验的情况下直接使用用户输入的数据(就像BDS一样 xD),就可能会造成免密码登录甚至数据丢失(注入执行`DROP TABLE``DROP DATABASE`)等严重后果。所以在处理用户输入的数据时,更推荐使用预准备语句。其次,它可以在(服务器)只编译一次语句的情况下,实现多次输入。
220+
> 预准备语句的主要作用是防止SQL注入攻击——一种很常见的、危险的攻击。如果在未经检验的情况下直接使用用户输入的数据(就像BDS一样 xD),就可能会造成免密码登录甚至数据丢失(注入执行`DROP TABLE``DROP DATABASE`)等严重后果。所以在处理用户输入的数据时,更推荐使用预准备语句。其次,它可以在(服务器)只编译一次语句的情况下,实现多次输入。
221221
222222

223223

@@ -260,10 +260,10 @@ INSERT INTO table VALUES ($X, ?Y, :Z);
260260

261261
#### 预准备语句对象 - 属性
262262

263-
| 属性 | 含义 | 类型 | 另见 |
264-
| ------------------- | ------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------- |
265-
| `stmt.affectedRows` | 获取该预准备语句执行后影响的行数(仅对`INSERT` `UPDATE` `DELETE` `REPLACE` 等语句生效) | `Integer` | [SQLite](https://www.sqlite.org/c3ref/changes.html) [MySQL](https://dev.mysql.com/doc/c-api/8.0/en/mysql-affected-rows.html) |
266-
| `stmt.insertId` | 获取该`INSERT`/`UPDATE`/`REPLACE`语句执行后最后一个更改行的行号(关于行号的解释详见官方文档) | `Integer` | [SQLite](https://www.sqlite.org/c3ref/last_insert_rowid.html) [MySQL](https://dev.mysql.com/doc/c-api/8.0/en/mysql-stmt-insert-id.html) |
263+
| 属性 | 含义 | 类型 | 另见 |
264+
|---------------------|----------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------|
265+
| `stmt.affectedRows` | 获取该预准备语句执行后影响的行数(仅对`INSERT` `UPDATE` `DELETE` `REPLACE` 等语句生效) | `Integer` | [SQLite](https://www.sqlite.org/c3ref/changes.html) [MySQL](https://dev.mysql.com/doc/c-api/8.0/en/mysql-affected-rows.html) |
266+
| `stmt.insertId` | 获取该`INSERT`/`UPDATE`/`REPLACE`语句执行后最后一个更改行的行号(关于行号的解释详见官方文档) | `Integer` | [SQLite](https://www.sqlite.org/c3ref/last_insert_rowid.html) [MySQL](https://dev.mysql.com/doc/c-api/8.0/en/mysql-stmt-insert-id.html) |
267267

268268
这些对象属性都是只读的,无法被修改,并且只能在语句执行之后获取到
269269

docs/apis/GameAPI/Block.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Each block object contains some member functions (member methods) that can be ex
9595
- Return value: Whether the write was successful or not.
9696
- Return value type: `Boolean`
9797

98-
For more usage of NBT objects, please refer to [NBT Interface Documentation](/NBT.md)
98+
For more usage of NBT objects, please refer to [NBT Interface Documentation](../NbtAPI/NBT.md)
9999
Note: Use this api with caution, consider using mc.setBlock() instead.
100100

101101

docs/apis/GameAPI/Packet.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The documentation does not list the packet ID and its structure, please check it
88

99

1010
## 目录
11-
- 🔉 [Packet Object API](#🔉-Packet-Object-api)
12-
- 🔌 [Binary stream object API](#🔌-Binary-stream-object-api)
11+
- 🔉 [Packet Object API](#-packet-object-api)
12+
- 🔌 [Binary stream object API](#-binary-stream-object-api)
1313

1414

1515

@@ -22,7 +22,7 @@ In LLSE, 「Packet Object」 is used to get information about packets.
2222
#### Get from API
2323

2424
Call some **return packet object** function to get to the packet object given by BDS
25-
See [Binary Stream Objects](#🔌-binary-stream-object-api) for details
25+
See [Binary Stream Objects](#-binary-stream-object-api) for details
2626

2727

2828

docs/apis/GameAPI/Packet.zh.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
## 目录
11-
- 🔉 [数据包对象 API](#🔉-数据包对象-api)
12-
- 🔌 [二进制流对象 API](#🔌-二进制流对象-api)
11+
- 🔉 [数据包对象 API](#-数据包对象-api)
12+
- 🔌 [二进制流对象 API](#-二进制流对象-api)
1313

1414

1515

@@ -22,7 +22,7 @@
2222
#### 从API获取
2323

2424
调用某些**返回数据包对象**的函数,来获取到BDS给出的数据包对象
25-
详见 [二进制流对象](#🔌-二进制流对象-api)
25+
详见 [二进制流对象](#-二进制流对象-api)
2626

2727

2828

docs/apis/ScriptAPI/ScriptHelp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This is an upgraded version of the above function; it supports color output.
3434

3535
#### Show results:
3636

37-
![ColorLogExample](/img/ColorLog.png)
37+
![ColorLogExample](../../img/ColorLog.png)
3838

3939
### Asynchronous Output
4040

docs/apis/ScriptAPI/ScriptHelp.zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#### 效果展示:
3535

36-
![ColorLogExample](/img/ColorLog.png)
36+
![ColorLogExample](../../img/ColorLog.png)
3737

3838
### 异步输出
3939

docs/apis/SystemAPI/Network.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
如果有更复杂的需求,可以使用各自语言平台的网络库来完成任务
55

66
## 目录
7-
- 🔌 [WebSocket 客户端对象 API](#🔌-websocket-客户端对象-api)
8-
- 📡 [Http 服务端对象 API](#📡-http-服务端对象-api)
7+
- 🔌 [WebSocket 客户端对象 API](#-websocket-客户端对象-api)
8+
- 📡 [Http 服务端对象 API](#-http-服务端对象-api)
99
- [Http 请求对象 API](#http-请求对象-api)
1010
- [Http 响应对象 API](#http-响应对象-api)
1111

docs/overrides/main.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{% extends "base.html" %}
2+
3+
{% block extrahead %}
4+
<script>
5+
(function () {
6+
const langMap = {
7+
'zh': '/zh/'
8+
};
9+
10+
const storageKey = 'user-language-set';
11+
12+
// safe storage access
13+
function storageGet(key) {
14+
try {
15+
return sessionStorage.getItem(key);
16+
} catch (e) {
17+
return null;
18+
}
19+
}
20+
21+
function storageSet(key, val) {
22+
try {
23+
sessionStorage.setItem(key, val);
24+
return true;
25+
} catch (e) {
26+
return false;
27+
}
28+
}
29+
30+
if (storageGet(storageKey)) {
31+
return;
32+
}
33+
34+
const userLang = (navigator.language || navigator.userLanguage || '').split('-')[0].toLowerCase();
35+
if (!userLang || !langMap[userLang]) {
36+
return;
37+
}
38+
const targetPath = langMap[userLang]; // e.g. '/zh/'
39+
40+
const pathname = window.location.pathname || '/';
41+
const search = window.location.search || '';
42+
const hash = window.location.hash || '';
43+
44+
// ensure targetPath ends with single slash and starts with slash
45+
const normalize = (p) => ('/' + p.replace(/^\/+|\/+$/g, '') + '/');
46+
const targetNorm = normalize(targetPath);
47+
48+
// check if pathname already has language prefix as a leading segment
49+
// match ^/zh(/|$)
50+
const langPrefixRegex = new RegExp('^' + targetNorm.replace(/\/$/, '') + '(?:\\/|$)');
51+
if (langPrefixRegex.test(pathname)) {
52+
return; // already in the right language prefix
53+
}
54+
55+
// strip any known language prefixes (values of langMap) from the start if present
56+
let cleanPath = pathname;
57+
for (const p of Object.values(langMap)) {
58+
const pNorm = normalize(p);
59+
const stripRegex = new RegExp('^' + pNorm.replace(/\/$/, '') + '(?:\\/|$)');
60+
if (stripRegex.test(cleanPath)) {
61+
cleanPath = cleanPath.replace(stripRegex, '/');
62+
break;
63+
}
64+
}
65+
66+
// make sure cleanPath begins with single slash
67+
if (!cleanPath.startsWith('/')) cleanPath = '/' + cleanPath;
68+
// avoid double slashes when building new path
69+
let newPath = targetNorm.replace(/\/+$/, '') + cleanPath.replace(/^\/+/, '/');
70+
// normalize multiple slashes
71+
newPath = newPath.replace(/\/+/g, '/');
72+
73+
// append search/hash back
74+
newPath = newPath + search + hash;
75+
76+
// set storage (best effort) before redirect to avoid repeated redirects
77+
storageSet(storageKey, userLang);
78+
79+
// use replace to avoid leaving the previous (un-prefixed) URL in history; change to href if you prefer
80+
window.location.replace(newPath);
81+
})();
82+
</script>
83+
{% endblock %}

mkdocs.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ nav:
6262

6363
theme:
6464
name: material
65+
custom_dir: docs/overrides
6566
features:
6667
- navigation.tabs
6768
- navigation.tabs.sticky
@@ -88,7 +89,10 @@ markdown_extensions:
8889
- def_list
8990
- footnotes
9091
- md_in_html
91-
- toc
92+
- toc:
93+
slugify: !!python/object/apply:pymdownx.slugs.slugify
94+
kwds:
95+
case: lower
9296
- tables
9397
- pymdownx.arithmatex
9498
- pymdownx.betterem

0 commit comments

Comments
 (0)