diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 38ecdb0..140d7eb 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -9,7 +9,9 @@ - Output directory: `dist` - Production branch: `main` - Automatic Production deployments: disabled -- Custom domains / DNS: none +- GitHub Pages environment URL: `http://ocodejs.co/docs.rtf/` (from the successful Pages deployment log). +- The frontend detects the `/docs.rtf` base path on `ocodejs.co`; Cloudflare Preview remains rooted at `/`. +- Custom domains / DNS: none changed by this project. ## Build output @@ -18,3 +20,5 @@ The build validates `index.html` and `studio.html`, then publishes only those tw ## Product boundaries This repository currently contains a static frontend prototype. Authentication, contact submission, student data, course purchases, and checkout are demonstrations only. No real payment or account operation is performed. Production launch requires backend integration, security review, privacy/legal review, and explicit production approval. + +The `fix/github-pages-subpath-routing` branch is also included in Preview builds so the `/docs.rtf` path fix can be tested before any further GitHub Pages release. diff --git a/README-IMPLEMENTATION.md b/README-IMPLEMENTATION.md index 74c732c..2066f36 100644 --- a/README-IMPLEMENTATION.md +++ b/README-IMPLEMENTATION.md @@ -20,7 +20,7 @@ npx serve dist - Build Cloudflare chỉ xuất bản `index.html`, `studio.html` và metadata; Pages tự động fallback về `index.html` cho route SPA khi không có `404.html`. GitHub Pages workflow tạo riêng `404.html` sau bước build. - `_redirects` hỗ trợ refresh các SPA route; `404.html` dùng app shell để router xử lý route trực tiếp. - `_headers` ngăn index bản preview. -- GitHub Pages dùng workflow `.github/workflows/pages.yml` làm pipeline tự động duy nhất khi có thay đổi trên `main`. Các workflow `static.yml`, `jekyll-gh-pages.yml` và `jekyll.yml` là legacy/manual-only để tránh nhiều workflow ghi đè cùng Pages deployment. +- GitHub Pages dùng workflow `.github/workflows/pages.yml` làm pipeline tự động duy nhất khi có thay đổi trên `main`. Frontend tự nhận diện base path `/docs.rtf` trên `ocodejs.co`, còn Cloudflare Preview chạy ở root. Các workflow `static.yml`, `jekyll-gh-pages.yml` và `jekyll.yml` là legacy/manual-only để tránh nhiều workflow ghi đè cùng Pages deployment. - Không tự bật domain riêng hoặc Production trong cấu hình staging. ## Phạm vi hiện tại diff --git a/index.html b/index.html index 2c5e83d..b86943a 100644 --- a/index.html +++ b/index.html @@ -66,17 +66,19 @@ color:#08090b !important; border-color:#e9edf5 !important; } -
OCODEJS LEARNING PLATFORM / BUILD YOUR CAREERHỌC THẬT · LÀM THẬT · PHÁT TRIỂN BỀN VỮNG
\ No newline at end of file diff --git a/package.json b/package.json index e68860c..5ff2b18 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "version": "0.1.0", "type": "module", "scripts": { - "build": "node scripts/build-site.mjs" + "build": "npm test && node scripts/build-site.mjs", + "test": "node --test scripts/base-path.test.mjs" }, "engines": { "node": ">=20" diff --git a/scripts/base-path.mjs b/scripts/base-path.mjs new file mode 100644 index 0000000..457712f --- /dev/null +++ b/scripts/base-path.mjs @@ -0,0 +1,22 @@ +export function createBasePathTools(hostname, pathname) { + const isDocsPagesHost = hostname === "ocodejs.co"; + const isDocsSubpath = pathname === "/docs.rtf" || pathname.startsWith("/docs.rtf/"); + const basePath = isDocsPagesHost && isDocsSubpath ? "/docs.rtf" : ""; + + function appPath(path) { + if (!basePath) return path; + if (path === "/") return basePath + "/"; + return basePath + (path.startsWith("/") ? path : "/" + path); + } + + function applyBaseLinks(root = document) { + if (!basePath) return; + root.querySelectorAll('a[href^="/"]').forEach(anchor => { + const href = anchor.getAttribute("href"); + if (href === basePath || href.startsWith(basePath + "/")) return; + anchor.setAttribute("href", appPath(href)); + }); + } + + return { basePath, appPath, applyBaseLinks }; +} diff --git a/scripts/base-path.test.mjs b/scripts/base-path.test.mjs new file mode 100644 index 0000000..5711d8b --- /dev/null +++ b/scripts/base-path.test.mjs @@ -0,0 +1,62 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { createBasePathTools } from "./base-path.mjs"; + +function fakeRoot(hrefs) { + const anchors = hrefs.map(href => ({ + href, + getAttribute(name) { return name === "href" ? this.href : null; }, + setAttribute(name, value) { if (name === "href") this.href = value; } + })); + return { + anchors, + querySelectorAll(selector) { + assert.equal(selector, 'a[href^="/"]'); + return anchors.filter(anchor => anchor.href.startsWith("/")); + } + }; +} + +test("GitHub Pages docs subpath is detected only inside /docs.rtf", () => { + assert.equal(createBasePathTools("ocodejs.co", "/docs.rtf/").basePath, "/docs.rtf"); + assert.equal(createBasePathTools("ocodejs.co", "/docs.rtf/kham-pha").basePath, "/docs.rtf"); + assert.equal(createBasePathTools("ocodejs.co", "/studio.html").basePath, ""); + assert.equal(createBasePathTools("preview.pages.dev", "/").basePath, ""); +}); + +test("client navigation preserves the docs base path", () => { + const { appPath } = createBasePathTools("ocodejs.co", "/docs.rtf/"); + assert.equal(appPath("/"), "/docs.rtf/"); + assert.equal(appPath("/kham-pha"), "/docs.rtf/kham-pha"); + assert.equal(appPath("studio.html"), "/docs.rtf/studio.html"); +}); + +test("base path rewrites dynamically generated course-card anchors", () => { + const { applyBaseLinks } = createBasePathTools("ocodejs.co", "/docs.rtf/kham-pha"); + const root = fakeRoot(["/khoa-hoc/js-core", "/studio.html", "/docs.rtf/khoa-hoc/already-prefixed", "https://example.com"]); + applyBaseLinks(root); + assert.deepEqual(root.anchors.map(anchor => anchor.href), [ + "/docs.rtf/khoa-hoc/js-core", + "/docs.rtf/studio.html", + "/docs.rtf/khoa-hoc/already-prefixed", + "https://example.com" + ]); +}); + +test("root deployment on ocodejs.co does not force docs subpath", () => { + const { basePath, appPath } = createBasePathTools("ocodejs.co", "/studio.html"); + assert.equal(basePath, ""); + assert.equal(appPath("/"), "/"); + const root = fakeRoot(["/studio.html"]); + createBasePathTools("ocodejs.co", "/studio.html").applyBaseLinks(root); + assert.equal(root.anchors[0].href, "/studio.html"); +}); + +test("Cloudflare Preview remains rooted and does not rewrite links", () => { + const { basePath, appPath, applyBaseLinks } = createBasePathTools("fix-preview.pages.dev", "/kham-pha"); + assert.equal(basePath, ""); + assert.equal(appPath("/kham-pha"), "/kham-pha"); + const root = fakeRoot(["/studio.html"]); + applyBaseLinks(root); + assert.equal(root.anchors[0].href, "/studio.html"); +}); diff --git a/scripts/build-site.mjs b/scripts/build-site.mjs index eb99067..a140c47 100644 --- a/scripts/build-site.mjs +++ b/scripts/build-site.mjs @@ -4,6 +4,7 @@ import { resolve } from "node:path"; const root = process.cwd(); const output = resolve(root, "dist"); const required = ["index.html", "studio.html"]; +const browserHelpers = ["scripts/base-path.mjs"]; for (const file of required) { const source = await readFile(resolve(root, file), "utf8"); @@ -27,6 +28,8 @@ for (const file of required) { await rm(output, { recursive: true, force: true }); await mkdir(output, { recursive: true }); for (const file of required) await cp(resolve(root, file), resolve(output, file)); +await mkdir(resolve(output, "scripts"), { recursive: true }); +for (const file of browserHelpers) await cp(resolve(root, file), resolve(output, file)); // Cloudflare Pages automatically serves index.html for unmatched routes when // no top-level 404.html is present. GitHub Pages gets its own 404 fallback // in the Pages workflow after this build command. diff --git a/studio.html b/studio.html index ab02e0a..fa6e9bb 100644 --- a/studio.html +++ b/studio.html @@ -31,7 +31,10 @@ }
OCODEJS / AI STUDIO
STUDIO PREVIEWReact · Next.js · Tailwind · shadcn/ui← Website
OCODEJS INTELLIGENCE / PRODUCT STUDIO

Biến ý tưởng thành
sản phẩm thực tế.

Trợ lý AI lập trình và thiết kế giao diện do OCodeJS phát triển. Mô tả bằng văn bản, đưa ảnh tham chiếu hoặc nhập liên kết Figma để bắt đầu.

Tiếng Việt · English
Thêm ảnh giao diện hoặc screenshot để AI phân tích layout, màu sắc và component.PNG · JPG · WEBP
Responsive UITypeScriptAccessibleDark modeReusable components

Bản hiện tại là giao diện prototype. Kết quả mẫu được tạo cục bộ; cần kết nối inference API để gọi Agents Mini / Pro / Max thực sự.

🔒 Không gửi ảnh, prompt hay Figma URL tới máy chủ trong bản preview này. Chưa có xác thực, lưu dự án hoặc đồng bộ GitHub thật.
LIVE PREVIEW
NORTHSTAROverview  Products  PricingSign in
DESIGNED TO MOVE YOU FORWARD

Your next big idea
starts right here.

A clean, responsive interface generated with OCodeJS Studio.

Get started →
◈Build fasterReusable UI blocks
⌘Ship confidentlyTyped components
↗Scale furtherModern workflow
Preview mẫu · Chưa kết nối AI inference
app/page.tsx
// Your generated source code will appear here.
-// Enter a prompt and select Generate to create a local UI starter.
GitHub sync và terminal export là điểm tích hợp dự kiến; chưa cấp quyền repository hoặc chạy lệnh từ trình duyệt.