Skip to content

Commit

Permalink
fix: loading embed files synchronously, fixed #525, fixed #527 (#544)
Browse files Browse the repository at this point in the history
* fix: loading embed files synchronously, fixed #525, fixed #527

* fix
  • Loading branch information
QingWei-Li authored Jun 29, 2018
1 parent cd09d91 commit feea7f9
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/core/render/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,44 @@ import {merge} from '../util/core'

const cached = {}

function walkFetchEmbed({step = 0, embedTokens, compile, fetch}, cb) {
const token = embedTokens[step]
function walkFetchEmbed({embedTokens, compile, fetch}, cb) {
let token
let step = 0
let count = 1

if (!token) {
if (!embedTokens.length) {
return cb({})
}

const next = text => {
let embedToken
if (text) {
if (token.embed.type === 'markdown') {
embedToken = compile.lexer(text)
} else if (token.embed.type === 'code') {
embedToken = compile.lexer(
'```' +
token.embed.lang +
'\n' +
text.replace(/`/g, '@DOCSIFY_QM@') +
'\n```\n'
)
while ((token = embedTokens[step++])) {
const next = (function (token) {
return text => {
let embedToken
if (text) {
if (token.embed.type === 'markdown') {
embedToken = compile.lexer(text)
} else if (token.embed.type === 'code') {
embedToken = compile.lexer(
'```' +
token.embed.lang +
'\n' +
text.replace(/`/g, '@DOCSIFY_QM@') +
'\n```\n'
)
}
}
cb({token, embedToken})
if (++count >= step) {
cb({})
}
}
}
cb({token, embedToken})
walkFetchEmbed({step: ++step, compile, embedTokens, fetch}, cb)
}
})(token)

if (process.env.SSR) {
fetch(token.embed.url).then(next)
} else {
get(token.embed.url).then(next)
if (process.env.SSR) {
fetch(token.embed.url).then(next)
} else {
get(token.embed.url).then(next)
}
}
}

Expand Down

0 comments on commit feea7f9

Please sign in to comment.