Skip to content

Commit cb2cc84

Browse files
committed
simplify logic in preview build to parse and resolve icons
1 parent c0bd687 commit cb2cc84

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

gulp.d/tasks/build-preview-pages.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const iconPacks = {
2222
}
2323
iconPacks.fa = iconPacks.fas
2424
const iconShims = require('@fortawesome/fontawesome-free/js/v4-shims').reduce((accum, it) => {
25-
accum[it[0]] = [it[1] || 'fas', it[2] || it[0]]
25+
accum['fa-' + it[0]] = [it[1] || 'fas', 'fa-' + (it[2] || it[0])]
2626
return accum
2727
}, {})
2828
const { obj: map } = require('through2')
@@ -228,20 +228,20 @@ function registerIconDefs (iconDefs, file) {
228228
const contents = file.contents
229229
if (!contents.includes('<i class="fa')) return
230230
const stringContents = contents.toString()
231-
const iconNames = stringContents.match(/<i class="fa[brs]? fa-[^" ]+/g).map((it) => it.substr(10).replace('fa-', ''))
231+
const iconNames = stringContents.match(/<i class="fa[brs]? fa-[^" ]+/g).map((it) => it.substr(10))
232232
if (!iconNames.length) return
233233
;[...new Set(iconNames)].reduce((accum, iconKey) => {
234234
if (!accum.has(iconKey)) {
235235
const [iconPrefix, iconName] = iconKey.split(' ').slice(0, 2)
236-
let iconDef = (iconPacks[iconPrefix] || {})['fa' + camelCase(iconName)]
236+
let iconDef = (iconPacks[iconPrefix] || {})[camelCase(iconName)]
237237
if (iconDef) {
238238
return accum.set(iconKey, { ...iconDef, prefix: iconPrefix })
239239
} else if (iconPrefix === 'fa') {
240240
const [realIconPrefix, realIconName] = iconShims[iconName] || []
241241
if (
242-
!accum.has((iconKey = `${realIconPrefix} ${realIconName}`)) &&
243242
realIconName &&
244-
(iconDef = (iconPacks[realIconPrefix] || {})['fa' + camelCase(realIconName)])
243+
!accum.has((iconKey = `${realIconPrefix} ${realIconName}`)) &&
244+
(iconDef = (iconPacks[realIconPrefix] || {})[camelCase(realIconName)])
245245
) {
246246
return accum.set(iconKey, { ...iconDef, prefix: realIconPrefix })
247247
}
@@ -251,7 +251,7 @@ function registerIconDefs (iconDefs, file) {
251251
}, iconDefs)
252252
}
253253

254-
async function writeIconDefs (iconDefs, to) {
254+
function writeIconDefs (iconDefs, to) {
255255
return fs.writeFile(to, `window.FontAwesomeIconDefs = ${JSON.stringify([...iconDefs.values()])}\n`, 'utf8')
256256
}
257257

@@ -285,7 +285,5 @@ function toPromise (stream) {
285285
}
286286

287287
function camelCase (str) {
288-
return str.replace(/(?:^|-)(.)/g, function (_, l) {
289-
return l.toUpperCase()
290-
})
288+
return str.replace(/-(.)/g, (_, l) => l.toUpperCase())
291289
}

0 commit comments

Comments
 (0)