2019-08-25 23:42:05 +00:00
|
|
|
'use strict'
|
|
|
|
/* global hexo */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper to embed css file with support of custom attributes
|
|
|
|
* https://github.com/hexojs/hexo/pull/3690
|
|
|
|
*/
|
|
|
|
|
2019-08-26 04:03:23 +00:00
|
|
|
hexo.extend.helper.register('addCss', (...args) => {
|
2019-08-25 23:42:05 +00:00
|
|
|
let result = '\n'
|
|
|
|
let items = args
|
|
|
|
|
|
|
|
if (!Array.isArray(args)) {
|
|
|
|
items = [args]
|
|
|
|
}
|
|
|
|
|
|
|
|
items.forEach(item => {
|
|
|
|
// Old syntax
|
|
|
|
if (typeof item === 'string' || item instanceof String) {
|
|
|
|
result += `<link rel="stylesheet" href="${item}">\n`
|
|
|
|
} else {
|
|
|
|
// New syntax
|
|
|
|
let tmpResult = '<link rel="stylesheet"'
|
2019-08-30 06:40:29 +00:00
|
|
|
Object.keys(item).forEach(attribute => {
|
2019-08-25 23:42:05 +00:00
|
|
|
tmpResult += ` ${attribute}="${item[attribute]}"`
|
2019-08-30 06:40:29 +00:00
|
|
|
})
|
2019-08-25 23:42:05 +00:00
|
|
|
tmpResult += '>\n'
|
|
|
|
result += tmpResult
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return result
|
2019-08-26 04:03:23 +00:00
|
|
|
})
|