mirror of
https://github.com/docsifyjs/docsify.git
synced 2026-10-18 21:21:27 +08:00
136e666e78
* develop: (104 commits) chore: bump ssri from 6.0.1 to 6.0.2 (#1563) chore: Update Edit Document using develop branch (#1541) fix: Add escapeHtml for search (#1551) docs: link with plugin Pagination (#1554) fix: Upgrade dompurify from 2.2.6 to 2.2.7 (#1553) fix: upgrade dompurify from 2.2.6 to 2.2.7 (#1552) chore: bump y18n from 4.0.0 to 4.0.1 (#1548) chore: Fix search for missing pathNamespaces (#1547) fix: Upgrade docsify from 4.12.0 to 4.12.1 (#1544) docs:Update deploy, change Zeit to Vercel (#1540) fix: Cannot read property 'classList' of null (#1527) chore: fix microsoft/playwright-github-action error (#1534) Update PULL_REQUEST_TEMPLATE.md chore: Update CHANGELOG and Update test snapshots chore: add changelog 4.12.1 [build] 4.12.1 feat: Support search when there is no title (#1519) test(unit): add test cases on isExternal. (#1515) docs: Update Vercel logo link (#1520) fix: Upgrade docsify from 4.11.6 to 4.12.0 (#1518) ...
112 lines
2.8 KiB
JavaScript
112 lines
2.8 KiB
JavaScript
import path from 'path';
|
|
import browserSyncModule from 'browser-sync';
|
|
import esMain from 'es-main';
|
|
|
|
const browserSync = browserSyncModule.create();
|
|
const hasStartArg = process.argv.includes('--start');
|
|
const dirname = path.dirname(import.meta.url.replace('file://', ''));
|
|
|
|
const serverConfig = {
|
|
host: '127.0.0.1',
|
|
port: 3001,
|
|
};
|
|
|
|
export function startServer(options = {}, cb = Function.prototype) {
|
|
const defaults = {
|
|
...serverConfig,
|
|
middleware: [
|
|
{
|
|
route: '/_blank.html',
|
|
handle: function (req, res, next) {
|
|
res.setHeader('Content-Type', 'text/html');
|
|
res.end('');
|
|
next();
|
|
},
|
|
},
|
|
],
|
|
notify: false,
|
|
open: false,
|
|
rewriteRules: [
|
|
// Replace docsify-related CDN URLs with local paths
|
|
{
|
|
match: /(https?:)?\/\/cdn\.jsdelivr\.net\/npm\/docsify(@\d?\.?\d?\.?\d)?\/lib\//g,
|
|
replace: '/lib/',
|
|
},
|
|
],
|
|
server: {
|
|
baseDir: path.resolve(dirname, '../'),
|
|
routes: {
|
|
'/docs': path.resolve(dirname, '../../docs'),
|
|
'/docs/changelog.md': './CHANGELOG.md',
|
|
'/lib': path.resolve(dirname, '../../lib'),
|
|
'/node_modules': path.resolve(dirname, '../../node_modules'),
|
|
},
|
|
},
|
|
snippetOptions: {
|
|
rule: {
|
|
match: /<\/body>/i,
|
|
fn: function (snippet, match) {
|
|
// Override changelog alias to load local changelog (see routes)
|
|
const injectJS = `
|
|
<script>
|
|
// Fix /docs site configuration during tests
|
|
(function() {
|
|
const aliasConfig = (window && window.$docsify && window.$docsify.alias) || {};
|
|
|
|
aliasConfig['.*?/changelog'] = '/changelog.md';
|
|
})();
|
|
</script>
|
|
`;
|
|
|
|
return injectJS + snippet + match;
|
|
},
|
|
},
|
|
},
|
|
ui: false,
|
|
};
|
|
|
|
console.log('\n');
|
|
|
|
browserSync.init(
|
|
// Config
|
|
{
|
|
...defaults,
|
|
...options,
|
|
},
|
|
// Callback
|
|
cb
|
|
);
|
|
}
|
|
|
|
export async function startServerAsync() {
|
|
await new Promise(resolve => {
|
|
startServer({}, () => {
|
|
console.log('\n');
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
export function stopServer() {
|
|
browserSync.exit();
|
|
}
|
|
|
|
const isTopLevelModule = esMain(import.meta);
|
|
|
|
// Allow starting the test server from the CLI. Useful for viewing test content
|
|
// like fixtures (/index.html)) and local docs site (/docs) used for testing.
|
|
if (hasStartArg) {
|
|
startServer({
|
|
open: true,
|
|
port: serverConfig.port + 1,
|
|
directory: true,
|
|
startPath: '/docs',
|
|
});
|
|
}
|
|
// Display friendly message about manually starting a server instance
|
|
else if (isTopLevelModule) {
|
|
console.info('Use the --start argument to manually start server instance');
|
|
}
|
|
|
|
export const TEST_HOST = `http://${serverConfig.host}:${serverConfig.port}`;
|