Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 80 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,93 @@
# Based on ripgrep's release action:
# https://github.com/BurntSushi/ripgrep/blob/master/.github/workflows/release.yml

name: Deploy Documentation
on:
push:
branches:
- main
permissions:
contents: write
- cn-revamp
workflow_dispatch:

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

env:
GITHUB_PAGES_BASE: "/${{ github.event.repository.name }}/"

jobs:
build-and-deploy:
name: build-and-deploy
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5
- name: Checkout typst-docs-web
uses: actions/checkout@v5
with:
repository: typst-community/typst-docs-web
path: docs-web

# Setup this repo
- uses: dtolnay/[email protected]
- uses: Swatinem/rust-cache@v2
# python3 and package jinja2
- uses: actions/setup-python@v2
with:
python-version: 3.x
- run: python3 -m pip install jinja2 PyYAML
- run: cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture
- run: python3 ./gen.py
# deploy ./dist to https://github.com/typst-doc-cn/typst-doc-cn.github.io
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
- run: python3 -m pip install PyYAML

# Setup typst-docs-web
- name: Setup tools managed by mise
uses: jdx/mise-action@13abe502c30c1559a5c37dff303831bab82c9402 # v2.2.3
with:
working_directory: docs-web
- name: Install dependencies
run: bun install --frozen-lockfile
working-directory: docs-web
- uses: taiki-e/install-action@v2
with:
folder: dist # The folder the action should deploy.

tool: sd
- name: Apply docs-web patches
working-directory: docs-web
run: |
git apply ../docs-web-scripts/0001-fix-use-Chinese-fonts.patch

- name: Create `assets/docs.json` and `assets/docs/*.png`
run: cargo test --package typst-docs --lib -- tests::test_docs --exact --nocapture
- name: Generate `assets/docs.zh.json`
run: python3 ./docs-web-scripts/generate_docs_zh_json.py

- name: Put files for typst-docs-web
shell: bash
run: |
set -euxo pipefail

cd docs-web/public

ln -s ../../assets/docs.zh.json docs.json
ln -s ../../assets/docs assets
ln -s ../../docs-web-scripts/metadata.json .

# Change base
sd '"/docs/' '"${{ env.GITHUB_PAGES_BASE }}' docs.json
sd '"basePath": "/docs/"' '"basePath": "${{ env.GITHUB_PAGES_BASE }}"' metadata.json

curl -L https://github.com/typst-community/org/raw/main/design/typst-community.icon.png \
-o favicon.png
- run: bun run build
working-directory: docs-web

- uses: actions/upload-pages-artifact@v4
with:
path: ./docs-web/dist/

deploy:
needs: build
permissions:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion crates/typst-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ mod tests {
let path = Path::new("../../assets/docs").join(filename.clone());
let _ = pixmap.save_png(path).map_err(|_| "failed to write PNG file");
Html::new(format!(
r#"<div class="previewed-code"><pre>{}</pre><div class="preview"><img src="/assets/docs/{}" alt="Preview" width="480" height="190"/></div></div>"#,
r#"<div class="previewed-code"><pre>{}</pre><div class="preview"><img src="/docs/assets/{}" alt="Preview" width="480" height="190"/></div></div>"#,
source.as_str(), filename
))

Expand Down
72 changes: 72 additions & 0 deletions docs-web-scripts/0001-fix-use-Chinese-fonts.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 8f24591a162542a1cd8fee72f0baca8a1ed7872a Mon Sep 17 00:00:00 2001
From: "Y.D.X." <[email protected]>
Date: Thu, 11 Dec 2025 20:21:19 +0800
Subject: [PATCH] fix: use Chinese fonts

---
src/globals.css | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/globals.css b/src/globals.css
index 1f6e1e4..f3d7573 100644
--- a/src/globals.css
+++ b/src/globals.css
@@ -35,11 +35,52 @@
font-display: swap;
}

+/*
+ The font configuration below is adpated from CLReq's local.css (W3C license).
+ https://github.com/w3c/clreq/blob/7cec684ff79714a9624bae6234d329c1d9413b99/local.css
+ https://www.w3.org/copyright/software-license-2023/
+*/
+
+@font-face {
+ font-family: "Punctuation SC";
+ src:
+ local("PingFang SC"), local("Noto Sans CJK SC"), local("Noto Sans SC"),
+ local("Heiti SC"), local("Microsoft Yahei");
+ unicode-range:
+ U+201C, U+201D, U+2018, U+2019, U+2E3A, U+2014, U+2013, U+2026, U+00B7,
+ U+007E, U+002F; /* Unicode range for punctuation marks */
+}
+
+/*
+-apple-system: iOS Safari, macOS Safari, macOS Firefox
+BlinkMacSystemFont: macOS Chrome
+Segoe UI: Windows
+Roboto: Android, Chrome OS
+Oxygen-Sans: KDE
+Fira Sans: Firefox OS
+Droid Sans: Older versions of Android
+Ubuntu: Ubuntu
+Cantarell: GNOME
+Helvetica Neue: macOS versions < 10.11
+Arial: Any
+PingFang SC: macOS
+Noto Sans CJK SC: Ubuntu, Android
+Noto Sans SC: Ubuntu, Android
+Heiti SC: macOS
+DengXian: Windows
+Microsoft Jhenghei / Microsoft Yahei: Windows < Vista
+sans-serif: Fallback
+*/
+
body {
font-family:
- "HK Grotesk", Inter, "BIZ UDGothic", "BIZ UDPGothic", system-ui,
- -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
- Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
+ "Punctuation SC", "HK Grotesk", Inter, system-ui,
+ -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue",
+ "PingFang SC", "Noto Sans CJK SC", "Noto Sans SC", "Heiti SC", "DengXian", "Microsoft YaHei", sans-serif;
+}
+
+[lang="zh-hans"] {
+ text-autospace: normal;
}

code,
--
2.51.2.windows.1

43 changes: 43 additions & 0 deletions docs-web-scripts/generate_docs_zh_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import os
from pathlib import Path

import yaml


def translate_with_yaml(page):
if page["body"]["kind"] in ["func", "type", "group", "category"]:
route = page["route"][:-1] if page["route"].endswith("/") else page["route"]
assert route.startswith("/docs/reference/")
if page["body"]["kind"] == "category":
path = ["category"] + route[len("/docs/reference/") :].split("/")
else:
path = route[len("/docs/reference/") :].split("/")
assert len(path) == 2, str(path) + " " + route

# without quotes and with indent
zh_path = "docs/i18n/" + path[0] + "/" + path[1] + "-zh.yaml"
if os.path.exists(zh_path):
# Change the base path to /docs/
page = yaml.load(
Path(zh_path)
.read_text(encoding="utf-8")
.replace('<img src="/assets/docs/', '<img src="/docs/assets/'),
Loader=yaml.FullLoader,
)
print(zh_path)

for i in range(len(page["children"])):
page["children"][i] = translate_with_yaml(page["children"][i])
return page


if __name__ == "__main__":
# load assets/docs.json docs/i18n/**/*-zh.yaml and combine them into assets/docs.zh.json
with open("./assets/docs.json", "r", encoding="utf-8") as f:
docs = json.load(f)
for i in range(len(docs)):
docs[i] = translate_with_yaml(docs[i])

with Path("./assets/docs.zh.json").open("w") as ff:
json.dump(docs, ff, ensure_ascii=False, indent=2)
18 changes: 18 additions & 0 deletions docs-web-scripts/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "../metadata.schema.json",
"language": "zh-Hans",
"version": "0.10.0+后期随缘更新",
"typstOfficialUrl": "https://typst.app",
"typstOfficialDocsUrl": "https://typst.app/docs/",
"githubOrganizationUrl": "https://github.com/typst-doc-cn",
"socialLinks": [
{ "url": "https://github.com/typst-doc-cn/typst-doc-cn.github.io" },
{
"url": "https://qm.qq.com/q/MQO6j6jCw2",
"title": "Typst 非官方中文交流群(QQ 793548390)"
}
],
"originUrl": "https://typst-doc-cn.github.io/",
"basePath": "/docs/",
"displayTranslationStatus": false
}