Skip to content

Commit

Permalink
fix: setup default content type
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 12, 2019
1 parent bf7dcb5 commit 00615c4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ const htmlTemplate = () => `
`

module.exports = ({ html, url, headers }) => {
const contentType = headers['content-type']
const isHTML =
const contentType = headers['content-type'] || 'text/html'
const hasHTML =
mimeTypes.extension(contentType) === 'html' && typeof html === 'string' && html.length
const content = isHTML ? html : htmlTemplate()
const content = hasHTML ? html : htmlTemplate()

const $ = cheerio.load(content, {
decodeEntities: false,
Expand All @@ -101,9 +101,19 @@ module.exports = ({ html, url, headers }) => {
if (isMime(contentType, 'image')) {
addMedia('image', { $, url, headers, body: url => `<img src="${url}">` })
} else if (isMime(contentType, 'video')) {
addMedia('video', { $, url, headers, body: url => `<video src="${url}"></video>` })
addMedia('video', {
$,
url,
headers,
body: url => `<video src="${url}"></video>`
})
} else if (isMime(contentType, 'audio')) {
addMedia('audio', { $, url, headers, body: url => `<audio src="${url}"></audio>` })
addMedia('audio', {
$,
url,
headers,
body: url => `<audio src="${url}"></audio>`
})
}

return $.html()
Expand Down

0 comments on commit 00615c4

Please sign in to comment.