-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (41 loc) · 1.42 KB
/
Copy pathindex.js
File metadata and controls
49 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { library, dom, icon: getIcon } = require('@fortawesome/fontawesome-svg-core')
function tryInstall(block) {
try {
var icons = block()
library.add(icons)
return true
} catch(ex) {
return false
}
}
tryInstall(function () { return require('@fortawesome/free-solid-svg-icons').fas })
tryInstall(function () { return require('@fortawesome/free-regular-svg-icons').far })
tryInstall(function () { return require('@fortawesome/free-brands-svg-icons').fab })
function faCss() {
return dom.css()
}
function faInline(iconName, opts) {
var options = opts || {prefix: 'fas'}
var prefix = options.prefix
var icon = getIcon({ prefix: prefix, iconName: iconName })
if (!icon) {
throw new Error(
'Can not find icon "' + iconName +'" with prefix "' + prefix + '"' +
'Make sure you have installed also a corresponding icons package:\n' +
' - @fortawesome/free-solid-svg-icons for fas prefix \n' +
' - @fortawesome/free-regular-svg-icons for far prefix\n' +
' - @fortawesome/free-brands-svg-icons for fab prefix\n'
)
}
return icon.html
}
hexo.extend.helper.register('fa_css', faCss)
hexo.extend.helper.register('fa_inline', faInline)
hexo.extend.tag.register('fa_css', function () {
return '<style>' + faCss() + '</style>'
})
hexo.extend.tag.register('fa_inline', function (args) {
var iconName = args[0]
var prefix = args[1] || 'fas'
return faInline(iconName, {prefix: prefix})
})