(options = {}, cb = Function.prototype)
| 8 | }; |
| 9 | |
| 10 | function startServer(options = {}, cb = Function.prototype) { |
| 11 | const defaults = { |
| 12 | ...serverConfig, |
| 13 | middleware: [ |
| 14 | { |
| 15 | route: '/_blank.html', |
| 16 | handle: function (req, res, next) { |
| 17 | res.setHeader('Content-Type', 'text/html'); |
| 18 | res.end(''); |
| 19 | next(); |
| 20 | }, |
| 21 | }, |
| 22 | ], |
| 23 | notify: false, |
| 24 | open: false, |
| 25 | rewriteRules: [ |
| 26 | // Replace docsify-related CDN URLs with local paths |
| 27 | { |
| 28 | match: |
| 29 | /(https?:)?\/\/cdn\.jsdelivr\.net\/npm\/docsify(@\d?\.?\d?\.?\d)?\/lib\//g, |
| 30 | replace: '/lib/', |
| 31 | }, |
| 32 | ], |
| 33 | server: { |
| 34 | baseDir: path.resolve(__dirname, '../'), |
| 35 | routes: { |
| 36 | '/docs': path.resolve(__dirname, '../../docs'), |
| 37 | '/docs/changelog.md': './CHANGELOG.md', |
| 38 | '/lib': path.resolve(__dirname, '../../lib'), |
| 39 | '/node_modules': path.resolve(__dirname, '../../node_modules'), |
| 40 | }, |
| 41 | }, |
| 42 | snippetOptions: { |
| 43 | rule: { |
| 44 | match: /<\/body>/i, |
| 45 | fn: function (snippet, match) { |
| 46 | // Override changelog alias to load local changelog (see routes) |
| 47 | const newSnippet = ` |
| 48 | ${snippet.replace(/<script[^>]*/, '$& type="text/plain"')} |
| 49 | <script> |
| 50 | (function() { |
| 51 | var aliasConfig = (window && window.$docsify && window.$docsify.alias) || {}; |
| 52 | var isIE = /*@cc_on!@*/false || !!document.documentMode; |
| 53 | |
| 54 | // Fix /docs site configuration during tests |
| 55 | aliasConfig['.*?/changelog'] = '/changelog.md'; |
| 56 | |
| 57 | // Enable BrowserSync snippet for non-IE browsers |
| 58 | if (!isIE) { |
| 59 | document.querySelector('#__bs_script__').removeAttribute('type'); |
| 60 | } |
| 61 | })(); |
| 62 | </script> |
| 63 | ${match} |
| 64 | `; |
| 65 | |
| 66 | return newSnippet; |
| 67 | }, |
no test coverage detected
searching dependent graphs…