#!/usr/bin/env python3
"""Writes the site's pages, its sitemap and its 404 page from docs/site/index.src.html.
The source is one multilingual document with five views (home, docs, pricing, and the
claude-code and codex landing pages). Every view in each of its languages gets its own address,
so each page a search engine sees has one language, one view, one
, and its own title,
description, canonical URL, hreflang alternates, social cards and structured data:
/ /docs/ /pricing/ /claude-code/ /codex/ (Chinese; the root is x-default)
/en/ /en/docs/ /en/pricing/ /en/claude-code/ /en/codex/ (English)
/ja/claude-code/ /ja/codex/ (Japanese: these two views only)
A view lists its languages in VIEW_LANGS; hreflang, the language switch and the sitemap name only
the ones it has. A link from a Japanese page to a view without Japanese leads to its English page.
Run after editing docs/site/index.src.html. Never edit the generated index.html files.
"""
import datetime
import html
import json
import pathlib
import re
SITE = pathlib.Path(__file__).resolve().parent.parent / "docs" / "site"
BASE = "https://linkshell.itool.tech/"
GITHUB = "https://github.com/LiuTianjie/LinkShell"
APP_STORE = "https://apps.apple.com/cn/app/linkshell/id6761547516"
# The landing pages are read outside China too: the store picks the visitor's own region.
APP_STORE_ANY = "https://apps.apple.com/app/id6761547516"
GITHUB_PAGES_REDIRECT = (
''
)
PRODUCT_HUNT = "https://www.producthunt.com/products/linkshell"
LANGS = {
"zh": {"prefix": "", "html": "zh-CN", "og": "zh_CN", "og_image": "assets/og.png"},
"en": {"prefix": "en/", "html": "en", "og": "en_US", "og_image": "assets/og-en.png"},
# No Japanese share image exists: the English one is the closer of the two.
"ja": {"prefix": "ja/", "html": "ja", "og": "ja_JP", "og_image": "assets/og-en.png"},
}
VIEWS = {"home": "", "docs": "docs/", "pricing": "pricing/", "claude-code": "claude-code/", "codex": "codex/"}
# The languages each view is written in; the first is x-default.
VIEW_LANGS = {
"home": ("zh", "en"),
"docs": ("zh", "en"),
"pricing": ("zh", "en"),
"claude-code": ("zh", "en", "ja"),
"codex": ("zh", "en", "ja"),
}
LANDING = ("claude-code", "codex")
# Where a page in one language sends a link to a view that isn't written in it.
FALLBACK = {"ja": "en"}
SWITCH_LABEL = {"zh": "中文", "en": "EN", "ja": "日本語"}
META = {
("zh", "home"): {
"title": "LinkShell | 手机远程控制 Claude Code、Codex 编程 Agent",
"description": "LinkShell 让 Claude Code、Codex、Gemini CLI 等编程 Agent 留在电脑上运行,你在 iPhone、Android、手表或锁屏上看进度、审批、插话;还能远程控制 Mac 桌面,用融合模式把另一台 Mac 的应用开在这台 Mac 上。端到端加密,可自建网关。",
"keywords": "LinkShell, 手机远程控制 Claude Code, Codex 手机, 编程 Agent, AI 编程助手, 远程桌面, Mac 远程控制, 融合模式, Mac 应用串流, 远程终端, iOS, Android, 端到端加密, 自建网关",
"image_alt": "LinkShell 首页:离开电脑,Agent 接着干,手机上收到 Claude 的审批请求",
},
("zh", "docs"): {
"title": "LinkShell 文档 | 安装、连接手机、自建网关",
"description": "LinkShell 文档:安装 Mac / Windows 桌面 App 或 CLI,启动 Host,用官方网关或自建网关连接手机,远程桌面,在终端里用 linkshell claude / codex 接力,以及常见问题。",
"keywords": "LinkShell 文档, LinkShell 安装, 自建网关, linkshell claude, linkshell codex, 远程桌面, 连接手机",
"image_alt": "LinkShell:在手机上继续电脑里的编程 Agent",
},
("zh", "pricing"): {
"title": "LinkShell 定价 | 免费使用,iTool 会员提供官方网关",
"description": "LinkShell 全部功能免费,自建网关即可使用。iTool 会员提供官方网关:单品 ¥49/年或 ¥9.9/月,全产品年包 ¥99/年,价格已含税,前往 iTool 官网购买。连接始终端到端加密。",
"keywords": "LinkShell 定价, iTool 会员, 官方网关, 免费, 自建网关",
"image_alt": "LinkShell:在手机上继续电脑里的编程 Agent",
},
("en", "home"): {
"title": "LinkShell: Control Claude Code and Codex from Your Phone",
"description": "Your local Claude Code, Codex, terminal, localhost previews, and 120fps Mac screen — end-to-end encrypted in your pocket. Approve from the Lock Screen or Apple Watch, steer mid-turn, or self-host the relay free.",
"keywords": "LinkShell, Claude Code mobile, Codex on phone, remote control coding agent, AI coding agent, remote desktop, remote Mac, Fusion Mode, remote Mac apps, remote terminal, iOS, Android, end-to-end encryption, self-hosted gateway",
"image_alt": "LinkShell's home page: leave your desk, your agents keep going, with a request from Claude on the phone",
},
("en", "docs"): {
"title": "LinkShell Docs: Install, Connect Your Phone, Self-Host",
"description": "Install LinkShell on Mac, Windows or Linux, connect your phone through the official or a self-hosted gateway, and hand off Claude Code and Codex sessions.",
"keywords": "LinkShell docs, install LinkShell, self-hosted gateway, linkshell claude, linkshell codex, remote screen, pair phone",
"image_alt": "LinkShell: follow the coding agents on your computer from your phone",
},
("en", "pricing"): {
"title": "LinkShell Pricing: Free Self-Hosted, or Cloud Relay from $12/mo",
"description": "Every LinkShell feature is free with your own gateway. LinkShell Pro adds the managed end-to-end encrypted relay and TURN screen streaming for $12/month or $99/year — or unlock all 7 iTool apps with the $199/year All-Access Pass. Tax included.",
"keywords": "LinkShell pricing, LinkShell Pro, official gateway, free self-hosted, All-Access Pass",
"image_alt": "LinkShell: follow the coding agents on your computer from your phone",
},
("zh", "claude-code"): {
"title": "手机远程控制 Claude Code:iPhone、Android 上审批和插话 | LinkShell",
"description": "Claude Code 留在电脑上跑,你在 iPhone、Android 和 Apple Watch 上看回复、批准权限请求、往正在跑的一轮里插话。linkshell claude 在终端和手机之间接力,端到端加密,自建网关免费。",
"keywords": "手机远程控制 Claude Code, Claude Code 手机, Claude Code iPhone, Claude Code 远程, Claude Code 审批, linkshell claude, Claude Code Android, Apple Watch",
"image_alt": "LinkShell:在手机上跟进、批准和插话 Claude Code",
},
("en", "claude-code"): {
"title": "Claude Code Remote Control from iPhone and Android | LinkShell",
"description": "Keep Claude Code running on your computer and control it from your phone: follow replies, approve permission requests from the Lock Screen or Apple Watch, and steer the running turn. End-to-end encrypted.",
"keywords": "Claude Code remote control, Claude Code on phone, Claude Code iPhone, Claude Code mobile, approve Claude Code permissions, linkshell claude, Claude Code Android, Apple Watch",
"image_alt": "LinkShell: follow, approve and steer Claude Code from your phone",
},
("ja", "claude-code"): {
"title": "iPhone で Claude Code を操作・承認 | LinkShell",
"description": "Claude Code はパソコンで動かしたまま、iPhone・Android・Apple Watch から返信を追い、権限リクエストを承認し、実行中のターンに指示を送れます。通信はエンドツーエンドで暗号化されます。",
"keywords": "Claude Code iPhone, iPhone で Claude Code を操作, Claude Code リモート操作, Claude Code スマホ, Claude Code 承認, linkshell claude, Apple Watch",
"image_alt": "LinkShell:iPhone から Claude Code を追い、承認し、指示を送る",
},
("zh", "codex"): {
"title": "手机上用 Codex:iPhone 审批、插话和 Computer Use | LinkShell",
"description": "Codex 留在电脑上跑,linkshell codex 让终端和手机同时在线:在 iPhone、Android 和 Apple Watch 上看进度、批准请求、插话,还能让 Codex 操作 Mac 上的浏览器和应用。端到端加密。",
"keywords": "Codex 手机, 手机远程控制 Codex, Codex iPhone, Codex 审批, linkshell codex, Codex Computer Use, Codex Android, Apple Watch",
"image_alt": "LinkShell:在手机上跟进、批准和插话 Codex",
},
("en", "codex"): {
"title": "Codex on Your Phone: Approve and Steer Codex from iPhone | LinkShell",
"description": "Run Codex on your computer and stay in the loop from iPhone, Android or Apple Watch: approve requests, steer the running turn and watch Computer Use live. The terminal and the phone stay live together.",
"keywords": "Codex on phone, Codex iPhone, approve Codex from iPhone, Codex mobile, Codex remote control, linkshell codex, Codex Computer Use, Codex Android",
"image_alt": "LinkShell: follow, approve and steer Codex from your phone",
},
("ja", "codex"): {
"title": "iPhone で Codex を操作・承認 | LinkShell",
"description": "Codex はパソコンで動かしたまま、iPhone・Android・Apple Watch から進み具合を追い、リクエストを承認し、実行中のターンに指示を送れます。Computer Use の画面もライブで見られます。",
"keywords": "Codex iPhone, iPhone で Codex を操作, Codex スマホ, Codex 承認, Codex リモート操作, linkshell codex, Codex Computer Use",
"image_alt": "LinkShell:iPhone から Codex を追い、承認し、指示を送る",
},
}
APP_DESCRIPTION = {
"zh": "在手机上关注、审批和指挥电脑上运行的编程 Agent(Claude Code、Codex、Gemini CLI、GitHub Copilot 等),并提供远程桌面、终端和本地网页预览。端到端加密,可自建网关。",
"en": "Follow, steer and approve the coding agents running on your computer (Claude Code, Codex, Gemini CLI, GitHub Copilot and more) from your phone, with remote desktop control, a terminal and local web previews. End-to-end encrypted, with a self-hostable gateway.",
"ja": "パソコンで動くコーディングエージェント(Claude Code、Codex、Gemini CLI、GitHub Copilot など)を、スマートフォンから追い、承認し、指示を送れます。Mac のリモートデスクトップ、ターミナル、ローカル Web のプレビューにも対応。通信はエンドツーエンドで暗号化され、ゲートウェイはセルフホストできます。",
}
CRUMB = {
"zh": {"home": "首页", "docs": "文档", "pricing": "定价", "claude-code": "Claude Code", "codex": "Codex"},
"en": {"home": "Home", "docs": "Docs", "pricing": "Pricing", "claude-code": "Claude Code", "codex": "Codex"},
# Japanese has no home page of its own: the crumb leads to the English one, by name.
"ja": {"home": "LinkShell", "claude-code": "Claude Code", "codex": "Codex"},
}
FILM = {
# The cuts' first publication (git history) and their length (49.9 s).
"zh": {"name": "LinkShell 介绍片", "video": "assets/promo/linkshell-2.0.mp4", "still": "assets/promo/film.jpg", "uploaded": "2026-09-30T22:36:03-07:00"},
"en": {"name": "LinkShell film", "video": "assets/promo/linkshell-en.mp4", "still": "assets/promo/film-en.jpg", "uploaded": "2026-10-20T05:29:57+08:00"},
}
THEME_LABEL = {"zh": "切换浅色或深色模式", "en": "Toggle light / dark", "ja": "ライトモードとダークモードを切り替え"}
CJK = re.compile(r"[ -鿿-]")
KANA = re.compile(r"[-ヿ]")
LANG_TAG = re.compile(r'<(/?)(span|a)(?=[\s>])([^>]*)>')
RAW = re.compile(r"(")
return "\n".join(" " + line for line in lines) + "\n"
def build(source: str, lang: str, view: str) -> str:
page = source
# One view per address.
for other in VIEWS:
if other != view:
# (The landing views sit last, so dropping them leaves the gap before the footer as it was.)
page = replace_one(r'\n \n .*?\n \n' % (other.upper(), other), "" if other in LANDING else "\n", page, re.S)
page = page.replace(f'', f'')
# Styles a view keeps to itself, so the other pages stay as they are.
def scoped(match: re.Match) -> str:
return match.group(0).replace(match.group(1), "") if view in match.group(2).split() else ""
page = re.sub(r' \n', scoped, page, flags=re.S)
if view != "home":
# The iPhone Duo viewer lives on the home page only.
page = replace_one(r' \n', "", page)
page = replace_one(r' \n', "", page)
# One language per address.
page = pick_language(page, lang)
page = pick_attributes(page, lang)
page = page.replace('aria-label="Toggle light / dark"', f'aria-label="{THEME_LABEL[lang]}"')
if lang != "zh":
# English stills (Japanese pages have none of their own).
page = re.sub(r'(src|srcset)="([^"]*)" data-en="([^"]*)"', r'\1="\3"', page)
page = page.replace(APP_STORE, APP_STORE_ANY)
else:
page = re.sub(r' data-en="[^"]*"', "", page)
# Rewrite all internal page links to root-relative paths (/docs/, /en/docs/, ...) so
# crawlers that ignore cannot walk into recursive paths like /docs/claude-code/docs/...
targets = {path or "./": name for name, path in VIEWS.items()}
pattern = "|".join(re.escape(path) for path in sorted(targets, key=len, reverse=True))
page = re.sub(
r'href="(%s)' % pattern,
lambda m: 'href="/' + LANGS[written_in(lang, targets[m.group(1)])]["prefix"] + ("" if m.group(1) == "./" else m.group(1)),
page,
)
page = page.replace('href="assets/', 'href="/assets/')
page = page.replace('href="site.webmanifest"', 'href="/site.webmanifest"')
# Every page links the other of Chinese and English (a Japanese page: English); a view with
# Japanese links its third language too, a switch that gives way on narrow screens.
other = "en" if lang == "zh" else "zh"
first = "en" if lang == "ja" else other
switches = [first] + [code for code in others(lang, view) if code != first]
def switch(code: str, primary: bool) -> str:
names = 'class="lang-switch" id="lang-toggle"' if primary else 'class="lang-switch lang-more"'
html_lang = LANGS[code]["html"]
return f'{SWITCH_LABEL[code]}'
page = replace_one(
r'[^<]*',
"".join(switch(code, i == 0) for i, code in enumerate(switches)),
page,
)
depth = (LANGS[lang]["prefix"] + VIEWS[view]).count("/")
# data-alt is where a visitor who chose the first switch's language goes; data-alt-
# names a view's other languages (Japanese, or Chinese from a Japanese page).
extra = "".join(f' data-alt-{code}="{rel(code, view)}"' for code in switches[1:])
page = replace_one(
r'',
f'',
page,
)
if depth:
page = replace_one(r'', '\n ', page)
page = replace_one(r" \n", head(lang, view, page), page, re.S)
# GitHub Pages keeps publishing docs/site for install.sh and the desktop update feeds but cannot
# send a 301, so a page opened there moves the visitor to the site's own host.
page = replace_one(r'', '\n ' + GITHUB_PAGES_REDIRECT, page)
return page
NOT_FOUND = """
{redirect}
页面不存在 · Page not found | LinkShell
页面不存在 · Page not found
这个地址没有内容,可能已经移动。
Nothing lives at this address; it may have moved.
"""
def page_images(page: str, lang: str) -> list:
"""The page's share image and the content images it shows, against the site root."""
found = [LANGS[lang]["og_image"]]
for src in re.findall(r']*?\ssrc="(assets/[^"?#]+)"', page):
if src not in found and not src.startswith("assets/duo/"):
found.append(src)
return found
def main() -> None:
source = (SITE / "index.src.html").read_text(encoding="utf-8")
mobile = json.loads((SITE / "mobile-release.json").read_text(encoding="utf-8"))
version = mobile["version"]
if not re.fullmatch(r"\d+\.\d+\.\d+", version):
raise SystemExit("invalid mobile release version")
source = source.replace("{{ANDROID_APK}}", f"{GITHUB}/releases/download/v{version}/LinkShell-{version}.apk")
sitemap = SITE / "sitemap.xml"
previous = dict(re.findall(r"([^<]*).*?([^<]*)", sitemap.read_text(encoding="utf-8"), re.S)) if sitemap.exists() else {}
today = datetime.date.today().isoformat()
entries = []
for view in VIEWS:
for lang in VIEW_LANGS[view]:
out = SITE / (LANGS[lang]["prefix"] + VIEWS[view]) / "index.html"
page = build(source, lang, view)
unchanged = out.exists() and out.read_text(encoding="utf-8") == page
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(page, encoding="utf-8")
print(f"wrote {out.relative_to(SITE.parent.parent)}")
# A page keeps its date until its content changes.
entries.append((url(lang, view), previous.get(url(lang, view)) if unchanged and url(lang, view) in previous else today, view, page_images(page, lang)))
alternates = lambda view: "".join(
f'\n '
for code, lang in [(LANGS[lang]["html"], lang) for lang in VIEW_LANGS[view]] + [("x-default", VIEW_LANGS[view][0])]
)
images = lambda found: "".join(f"\n {BASE + src}" for src in found)
body = "".join(f" \n {loc}\n {mod}{images(found)}{alternates(view)}\n \n" for loc, mod, view, found in entries)
sitemap.write_text(
'\n'
'\n'
f"{body}\n",
encoding="utf-8",
)
print(f"wrote {sitemap.relative_to(SITE.parent.parent)} ({len(entries)} pages)")
(SITE / "404.html").write_text(NOT_FOUND.replace("{redirect}", GITHUB_PAGES_REDIRECT), encoding="utf-8")
print("wrote docs/site/404.html")
if __name__ == "__main__":
main()