mirror of https://gitlab.com/curben/blog
refactor(helpers): js() and css() helpers now support custom attributes
- https://github.com/hexojs/hexo/pull/3681 - https://github.com/hexojs/hexo/pull/3690
This commit is contained in:
parent
5cd412bda6
commit
887f9ec116
|
@ -1,6 +1,6 @@
|
|||
<% if (is_post()) { %>
|
||||
<%- addJs({ src: '/libs/clipboard.js/2.0.4/clipboard.min.js', 'data-sri-fallback': '/js/clipboard.min.js', integrity: 'sha384-8CYhPwYlLELodlcQV713V9ZikA3DlCVaXFDpjHfP8Z36gpddf/Vrt47XmKDsCttu', crossorigin: 'anonymous', defer: true}) %>
|
||||
<%- js({ src: '/libs/clipboard.js/2.0.4/clipboard.min.js', 'data-sri-fallback': '/js/clipboard.min.js', integrity: 'sha384-8CYhPwYlLELodlcQV713V9ZikA3DlCVaXFDpjHfP8Z36gpddf/Vrt47XmKDsCttu', crossorigin: 'anonymous', defer: true}) %>
|
||||
<% } %>
|
||||
|
||||
<%/* javascript of Typing theme */%>
|
||||
<%- addJs('/js/chameleon.js') %>
|
||||
<%/* javascript of Chameleon theme */%>
|
||||
<%- js('/js/chameleon.js') %>
|
||||
|
|
|
@ -44,11 +44,12 @@
|
|||
<link rel="sitemap" type="application/xml" title="Sitemap" href="/sitemap.xml">
|
||||
|
||||
<%/* Fallback function for SRI */%>
|
||||
<%- addJs({ src: '/js/sri.min.js', 'async': true }) %>
|
||||
<%- js({ src: '/js/sri.min.js', 'async': true }) %>
|
||||
|
||||
<%- addCss('/css/chameleon.css') %>
|
||||
<%/* CSS of Chameleon theme */%>
|
||||
<%- css('/css/chameleon.css') %>
|
||||
|
||||
<% if (theme.icons) { %>
|
||||
<%- addCss({ href: '/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' }) %>
|
||||
<%- css({ href: '/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>
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
'use strict'
|
||||
/* global hexo */
|
||||
|
||||
/*
|
||||
* Helper to embed css file with support of custom attributes
|
||||
* https://github.com/hexojs/hexo/pull/3690
|
||||
*/
|
||||
|
||||
hexo.extend.helper.register('addCss', (...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"'
|
||||
Object.keys(item).forEach(attribute => {
|
||||
tmpResult += ` ${attribute}="${item[attribute]}"`
|
||||
})
|
||||
tmpResult += '>\n'
|
||||
result += tmpResult
|
||||
}
|
||||
})
|
||||
return result
|
||||
})
|
|
@ -1,33 +0,0 @@
|
|||
'use strict'
|
||||
/* global hexo */
|
||||
|
||||
/*
|
||||
* Helper to add <script src=""> with support of custom attributes
|
||||
* https://github.com/hexojs/hexo/pull/3681
|
||||
*/
|
||||
|
||||
hexo.extend.helper.register('addJs', (...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 += `<script src="${item}"></script>\n`
|
||||
} else {
|
||||
// New syntax
|
||||
let tmpResult = '<script'
|
||||
Object.keys(item).forEach(attribute => {
|
||||
if (item[attribute] === true) tmpResult += ' ' + attribute
|
||||
else tmpResult += ` ${attribute}="${item[attribute]}"`
|
||||
})
|
||||
tmpResult += '></script>\n'
|
||||
result += tmpResult
|
||||
}
|
||||
})
|
||||
return result
|
||||
})
|
Loading…
Reference in New Issue