From a3d079febd647861de098bbcceff2a8ceb9242d8 Mon Sep 17 00:00:00 2001 From: purocean Date: Sat, 13 Nov 2021 11:22:02 +0800 Subject: [PATCH] fix(demo): macro include & fetch --- src/renderer/others/demo.ts | 12 ++++++++++-- src/renderer/plugins/markdown-macro.ts | 2 -- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/renderer/others/demo.ts b/src/renderer/others/demo.ts index 85562c5f..47ad4752 100644 --- a/src/renderer/others/demo.ts +++ b/src/renderer/others/demo.ts @@ -34,7 +34,7 @@ if (FLAG_DEMO) { } }, true) - window.fetch = (uri: any, init: any) => Promise.resolve({ + const fakeFetch = (uri: any, init: any) => Promise.resolve({ json: () => { console.log('mock api >', uri, init) @@ -121,7 +121,7 @@ if (FLAG_DEMO) { }) } - const path = '/' + (url.searchParams.get('doc') || 'FEATURES.md') + const path = '/' + (url.searchParams.get('doc')?.replace(/^\//, '') || 'FEATURES.md') const data = { status: 'ok', message: 'success', @@ -159,6 +159,14 @@ if (FLAG_DEMO) { } } as any) + window.fetch = (uri: any, init: any) => { + if (uri.startsWith('https://') || uri.startsWith('http://')) { + return xFetch(uri, init) + } + + return fakeFetch(uri, init) + } + window.open = function (...args: any[]) { const win = xOpen(...args) win!.fetch = window.fetch diff --git a/src/renderer/plugins/markdown-macro.ts b/src/renderer/plugins/markdown-macro.ts index 06649d49..80edba67 100644 --- a/src/renderer/plugins/markdown-macro.ts +++ b/src/renderer/plugins/markdown-macro.ts @@ -138,8 +138,6 @@ export default { let posOffset = 0 state.src = state.src.replace(reg, (match, matchPos) => { try { - console.log('xxx', match, { ...vars }) - const exp = match .substring(2, match.length - 2) .trim()