Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update local and Vercel preview. Fix CSS watch functionality. (#…
- Loading branch information
1 parent
25e715b
commit 167596b
Showing
10 changed files
with
106 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Exports | ||
// ============================================================================= | ||
export const config = { | ||
matcher: ['/preview/(index.html)?'], | ||
}; | ||
|
||
// Rewrite rules shared with local server configurations | ||
export const rewriteRules = [ | ||
// Replace CDN URLs with local paths | ||
{ | ||
match: /https?.*\/CHANGELOG.md/g, | ||
replace: '/CHANGELOG.md', | ||
}, | ||
{ | ||
// CDN versioned default | ||
// Ex1: //cdn.com/package-name | ||
// Ex2: http://cdn.com/package-name@1.0.0 | ||
// Ex3: https://cdn.com/package-name@latest | ||
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*(?=["'])/g, | ||
replace: '/lib/docsify.min.js', | ||
}, | ||
{ | ||
// CDN paths to local paths | ||
// Ex1: //cdn.com/package-name/path/file.js => /path/file.js | ||
// Ex2: http://cdn.com/package-name@1.0.0/dist/file.js => /dist/file.js | ||
// Ex3: https://cdn.com/package-name@latest/dist/file.js => /dist/file.js | ||
match: /(?:https?:)*\/\/.*cdn.*docsify[@\d.latest]*\/(?:lib\/)/g, | ||
replace: '/lib/', | ||
}, | ||
]; | ||
|
||
// Serve virtual /preview/index.html | ||
// Note: See vercel.json for preview routing configuration | ||
// 1. Fetch index.html from /docs/ directory | ||
// 2. Replace CDN URLs with local paths (see rewriteRules) | ||
// 3. Return preview HTML | ||
export default async function middleware(request) { | ||
const { origin } = new URL(request.url); | ||
const indexURL = `${origin}/docs/index.html`; | ||
const indexHTML = await fetch(indexURL).then(res => res.text()); | ||
const previewHTML = rewriteRules.reduce( | ||
(html, rule) => html.replace(rule.match, rule.replace), | ||
indexHTML | ||
); | ||
|
||
return new Response(previewHTML, { | ||
status: 200, | ||
headers: { | ||
'content-type': 'text/html', | ||
'x-robots-tag': 'noindex', | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { create } from 'browser-sync'; | ||
import serverConfigs from './server.config.js'; | ||
import { devConfig, prodConfig } from './server.configs.js'; | ||
|
||
const bsServer = create(); | ||
const args = process.argv.slice(2); | ||
const configName = | ||
Object.keys(serverConfigs).find(name => args.includes(`--${name}`)) || 'prod'; | ||
const settings = serverConfigs[configName]; | ||
const config = args.includes('--dev') ? devConfig : prodConfig; | ||
const configName = config === devConfig ? 'development' : 'production'; | ||
const isWatch = Boolean(config.files) && config.watch !== false; | ||
const urlType = config === devConfig ? 'local' : 'CDN'; | ||
|
||
// prettier-ignore | ||
console.log(`\nStarting ${configName} server (${settings.server.index}, watch: ${Boolean(settings.files)})\n`); | ||
console.log(`\nStarting ${configName} server (${urlType} URLs, watch: ${isWatch})\n`); | ||
|
||
bsServer.init(settings); | ||
bsServer.init(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
{ | ||
"redirects": [ | ||
"headers": [ | ||
{ | ||
"source": "/", | ||
"destination": "./docs/preview.html", | ||
"permanent": true | ||
"source": "/(.*)", | ||
"headers": [{ "key": "x-robots-tag", "value": "noindex" }] | ||
} | ||
], | ||
"redirects": [{ "source": "/", "destination": "/preview/" }], | ||
"rewrites": [ | ||
{ "source": "/preview/CHANGELOG.md", "destination": "/CHANGELOG.md" }, | ||
{ "source": "/preview/:path*", "destination": "/docs/:path*" } | ||
] | ||
} |
167596b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docsify-preview – ./
docsify-preview.vercel.app
docsify-preview-git-develop-docsifyjs.vercel.app
www.docsifyjs.org
docsify-preview-docsifyjs.vercel.app
docsifyjs.org