Skip to content

Commit 6af0485

Browse files
committed
docs(site): point install URLs at the deploy origin on preview builds
Preview deploys (main.viteplus.dev, PR staging) serve their own install scripts, but the docs hardcode the production https://vite.plus shortcuts. The deploy-docs composite now passes a site-origin input to the build as DOCS_SITE_ORIGIN. When set, a markdown-it rule rewrites the install URLs in markdown content, and the homepage install command and AI copy prompt read __DOCS_*__ define constants from the same origin (including the llms-full.txt link). The build:site task tracks the variable in env so each deploy target keeps its own Vite Task cache entry. Production builds are unchanged. Known gap: the llms dumps copy raw markdown and keep production URLs on previews.
1 parent 3dfbee2 commit 6af0485

9 files changed

Lines changed: 109 additions & 7 deletions

File tree

.github/actions/deploy-docs/action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ inputs:
2222
description: 'Commit sha that scopes the primary cache key.'
2323
required: false
2424
default: ${{ github.sha }}
25+
site-origin:
26+
description: >-
27+
Origin of this deploy when it is not production viteplus.dev
28+
(e.g. https://main.viteplus.dev). When set, the docs build rewrites the
29+
https://vite.plus installer URLs to this origin's install scripts.
30+
Leave empty for production.
31+
required: false
32+
default: ''
2533

2634
runs:
2735
using: 'composite'
@@ -62,6 +70,8 @@ runs:
6270
- run: vp run build
6371
shell: bash
6472
working-directory: docs
73+
env:
74+
DOCS_SITE_ORIGIN: ${{ inputs.site-origin }}
6575

6676
- name: Save docs Vite Task cache
6777
if: success() && steps.vite-task-cache.outputs.cache-hit != 'true'

.github/workflows/deploy-docs-main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ jobs:
3737
with:
3838
void-project: viteplus-main
3939
void-token: ${{ secrets.VOID_TOKEN }}
40+
site-origin: https://main.viteplus.dev

.github/workflows/deploy-docs-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
void-token: ${{ secrets.VOID_TOKEN }}
4040
cache-ref: pr-${{ github.event.pull_request.number }}
4141
cache-sha: ${{ github.event.pull_request.head.sha }}
42+
site-origin: https://viteplus-staging.void.app
4243

4344
- name: Comment on PR
4445
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9

docs/.vitepress/config.mts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-i
77
import llmstxt from 'vitepress-plugin-llms';
88
import { withMermaid } from 'vitepress-plugin-mermaid';
99

10+
// Non-production deploys (the main preview, PR staging) serve their own
11+
// copies of the install scripts and llms dumps, so the https://vite.plus
12+
// installer shortcuts and absolute site URLs must point at the deploy's
13+
// origin instead of production. The deploy workflows set DOCS_SITE_ORIGIN via
14+
// the deploy-docs composite action; markdown content is rewritten through
15+
// markdown-it below, and Vue components read the __DOCS_*__ define constants.
16+
const siteOrigin = process.env.DOCS_SITE_ORIGIN;
17+
const docsOrigin = siteOrigin || 'https://viteplus.dev';
18+
const installShUrl = siteOrigin ? `${siteOrigin}/install.sh` : 'https://vite.plus';
19+
const installPs1Url = siteOrigin ? `${siteOrigin}/install.ps1` : 'https://vite.plus/ps1';
20+
21+
function rewriteInstallUrls(text: string): string {
22+
if (!siteOrigin) {
23+
return text;
24+
}
25+
return text
26+
.replaceAll('https://vite.plus/ps1', installPs1Url)
27+
.replaceAll('https://vite.plus', installShUrl);
28+
}
29+
1030
const taskRunnerGuideItems = [
1131
{
1232
text: 'Run',
@@ -113,6 +133,11 @@ export default extendConfig(
113133
['meta', { name: 'twitter:site', content: '@voidzerodev' }],
114134
],
115135
vite: {
136+
define: {
137+
__DOCS_ORIGIN__: JSON.stringify(docsOrigin),
138+
__DOCS_INSTALL_SH_URL__: JSON.stringify(installShUrl),
139+
__DOCS_INSTALL_PS1_URL__: JSON.stringify(installPs1Url),
140+
},
116141
optimizeDeps: {
117142
include: ['mermaid > @braintree/sanitize-url'],
118143
},
@@ -258,6 +283,31 @@ export default extendConfig(
258283
markdown: {
259284
config(md) {
260285
md.use(groupIconMdPlugin);
286+
if (siteOrigin) {
287+
md.core.ruler.push('rewrite-install-urls', (state) => {
288+
const walk = (tokens: typeof state.tokens) => {
289+
for (const token of tokens) {
290+
if (
291+
token.type === 'fence' ||
292+
token.type === 'code_inline' ||
293+
token.type === 'text'
294+
) {
295+
token.content = rewriteInstallUrls(token.content);
296+
}
297+
if (token.type === 'link_open') {
298+
const href = token.attrGet('href');
299+
if (href) {
300+
token.attrSet('href', rewriteInstallUrls(href));
301+
}
302+
}
303+
if (token.children) {
304+
walk(token.children);
305+
}
306+
}
307+
};
308+
walk(state.tokens);
309+
});
310+
}
261311
},
262312
},
263313
}),

docs/.vitepress/env.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Build-time constants injected via vite.define in config.mts. They point at
2+
// the current deploy's origin (production, main preview, or PR staging). The
3+
// dunder names follow the Vite convention for compile-time replaced globals.
4+
// oxlint-disable-next-line no-underscore-dangle
5+
declare const __DOCS_ORIGIN__: string;
6+
// oxlint-disable-next-line no-underscore-dangle
7+
declare const __DOCS_INSTALL_SH_URL__: string;
8+
// oxlint-disable-next-line no-underscore-dangle
9+
declare const __DOCS_INSTALL_PS1_URL__: string;
10+
111
// Vue SFC module declaration
212
declare module '*.vue' {
313
import type { DefineComponent } from 'vue';

docs/.vitepress/theme/components/CopyPrompt.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,28 @@ import { onBeforeUnmount, ref } from 'vue';
77
// live llms-full.txt docs dump.
88
const DEFAULT_PROMPT = `I want to use Vite+ in my project. Vite+ is the unified toolchain for the web behind the \`vp\` CLI — one tool combining Vite, Rolldown, Vitest, tsdown, Oxlint, Oxfmt, and Vite Task, plus runtime and package-manager management.
99
10-
First, read https://viteplus.dev/llms-full.txt to learn Vite+'s commands and configuration.
10+
First, read ${__DOCS_ORIGIN__}/llms-full.txt to learn Vite+'s commands and configuration.
1111
1212
Install the \`vp\` CLI if it's not already on the system:
13-
- macOS / Linux: curl -fsSL https://vite.plus | bash
14-
- Windows (PowerShell): irm https://vite.plus/ps1 | iex
13+
- macOS / Linux: curl -fsSL ${__DOCS_INSTALL_SH_URL__} | bash
14+
- Windows (PowerShell): irm ${__DOCS_INSTALL_PS1_URL__} | iex
1515
1616
Then open a new terminal and run \`vp help\`. To scaffold a new project run \`vp create\`; to move an existing Vite project onto Vite+ run \`vp migrate\`.
1717
1818
Day-to-day commands: \`vp install\` (dependencies), \`vp dev\` (dev server), \`vp check\` (format + lint + type-check), \`vp test\` (tests), and \`vp build\` (production build).
1919
2020
Help me get set up and explain anything I should know.`;
2121
22+
// DEFAULT_PROMPT interpolates the __DOCS_*__ define constants, so it is not a
23+
// static literal and cannot be a withDefaults() default (defineProps is
24+
// hoisted out of setup). Resolve the fallback at use sites instead.
2225
const props = withDefaults(
2326
defineProps<{
2427
prompt?: string;
2528
label?: string;
2629
}>(),
2730
{
28-
prompt: DEFAULT_PROMPT,
31+
prompt: '',
2932
label: 'Copy Prompt',
3033
},
3134
);
@@ -55,7 +58,7 @@ const copyPrompt = async (event: MouseEvent) => {
5558
(event.currentTarget as HTMLElement | null)?.blur();
5659
}
5760
try {
58-
await navigator.clipboard.writeText(props.prompt);
61+
await navigator.clipboard.writeText(props.prompt || DEFAULT_PROMPT);
5962
flash('copied');
6063
} catch {
6164
flash('error');

docs/.vitepress/theme/components/home/InstallCommand.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const commandCards: CommandCard[] = [
1212
{
1313
id: 'unix',
1414
label: 'macOS / Linux',
15-
command: 'curl -fsSL https://vite.plus | bash',
15+
command: `curl -fsSL ${__DOCS_INSTALL_SH_URL__} | bash`,
1616
},
1717
{
1818
id: 'windows',
1919
label: 'Windows (PowerShell)',
20-
command: 'irm https://vite.plus/ps1 | iex',
20+
command: `irm ${__DOCS_INSTALL_PS1_URL__} | iex`,
2121
},
2222
];
2323

docs/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export default {
33
tasks: {
44
'build:site': {
55
command: 'vitepress build',
6+
// The install-URL rewrite in .vitepress/config.mts depends on this
7+
// variable, so different deploy targets must not share cached output.
8+
env: ['DOCS_SITE_ORIGIN'],
69
input: [
710
{ auto: true },
811
'!.vitepress/.temp/**',

rfcs/deploy-docs-on-release.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,30 @@ jobs:
208208
target, and its PR comment step, and now runs the same composite. Per-PR
209209
staging deploys remain the place to review docs changes before merge.
210210

211+
### Origin-aware install URLs in the docs
212+
213+
The docs hardcode the production installer shortcuts (`https://vite.plus`,
214+
`https://vite.plus/ps1`) in markdown code blocks and in the homepage Vue
215+
components. A preview deploy must point them at its own install scripts
216+
instead (for example `https://main.viteplus.dev/install.sh`), or readers of
217+
unreleased install docs run the production installer.
218+
219+
The composite action passes its `site-origin` input to the docs build as
220+
`DOCS_SITE_ORIGIN`. When the variable is set:
221+
222+
- A markdown-it rule in `.vitepress/config.mts` rewrites the install URLs in
223+
fenced code, inline code, text, and link hrefs. Other `viteplus.dev`
224+
subdomains (`setup.`, `registry-bridge.`) stay untouched.
225+
- The Vue components (homepage install command, AI copy prompt) read
226+
`__DOCS_*__` define constants computed from the same origin. The AI prompt
227+
also points at the deploy's own `llms-full.txt`.
228+
- The `build:site` run task lists `DOCS_SITE_ORIGIN` in `env`, so each deploy
229+
target keeps its own Vite Task cache entry.
230+
231+
Production builds leave the content untouched: the variable is unset there.
232+
Known gap: the llms dumps (`llms.txt`, `llms-full.txt`, per-page `.md`) copy
233+
raw markdown, so on previews they keep the production install URLs.
234+
211235
### Manual deploys
212236

213237
`workflow_dispatch` covers urgent updates outside the release cycle:

0 commit comments

Comments
 (0)