Skip to content

Commit c0df9ba

Browse files
committed
[contrib][doc] Setup documentation demo
1 parent aa6b355 commit c0df9ba

File tree

8 files changed

+285
-1
lines changed

8 files changed

+285
-1
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Simple workflow for deploying static content to GitHub Pages
2+
name: Deploy static content to Pages
3+
4+
on:
5+
# Runs on pushes targeting the default branch
6+
push:
7+
# TODO: Change this to dev
8+
branches: ["2025-01-20-mkdocs"]
9+
10+
# Allows you to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
14+
permissions:
15+
contents: read
16+
pages: write
17+
id-token: write
18+
19+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
20+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
21+
concurrency:
22+
group: "pages"
23+
cancel-in-progress: false
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
submodules: recursive
33+
- name: Setup Pages
34+
uses: actions/configure-pages@v5
35+
- name: Setup build environment
36+
run: |
37+
sudo apt-get update
38+
sudo apt-get install doxygen clang-format
39+
pip install mkdocs-material==9.5.50 mkdocstrings==0.27.0 mkdocs-autorefs==1.3.0
40+
- name: build
41+
run: |
42+
./contrib/doc/mkdocs.py build
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
45+
with:
46+
path: './build-docs/site/'
47+
48+
49+
deploy:
50+
environment:
51+
name: github-pages
52+
url: ${{ steps.deployment.outputs.page_url }}
53+
runs-on: ubuntu-latest
54+
needs: build
55+
steps:
56+
- name: Deploy to GitHub Pages
57+
id: deployment
58+
uses: actions/deploy-pages@v4

contrib/doc/mkdocs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
# A script to invoke mkdocs with the correct environment.
3+
# Additionally supports deploying via mike:
4+
# ./mkdocs deploy
5+
6+
import errno
7+
import os
8+
import shutil
9+
import sys
10+
from pathlib import Path
11+
from subprocess import call
12+
13+
contrib_doc_dir = Path(__file__).parent
14+
root_dir = contrib_doc_dir.parents[1]
15+
zstd_handler_dir = contrib_doc_dir / "mkdocstrings-zstd" / "src"
16+
config_path = os.path.join(contrib_doc_dir, "mkdocs.yml")
17+
18+
19+
build_dir = root_dir / "build-docs"
20+
21+
# Set PYTHONPATH for the mkdocstrings handler.
22+
env = os.environ.copy()
23+
path = env.get("PYTHONPATH")
24+
env["PYTHONPATH"] = (path + ":" if path else "") + str(zstd_handler_dir)
25+
26+
args = sys.argv[1:]
27+
args += ["-f", config_path]
28+
sys.exit(call(["mkdocs"] + args, env=env))

contrib/doc/mkdocs.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
site_name: 'Zstandard'
2+
3+
docs_dir: ../../doc
4+
5+
site_dir: ../../build-docs/site
6+
7+
repo_url: https://github.com/facebook/zstd
8+
9+
extra_css:
10+
- zstd.css
11+
12+
nav:
13+
- Home: index.md
14+
- User Guide:
15+
- Basics: user-guide/basics.md
16+
- Simple: user-guide/simple.md
17+
- Advanced: user-guide/advanced.md
18+
19+
theme:
20+
name: material
21+
logo: images/zstd_logo86.png
22+
favicon: images/zstd_logo86.png
23+
features:
24+
- search.suggest
25+
- navigation.tabs
26+
- navigation.top
27+
# - toc.integrate
28+
29+
palette:
30+
# Palette toggle for automatic mode
31+
- media: "(prefers-color-scheme)"
32+
toggle:
33+
icon: material/brightness-auto
34+
name: Switch to light mode
35+
36+
# Palette toggle for light mode
37+
- media: "(prefers-color-scheme: light)"
38+
scheme: default
39+
toggle:
40+
icon: material/brightness-7
41+
name: Switch to dark mode
42+
43+
# Palette toggle for dark mode
44+
- media: "(prefers-color-scheme: dark)"
45+
scheme: slate
46+
toggle:
47+
icon: material/brightness-4
48+
name: Switch to system preference
49+
50+
markdown_extensions:
51+
- admonition
52+
- pymdownx.details
53+
- md_in_html
54+
- pymdownx.highlight:
55+
use_pygments: true
56+
anchor_linenums: true
57+
line_spans: __span
58+
pygments_lang_class: true
59+
- pymdownx.inlinehilite
60+
- pymdownx.snippets
61+
- pymdownx.superfences:
62+
custom_fences:
63+
- name: mermaid
64+
class: mermaid
65+
format: !!python/name:pymdownx.superfences.fence_code_format
66+
67+
plugins:
68+
- search
69+
- mkdocstrings:
70+
default_handler: zstd
71+
handlers:
72+
zstd:
73+
source_directory: "../../lib/"
74+
build_directory: "../../build-docs/"
75+
sources: [
76+
"zstd.h",
77+
"zstd_errors.h",
78+
]
79+
predefined:
80+
- ZSTD_STATIC_LINKING_ONLY
81+
options:
82+
clang_format_based_on_style: "Google"
83+
heading_level: 3
84+
85+
# exclude_docs: ChangeLog-old.md
86+
87+
extra:
88+
generator: false
89+
# version:
90+
# provider: mike

doc/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Under Construction

doc/user-guide/advanced.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Compression Context
2+
3+
Context lifteimte management
4+
5+
::: ZSTD_createCCtx
6+
7+
::: ZSTD_freeCCtx
8+
9+
## Configure Compression
10+
11+
Configure any parameters you like
12+
13+
::: ZSTD_CCtx_setParameter
14+
15+
::: ZSTD_cParameter
16+
17+
## Dictionary Compression
18+
19+
Load dictionaries
20+
21+
::: ZSTD_CCtx_loadDictionary
22+
23+
## Single shot compression
24+
25+
Then compress
26+
27+
::: ZSTD_compress2
28+
29+
## Streaming compression
30+
31+
You can also use streaming compression
32+
33+
::: ZSTD_compressStream2
34+
35+
::: ZSTD_EndDirective

doc/user-guide/basics.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Basics
3+
---
4+
These are the basic helper functions that you need to interact with `zstd`.
5+
6+
## Error Checking
7+
8+
Any function that returns a `size_t` must be checked with `ZSTD_isError()`.
9+
10+
::: ZSTD_isError
11+
12+
If the function returned an error, then `ZSTD_getErrorName()` will return the error string.
13+
14+
::: ZSTD_getErrorName
15+
16+
## Compression Utilities
17+
18+
`ZSTD_compressBound()` returns the maximum possible compressed size of a given
19+
input, which will be slightly larger than the input size. If you provide an
20+
output buffer at least this large to [ZSTD_compress()][ZSTD_compress],
21+
[ZSTD_compressCCtx()][ZSTD_compressCCtx], or [ZSTD_compress2()][ZSTD_compress2]
22+
the compressed result is guaranteed to fit.
23+
24+
::: ZSTD_compressBound
25+
26+
## Decompression Utilities
27+
28+
`ZSTD_getFrameContentSize()` will return the (decompressed) content size of a
29+
Zstandard or Skippable frame. If the content size is not known it will return
30+
[ZSTD_CONTENTSIZE_UNKNOWN][], and if an error occurs it will return
31+
[ZSTD_CONTENTSIZE_ERROR][].
32+
33+
???+ warning
34+
35+
This only returns the content size of the first compressed frame in the
36+
compressed source. Zstd decompression functions like
37+
[ZSTD_decompress()][ZSTD_decompress] will decompress zero or more
38+
concatenated frames. So calling this function does not guarantee that
39+
decompression will have enough space, unless you know a-priori that there
40+
is only one compressed frame in the source.
41+
42+
::: ZSTD_getFrameContentSize
43+
44+
::: ZSTD_CONTENTSIZE_UNKNOWN
45+
options:
46+
show_description: false
47+
48+
::: ZSTD_CONTENTSIZE_ERROR
49+
options:
50+
show_description: false
51+
52+
`ZSTD_findFrameCompressedSize()` will return the compressed size of the Zstd
53+
frame. This function can be useful if:
54+
55+
- You don't know the compressed size of the frame.
56+
- There may be more than one compressed frame in the compressed source.
57+
58+
???+ note
59+
60+
This function has to traverse the entire Zstd compressed frame, and read
61+
each block's header. It is cheap, given that there is normally one block
62+
for every 128 KiB of content, but it isn't free.
63+
64+
::: ZSTD_findFrameCompressedSize

doc/user-guide/simple.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
::: ZSTD_compress
3+
4+
::: ZSTD_decompress
5+
6+
::: ZSTD_compressCCtx
7+
8+
::: ZSTD_decompressDCtx

0 commit comments

Comments
 (0)