From 64e92c769d46dfc8aa8ad5d9a3755023ebd4ee5d Mon Sep 17 00:00:00 2001 From: yoge Date: Tue, 24 Mar 2026 23:50:12 +0800 Subject: [PATCH] feat: optimize SEO based on GSC data - Fix broken hreflang: /en/ ghost page removed, all hreflang point to canonical / - Add canonical URL tag - Remove emoji from page titles - Rewrite title/description with target keywords (LaTeX OCR, math formula recognition, handwriting math) - Add JSON-LD WebApplication structured data schema - Update og:image to clean URL without OSS params, add og:image dimensions - Fix favicon reference from vite.svg to favicon.png - Add public/sitemap.xml with hreflang annotations - Add public/robots.txt pointing to sitemap - Update seoHelper.ts keywords for both zh/en to match search intent - Add CLAUDE.md project documentation --- CLAUDE.md | 76 ++++++++++++++++++++++++++++++++++++ index.html | 92 ++++++++++++++++++++++++++++++-------------- public/robots.txt | 4 ++ public/sitemap.xml | 13 +++++++ src/lib/seoHelper.ts | 12 +++--- 5 files changed, 162 insertions(+), 35 deletions(-) create mode 100644 CLAUDE.md create mode 100644 public/robots.txt create mode 100644 public/sitemap.xml diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..90799e3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,76 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Commands + +```bash +# Development server +npm run dev + +# Build +npm run build # production +npm run build:dev # development build (VITE_ENV=development) +npm run build:prod # production build (VITE_ENV=production) + +# Type checking +npm run typecheck + +# Linting +npm run lint + +# Unit tests (vitest) +npm run test # run once +npm run test:watch # watch mode + +# E2E tests (playwright) +npm run test:e2e +``` + +To run a single unit test file: +```bash +npx vitest run src/components/__tests__/AuthModal.test.tsx +``` + +## Architecture + +### Provider Tree +`main.tsx` wraps everything in: `BrowserRouter → AuthProvider → LanguageProvider → AppRouter` + +### Routing +Only two routes (`src/routes/AppRouter.tsx`): +- `/` → `App` (main app) +- `/auth/google/callback` → `AuthCallbackPage` (Google OAuth callback handler) + +### Auth System +- **`AuthContext.tsx`** — React context providing `signIn`, `signUp`, `beginGoogleOAuth`, `completeGoogleOAuth`, `signOut`. Uses `useReducer` with `authMachine.ts`. +- **`authMachine.ts`** — Pure reducer + state types (`AuthPhase`, `AuthState`, `AuthAction`). No side effects — all async logic lives in `AuthContext`. +- **`authService.ts`** — Calls backend API for login/register/Google OAuth/user info. Decodes JWT payload client-side to extract `UserInfo`. Handles session restore from `localStorage`. +- **`lib/api.ts`** — `http` client wrapper with `tokenManager` (stores JWT in `localStorage` under key `texpixel_token`). Adds `Authorization` header automatically. Throws `ApiError` for non-success business codes. + +### Environment / API +- **`src/config/env.ts`** — Switches API base URL based on `VITE_ENV` env var: + - `development`: `https://cloud.texpixel.com:10443/doc_ai/v1` + - `production`: `https://api.texpixel.com/doc_ai/v1` +- The API uses a custom response envelope: `{ request_id, code, message, data }`. Success is `code === 200` (some endpoints also accept `0`). + +### Main App Flow (`App.tsx`) +Three-panel layout: `LeftSidebar | FilePreview | ResultPanel` + +Core data flow: +1. On auth, `loadFiles()` fetches paginated task history from `/task/list` +2. File upload goes: compute MD5 → get OSS pre-signed URL (`/oss/signature_url`) → PUT to OSS → create task (`/formula/recognition`) → poll every 2s for result +3. Results cached in `resultsCache` ref (keyed by `task_id`) to avoid redundant API calls +4. Guest users get 3 free uploads tracked via `localStorage` (`texpixel_guest_usage_count`) + +### Internationalization +`LanguageContext.tsx` supports `en` / `zh`. Language is auto-detected via IP (`lib/ipLocation.ts`) on first visit, persisted to `localStorage` on manual switch. All UI strings come from `lib/translations.ts` via `const { t } = useLanguage()`. + +### Key Type Definitions +- `src/types/api.ts` — All API request/response types, `TaskStatus` enum, `ApiErrorCode` enum, `ApiErrorMessages` map +- `src/types/index.ts` — Internal app types (`FileRecord`, `RecognitionResult`) + +### Tests +- Unit tests: `src/components/__tests__/` and `src/contexts/__tests__/`, run with vitest + jsdom + `@testing-library/react` +- E2E tests: `e2e/` directory, run with Playwright +- Setup file: `src/test/setup.ts` diff --git a/index.html b/index.html index 8c623d6..f8d3b97 100644 --- a/index.html +++ b/index.html @@ -3,56 +3,90 @@ - + - - - - - - - - ⚡️ TexPixel - 公式识别工具 | Formula Recognition Tool - - - + + + + + + + + TexPixel - AI Math Formula Recognition | LaTeX, MathML OCR Tool + + + + - - - + + + - - - + + + + + - + - - - + + + + + + @@ -64,4 +98,4 @@ - \ No newline at end of file + diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..a40ec7f --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://texpixel.com/sitemap.xml diff --git a/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 0000000..9bb6be2 --- /dev/null +++ b/public/sitemap.xml @@ -0,0 +1,13 @@ + + + + https://texpixel.com/ + 2026-03-11 + weekly + 1.0 + + + + + diff --git a/src/lib/seoHelper.ts b/src/lib/seoHelper.ts index 65392a4..1791d10 100644 --- a/src/lib/seoHelper.ts +++ b/src/lib/seoHelper.ts @@ -8,14 +8,14 @@ interface SEOContent { const seoContent: Record = { zh: { - title: '⚡️ TexPixel - 公式识别工具', - description: '在线公式识别工具,支持印刷体和手写体数学公式识别,快速准确地将图片中的数学公式转换为可编辑文本。', - keywords: '公式识别,数学公式,OCR,手写公式识别,印刷体识别,AI识别,数学工具,免费,混合文字识别,texpixel,TexPixel', + title: 'TexPixel - AI 数学公式识别工具 | LaTeX、MathML OCR', + description: '免费 AI 数学公式识别工具,支持手写和印刷体公式识别,一键将图片或 PDF 中的数学公式转换为 LaTeX、MathML 和 Markdown 格式。', + keywords: '数学公式识别,LaTeX OCR,手写公式识别,公式转LaTeX,数学OCR,MathML转换,手写方程识别,公式识别,数学公式OCR,texpixel', }, en: { - title: '⚡️ TexPixel - Formula Recognition Tool', - description: 'Online formula recognition tool supporting printed and handwritten math formulas. Convert images to LaTeX, MathML, and Markdown quickly and accurately.', - keywords: 'formula recognition,math formula,OCR,handwriting recognition,latex,mathml,markdown,AI recognition,math tool,free,texpixel,TexPixel,document recognition', + title: 'TexPixel - AI Math Formula Recognition | LaTeX, MathML OCR Tool', + description: 'Free AI-powered math formula recognition tool. Convert handwritten or printed math formulas in images to LaTeX, MathML, and Markdown instantly. Supports PDF and image files.', + keywords: 'math formula recognition,LaTeX OCR,handwriting math recognition,formula to latex,math OCR,MathML converter,handwritten equation recognition,texpixel', }, };