Skip to content

Commit

Permalink
refactor: embed files feature, resolve #383, resolve #333, resolve #134
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 11, 2018
1 parent c4d83f2 commit 4d61b1e
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const compileMedia = {
const id = `docsify-get-${uid++}`
let ext = url.match(/\.(\w+)$/)

ext = config.ext || (ext && ext[1])
ext = config.lang || (ext && ext[1])
if (ext === 'md') ext = 'markdown'

if (!process.env.SSR) {
Expand Down Expand Up @@ -182,6 +182,32 @@ export class Compiler {
const { str, config } = getAndRemoveConfig(title)
title = str

if (config.include) {
if (!isAbsolutePath(href)) {
href = getPath(contentBase, href)
}

let media
if (config.type && (media = compileMedia[config.type])) {
return media.call(_self, href, title)
}

let type = null
if (/\.(md|markdown)/.test(href)) {
type = 'markdown'
} else if (/\.html?/.test(href)) {
type = 'html'
} else if (/\.(mp4|ogg)/.test(href)) {
type = 'video'
} else if (/\.mp3/.test(href)) {
type = 'audio'
}
console.log(href)
if (type) {
return compileMedia[type].call(_self, href, title)
}
}

if (
!/:|(\/{2})/.test(href) &&
!_self.matchNotCompileLink(href) &&
Expand Down Expand Up @@ -235,25 +261,6 @@ export class Compiler {
url = getPath(contentBase, href)
}

let media
if (config.type && (media = compileMedia[config.type])) {
return media.call(_self, url, title)
}

let type = null
if (/\.(md|markdown)/.test(url)) {
type = 'markdown'
} else if (/\.html?/.test(url)) {
type = 'html'
} else if (/\.(mp4|ogg)/.test(url)) {
type = 'video'
} else if (/\.mp3/.test(url)) {
type = 'audio'
}
if (type) {
return compileMedia[type].call(_self, url, title)
}

return `<img src="${url}"data-origin="${href}" alt="${text}"${attrs}>`
}

Expand Down

0 comments on commit 4d61b1e

Please sign in to comment.