Skip to content

Commit 53647ed

Browse files
LessUpqwencoder
andcommitted
docs: 彻底更新和优化文档系统
- 更新VitePress配置:添加API参考、基准测试、贡献指南导航 - 新增API参考页面:Go库、Rust包、C++实现 - 新增基准测试结果页面和运行指南 - 新增参与贡献指南页面(双语) - 更新快速开始指南反映新的Go cmd/结构 - 更新项目结构文档 - 完善搜索配置的英文本地化 - 更新暗色模式样式和CSS变量 - 增强特性卡片悬停效果和滚动条样式 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 2bae804 commit 53647ed

19 files changed

Lines changed: 1424 additions & 15 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,65 @@ const sharedSidebar = {
55
'/en/': [
66
{
77
text: 'Overview',
8-
items: [{ text: 'Home', link: '/en/' }],
8+
items: [
9+
{ text: 'Home', link: '/en/' },
10+
{ text: 'Quick Start', link: '/en/guide/getting-started' },
11+
{ text: 'Algorithms', link: '/en/guide/algorithms' },
12+
],
913
},
1014
{
11-
text: 'Guide',
15+
text: 'API Reference',
1216
items: [
13-
{ text: 'Getting Started', link: '/en/guide/getting-started' },
14-
{ text: 'Algorithms', link: '/en/guide/algorithms' },
17+
{ text: 'Go Library', link: '/en/api/go' },
18+
{ text: 'Rust Crate', link: '/en/api/rust' },
19+
{ text: 'C++ Header', link: '/en/api/cpp' },
20+
],
21+
},
22+
{
23+
text: 'Benchmarks',
24+
items: [
25+
{ text: 'Performance Results', link: '/en/benchmarks/results' },
26+
{ text: 'How to Run', link: '/en/benchmarks/how-to-run' },
1527
],
1628
},
1729
{
1830
text: 'Reference',
1931
items: [
2032
{ text: 'Project Structure', link: '/en/guide/project-structure' },
33+
{ text: 'Contributing', link: '/en/guide/contributing' },
2134
{ text: 'Specs (SSOT)', link: 'https://github.com/LessUp/encoding/tree/master/specs' },
2235
],
2336
},
2437
],
2538
'/zh/': [
2639
{
2740
text: '概览',
28-
items: [{ text: '首页', link: '/zh/' }],
29-
},
30-
{
31-
text: '指南',
3241
items: [
42+
{ text: '首页', link: '/zh/' },
3343
{ text: '快速开始', link: '/zh/guide/getting-started' },
3444
{ text: '算法详解', link: '/zh/guide/algorithms' },
3545
],
3646
},
47+
{
48+
text: 'API 参考',
49+
items: [
50+
{ text: 'Go 库', link: '/zh/api/go' },
51+
{ text: 'Rust 包', link: '/zh/api/rust' },
52+
{ text: 'C++ 头文件', link: '/zh/api/cpp' },
53+
],
54+
},
55+
{
56+
text: '基准测试',
57+
items: [
58+
{ text: '性能结果', link: '/zh/benchmarks/results' },
59+
{ text: '如何运行', link: '/zh/benchmarks/how-to-run' },
60+
],
61+
},
3762
{
3863
text: '参考',
3964
items: [
4065
{ text: '项目结构', link: '/zh/guide/project-structure' },
66+
{ text: '参与贡献', link: '/zh/guide/contributing' },
4167
{ text: '规范文档 (SSOT)', link: 'https://github.com/LessUp/encoding/tree/master/specs' },
4268
],
4369
},
@@ -49,7 +75,9 @@ const sharedNav = (lang: string) => [
4975
{ text: lang === 'zh' ? '概览' : 'Overview', link: lang === 'zh' ? '/zh/' : '/en/' },
5076
{ text: lang === 'zh' ? '快速开始' : 'Get Started', link: lang === 'zh' ? '/zh/guide/getting-started' : '/en/guide/getting-started' },
5177
{ text: lang === 'zh' ? '算法' : 'Algorithms', link: lang === 'zh' ? '/zh/guide/algorithms' : '/en/guide/algorithms' },
52-
{ text: lang === 'zh' ? '参考' : 'Reference', link: lang === 'zh' ? '/zh/guide/project-structure' : '/en/guide/project-structure' },
78+
{ text: lang === 'zh' ? 'API' : 'API', link: lang === 'zh' ? '/zh/api/go' : '/en/api/go' },
79+
{ text: lang === 'zh' ? '性能' : 'Benchmarks', link: lang === 'zh' ? '/zh/benchmarks/results' : '/en/benchmarks/results' },
80+
{ text: lang === 'zh' ? '贡献' : 'Contributing', link: lang === 'zh' ? '/zh/guide/contributing' : '/en/guide/contributing' },
5381
{ text: 'Changelog', link: 'https://github.com/LessUp/encoding/blob/master/CHANGELOG.md' },
5482
]
5583

@@ -72,7 +100,7 @@ export default defineConfig({
72100
['meta', { property: 'og:title', content: 'Encoding | Compression Algorithms Collection' }],
73101
['meta', { property: 'og:description', content: 'Classic compression algorithms in C++, Go, and Rust for learning, comparison and cross-language verification' }],
74102
['meta', { property: 'og:url', content: 'https://lessup.github.io/encoding/' }],
75-
['meta', { name: 'twitter:card', content: 'summary' }],
103+
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
76104
['meta', { name: 'twitter:title', content: 'Encoding | Compression Algorithms Collection' }],
77105
['meta', { name: 'twitter:description', content: 'Classic compression algorithms in C++, Go, and Rust for learning, comparison and cross-language verification' }],
78106
['link', { rel: 'icon', type: 'image/svg+xml', href: '/encoding/logo.svg' }],
@@ -159,11 +187,28 @@ export default defineConfig({
159187
{ icon: 'github', link: 'https://github.com/LessUp/encoding' },
160188
],
161189

162-
// Search (shared)
190+
// Search (localized)
163191
search: {
164192
provider: 'local',
165193
options: {
166194
locales: {
195+
root: {
196+
translations: {
197+
button: {
198+
buttonText: 'Search',
199+
buttonAriaLabel: 'Search docs',
200+
},
201+
modal: {
202+
noResultsText: 'No results found',
203+
resetButtonTitle: 'Reset search',
204+
footer: {
205+
selectText: 'select',
206+
navigateText: 'navigate',
207+
closeText: 'close',
208+
},
209+
},
210+
},
211+
},
167212
zh: {
168213
translations: {
169214
button: {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
11
/* Custom styles */
2+
3+
/* Algorithm comparison table - highlight compression ratios */
4+
.vp-doc table td:last-child {
5+
font-variant-numeric: tabular-nums;
6+
}
7+
8+
/* Code block improvements */
9+
.vp-doc .line-numbers-mode {
10+
border-radius: 8px;
11+
}
12+
13+
/* Improve dark mode contrast for code blocks */
14+
.dark .vp-doc div[class*='language-'] {
15+
border: 1px solid var(--vp-c-border);
16+
}
17+
18+
/* Hero image sizing */
19+
.VPHero .image-container {
20+
width: 200px;
21+
height: 200px;
22+
}
23+
24+
.VPHero .image-bg {
25+
width: 200px;
26+
height: 200px;
27+
}
28+
29+
/* Feature card hover effect */
30+
.VPFeature {
31+
transition: transform 0.2s ease, box-shadow 0.2s ease;
32+
}
33+
34+
.VPFeature:hover {
35+
transform: translateY(-2px);
36+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
37+
}
38+
39+
.dark .VPFeature:hover {
40+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
41+
}
42+
43+
/* Scrollbar styling */
44+
::-webkit-scrollbar {
45+
width: 8px;
46+
height: 8px;
47+
}
48+
49+
::-webkit-scrollbar-track {
50+
background: transparent;
51+
}
52+
53+
::-webkit-scrollbar-thumb {
54+
background: var(--vp-c-divider);
55+
border-radius: 4px;
56+
}
57+
58+
::-webkit-scrollbar-thumb:hover {
59+
background: var(--vp-c-text-3);
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
/* Custom CSS variables for VitePress theme */
2+
3+
:root {
4+
--vp-c-brand: #3b82f6;
5+
--vp-c-brand-light: #60a5fa;
6+
--vp-c-brand-lighter: #93c5fd;
7+
--vp-c-brand-dark: #2563eb;
8+
--vp-c-brand-darker: #1d4ed8;
9+
--vp-c-brand-1: #3b82f6;
10+
--vp-c-brand-2: #2563eb;
11+
--vp-c-brand-3: #1d4ed8;
12+
}
13+
14+
.dark {
15+
--vp-c-brand: #60a5fa;
16+
--vp-c-brand-light: #93c5fd;
17+
--vp-c-brand-lighter: #bfdbfe;
18+
--vp-c-brand-dark: #3b82f6;
19+
--vp-c-brand-darker: #2563eb;
20+
--vp-c-brand-1: #60a5fa;
21+
--vp-c-brand-2: #3b82f6;
22+
--vp-c-brand-3: #2563eb;
23+
}

docs/en/api/cpp.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# C++ Implementation Reference
2+
3+
All C++ implementations are single-file, zero-dependency programs using C++17.
4+
5+
## Compilation
6+
7+
```bash
8+
g++ -std=c++17 -O2 -Wall -Wextra -o <binary> main.cpp
9+
```
10+
11+
### Recommended Flags
12+
13+
| Flag | Purpose |
14+
|------|---------|
15+
| `-std=c++17` | Enable C++17 features |
16+
| `-O2` | Optimization level |
17+
| `-Wall -Wextra` | Warnings |
18+
| `-fsanitize=address` | AddressSanitizer (debug builds) |
19+
| `-fsanitize=undefined` | UBSan (debug builds) |
20+
21+
## Huffman (`algorithms/huffman/cpp/main.cpp`)
22+
23+
### Usage
24+
25+
```bash
26+
./huffman_cpp encode input.bin output.huf
27+
./huffman_cpp decode output.huf decoded.bin
28+
```
29+
30+
### Internal Structure
31+
32+
- `BitWriter` / `BitReader` — bit-level I/O classes
33+
- `Node` — Huffman tree node with custom deleter
34+
- `compress_file()` / `decompress_file()` — main encode/decode functions
35+
36+
### File Format
37+
38+
| Offset | Size | Field |
39+
|--------|------|-------|
40+
| 0 | 4B | Magic: `HFMN` |
41+
| 4 | 4B | Frequency table size (always 257) |
42+
| 8 | 1028B | Frequency table (257 × uint32 LE) |
43+
| 1036+ | Variable | Encoded bit stream |
44+
45+
---
46+
47+
## Arithmetic (`algorithms/arithmetic/cpp/main.cpp`)
48+
49+
### Usage
50+
51+
```bash
52+
./arithmetic_cpp encode input.bin output.aenc
53+
./arithmetic_cpp decode output.aenc decoded.bin
54+
```
55+
56+
### Key Classes
57+
58+
- `ArithmeticEncoder` — state machine with `low`, `high`, `pendingBits`
59+
- `ArithmeticDecoder` — decoder with `code` initialization
60+
61+
---
62+
63+
## Range Coder (`algorithms/range/cpp/main.cpp`)
64+
65+
### Usage
66+
67+
```bash
68+
./rangecoder_cpp encode input.bin output.rcnc
69+
./rangecoder_cpp decode output.rcnc decoded.bin
70+
```
71+
72+
### File Format
73+
74+
| Offset | Size | Field |
75+
|--------|------|-------|
76+
| 0 | 4B | Magic: `RCNC` |
77+
| 4 | 4B | Frequency table size |
78+
| 8 | Variable | Frequency table |
79+
| ... | Variable | Byte stream (renormalized intervals) |
80+
81+
---
82+
83+
## RLE (`algorithms/rle/cpp/main.cpp`)
84+
85+
### Usage
86+
87+
```bash
88+
./rle_cpp encode input.bin output.rle
89+
./rle_cpp decode output.rle decoded.bin
90+
```
91+
92+
### File Format
93+
94+
Repeated `(count: uint32 LE, value: byte)` pairs.
95+
96+
---
97+
98+
## Common Patterns
99+
100+
| Pattern | Description |
101+
|---------|-------------|
102+
| Single file | Each algorithm in one `main.cpp` |
103+
| Zero dependencies | Only standard library |
104+
| `#include <...>` | Standard library only |
105+
| Error handling | `fprintf(stderr, ...)` + `exit(1)` |
106+
| Memory management | `std::unique_ptr` with custom deleters |

0 commit comments

Comments
 (0)