From b4ff248560de74c121b5f391b716780c48b8476d Mon Sep 17 00:00:00 2001 From: curben <2809763-curben@users.noreply.gitlab.com> Date: Mon, 26 Aug 2019 09:12:05 +0930 Subject: [PATCH] feat(addCss): add helper to embed css file --- scripts/addCss.js | 34 ++++++++++++++++++++++++++ themes/typing/layout/_partial/head.ejs | 4 +-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 scripts/addCss.js diff --git a/scripts/addCss.js b/scripts/addCss.js new file mode 100644 index 0000000..a5c1d61 --- /dev/null +++ b/scripts/addCss.js @@ -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 += `\n` + } else { + // New syntax + let tmpResult = ' <%- js('js/sri.min') %> - <%- css('css/typing') %> + <%- addCss('css/typing.css') %> <% if (theme.icons) { %> - + <%- 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' }) %> <% } %>