mirror of https://gitlab.com/curben/blog
feat(addCss): add helper to embed css file
This commit is contained in:
parent
2dacb8f5fe
commit
b4ff248560
|
@ -0,0 +1,34 @@
|
||||||
|
'use strict'
|
||||||
|
/* global hexo */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper to embed css file with support of custom attributes
|
||||||
|
* https://github.com/hexojs/hexo/pull/3690
|
||||||
|
*/
|
||||||
|
|
||||||
|
function cssHelper (...args) {
|
||||||
|
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"'
|
||||||
|
for (const attribute in item) {
|
||||||
|
tmpResult += ` ${attribute}="${item[attribute]}"`
|
||||||
|
}
|
||||||
|
tmpResult += '>\n'
|
||||||
|
result += tmpResult
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
hexo.extend.helper.register('addCss', cssHelper)
|
|
@ -44,8 +44,8 @@
|
||||||
<%/* Fallback function for SRI */%>
|
<%/* Fallback function for SRI */%>
|
||||||
<%- js('js/sri.min') %>
|
<%- js('js/sri.min') %>
|
||||||
|
|
||||||
<%- css('css/typing') %>
|
<%- addCss('css/typing.css') %>
|
||||||
<% if (theme.icons) { %>
|
<% if (theme.icons) { %>
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fork-awesome/1.1.7/css/fork-awesome.min.css" data-sri-fallback="/forkawesome/css/fork-awesome.min.css" integrity="sha384-mByhW6NjnxyShh67P9+fepUvYSd7Uz/qV6e2u4kA2Fi4ZkjXxIP2mRkyK9dwK24W" crossorigin="anonymous">
|
<%- addCss({ href: 'https://cdnjs.cloudflare.com/ajax/libs/fork-awesome/1.1.7/css/fork-awesome.min.css', 'data-sri-fallback': '/forkawesome/css/fork-awesome.min.css', integrity: 'sha384-mByhW6NjnxyShh67P9+fepUvYSd7Uz/qV6e2u4kA2Fi4ZkjXxIP2mRkyK9dwK24W', crossorigin: 'anonymous' }) %>
|
||||||
<% } %>
|
<% } %>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue