fix: loading embed files synchronously, fixed #525, fixed #527 (#544)

* fix: loading embed files synchronously, fixed #525, fixed #527

* fix
This commit is contained in:
cinwell.li 2018-06-29 21:27:07 +08:00 • committed by GitHub
commit feea7f9b48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,14 +3,18 @@ import {merge} from '../util/core'
const cached = {} const cached = {}
function walkFetchEmbed({step = 0, embedTokens, compile, fetch}, cb) { function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
const token = embedTokens[step] let token
let step = 0
let count = 1
if (!token) { if (!embedTokens.length) {
return cb({}) return cb({})
} }
const next = text => { while ((token = embedTokens[step++])) {
const next = (function (token) {
return text => {
let embedToken let embedToken
if (text) { if (text) {
if (token.embed.type === 'markdown') { if (token.embed.type === 'markdown') {
@ -26,8 +30,11 @@ function walkFetchEmbed({step = 0, embedTokens, compile, fetch}, cb) {
} }
} }
cb({token, embedToken}) cb({token, embedToken})
walkFetchEmbed({step: ++step, compile, embedTokens, fetch}, cb) if (++count >= step) {
cb({})
} }
}
})(token)
if (process.env.SSR) { if (process.env.SSR) {
fetch(token.embed.url).then(next) fetch(token.embed.url).then(next)
@ -35,6 +42,7 @@ function walkFetchEmbed({step = 0, embedTokens, compile, fetch}, cb) {
get(token.embed.url).then(next) get(token.embed.url).then(next)
} }
} }
}
export function prerenderEmbed({compiler, raw = '', fetch}, done) { export function prerenderEmbed({compiler, raw = '', fetch}, done) {
let hit let hit