Skip to content

Commit

Permalink
fix: account for router.base in static mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Jan 8, 2019
1 parent 289075f commit fd84859
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
11 changes: 4 additions & 7 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,19 @@ export default function nuxtRfgIcon(options) {
}
}

let publicPath = faviconConfig.staticPath
if (publicPath.charAt(0) !== '/') publicPath = '/' + publicPath
if (publicPath.charAt(publicPath.length - 1) !== '/') publicPath += '/'

const publicPath = this.options.router.base + faviconConfig.staticPath + '/'
faviconConfig.rfg.iconsPath = fixUrl(publicPath)
} else {
// routerBase and publicPath
const routerBase = this.options.router.base
let publicPath = fixUrl(`${routerBase}/${this.options.build.publicPath}`)
let publicPath
if (isUrl(this.options.build.publicPath)) { // CDN
publicPath = this.options.build.publicPath

/* istanbul ignore next */
if (publicPath.indexOf('//') === 0) {
publicPath = '/' + publicPath // escape fixUrl
}
} else {
publicPath = fixUrl(`${this.options.router.base}`)
}
faviconConfig.rfg.iconsPath = fixUrl(publicPath + '/icons/')
}
Expand Down
19 changes: 8 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
const axios = require('axios')
import axios from 'axios'
const rfg = require('rfg-api').init()

const fixUrl = url => url.replace(/\/\//g, '/').replace(':/', '://')
const isUrl = url => url.indexOf('http') === 0 || url.indexOf('//') === 0
export const fixUrl = url => url.replace(/\/\//g, '/').replace(':/', '://')
export const isUrl = url => url.indexOf('http') === 0 || url.indexOf('//') === 0

exports.isUrl = isUrl
exports.fixUrl = fixUrl

exports.rfgDefaults = {
export const rfgDefaults = {
// taken from https://github.com/RealFaviconGenerator/cli-real-favicon/blob/master/common.js
apiKey: '402333a17311c9aa68257b9c5fc571276090ee56',
apiUrl: 'https://realfavicongenerator.net/api/favicon',
Expand Down Expand Up @@ -68,7 +65,7 @@ exports.rfgDefaults = {
}
}

exports.headersToJson = (headers, options) => {
export const headersToJson = (headers, options) => {
// add link and meta's to head
const head = {}

Expand Down Expand Up @@ -103,7 +100,7 @@ const convertToBuffer = (data) => {
return data
}

exports.rfgApiRequestMeta = (faviconConfig) => {
export const rfgApiRequestMeta = (faviconConfig) => {
if (faviconConfig.rfgApiMetaResponse) {
return Promise.resolve({ data: faviconConfig.rfgApiMetaResponse })
}
Expand All @@ -116,7 +113,7 @@ exports.rfgApiRequestMeta = (faviconConfig) => {
})
}

exports.rfgApiRequestPackage = (faviconConfig, packageUrl) => {
export const rfgApiRequestPackage = (faviconConfig, packageUrl) => {
if (faviconConfig.rfgApiPackageResponse) {
return Promise.resolve({ data: convertToBuffer(faviconConfig.rfgApiPackageResponse) })
}
Expand All @@ -125,7 +122,7 @@ exports.rfgApiRequestPackage = (faviconConfig, packageUrl) => {
})
}

exports.extractZipfile = (zipfile) => {
export const extractZipfile = (zipfile) => {
return new Promise((resolve, reject) => {
const entries = []
const faviconFiles = []
Expand Down

0 comments on commit fd84859

Please sign in to comment.