Skip to content

Commit a20b0e5

Browse files
committed
feat: add sri support for css
1 parent 7276085 commit a20b0e5

File tree

3 files changed

+106
-77
lines changed

3 files changed

+106
-77
lines changed

_config.yml

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ anchor_icon: # default use '#' icon, you can use a hexadecimal representation of
164164
reimu_cursor:
165165
enable: true
166166
cursor:
167-
default: ../images/cursor/reimu-cursor-default.png # this path is relative to the css/style.css, so it needs to go up one level to reach the images folder
167+
default: ../images/cursor/reimu-cursor-default.png # this path is relative to the css/style.css, so it needs to go up one level to reach the images folder
168168
pointer: ../images/cursor/reimu-cursor-pointer.png
169169
text: ../images/cursor/reimu-cursor-text.png
170170

@@ -401,7 +401,7 @@ generator_search:
401401
# Loader animation
402402
preloader:
403403
enable: true
404-
text:
404+
text:
405405
zh-CN: 少女祈祷中...
406406
zh-TW: 少女祈禱中...
407407
en: Loading...
@@ -467,12 +467,12 @@ firework:
467467

468468
# Clipboard configuration
469469
clipboard:
470-
success:
470+
success:
471471
en: Copy successfully (*^▽^*)
472472
zh-CN: 复制成功 (*^▽^*)
473473
zh-TW: 複製成功 (*^▽^*)
474474
ja: コピー成功 (*^▽^*)
475-
fail:
475+
fail:
476476
en: Copy failed (゚⊿゚)ツ
477477
zh-CN: 复制失败 (゚⊿゚)ツ
478478
zh-TW: 複製失敗 (゚⊿゚)ツ
@@ -504,7 +504,7 @@ outdate:
504504
# Sponsor
505505
sponsor:
506506
enable: false
507-
tip:
507+
tip:
508508
zh-CN: 请作者喝杯咖啡吧
509509
zh-TW: 請作者喝杯咖啡吧
510510
en: Buy me a coffee
@@ -607,7 +607,7 @@ player:
607607
autoplay:
608608
loop:
609609
order:
610-
preload:
610+
preload:
611611
volume:
612612
mutex:
613613
listFolded:
@@ -628,8 +628,8 @@ player:
628628
########################################
629629

630630
pangu:
631-
# more information: https://github.com/vinta/pangu.js
632-
enable: false # enable pangu.js to add space between Chinese and English
631+
# more information: https://github.com/vinta/pangu.js
632+
enable: false # enable pangu.js to add space between Chinese and English
633633

634634
########################################
635635
# Theme
@@ -645,51 +645,51 @@ material_theme:
645645

646646
internal_theme:
647647
light:
648-
--red-0: '#ff0000'
649-
--red-1: '#ff5252'
650-
--red-2: '#ff7c7c'
651-
--red-3: '#ffafaf'
652-
--red-4: '#ffd0d0'
653-
--red-5: '#ffecec'
654-
--red-5-5: '#fff3f3'
655-
--red-6: '#fff7f7'
656-
--color-red-6-shadow: 'rgba(255, 78, 78, 0.6)'
657-
--color-red-3-shadow: 'rgba(255, 78, 78, 0.3)'
658-
659-
--highlight-nav: '#e6e6e6'
660-
--highlight-scrollbar: '#d6d6d6'
661-
--highlight-background: '#f7f7f7'
662-
--highlight-current-line: '#dadada'
663-
--highlight-selection: '#e9e9e9'
664-
--highlight-foreground: '#4d4d4d'
665-
--highlight-comment: '#7d7d7d'
666-
--highlight-red: '#c8362b'
667-
--highlight-orange: '#b66014'
668-
--highlight-yellow: '#cb911d'
669-
--highlight-green: '#2ea52e'
670-
--highlight-aqua: '#479d9d'
671-
--highlight-blue: '#1973b8'
672-
--highlight-purple: '#7135ac'
648+
--red-0: "#ff0000"
649+
--red-1: "#ff5252"
650+
--red-2: "#ff7c7c"
651+
--red-3: "#ffafaf"
652+
--red-4: "#ffd0d0"
653+
--red-5: "#ffecec"
654+
--red-5-5: "#fff3f3"
655+
--red-6: "#fff7f7"
656+
--color-red-6-shadow: "rgba(255, 78, 78, 0.6)"
657+
--color-red-3-shadow: "rgba(255, 78, 78, 0.3)"
658+
659+
--highlight-nav: "#e6e6e6"
660+
--highlight-scrollbar: "#d6d6d6"
661+
--highlight-background: "#f7f7f7"
662+
--highlight-current-line: "#dadada"
663+
--highlight-selection: "#e9e9e9"
664+
--highlight-foreground: "#4d4d4d"
665+
--highlight-comment: "#7d7d7d"
666+
--highlight-red: "#c8362b"
667+
--highlight-orange: "#b66014"
668+
--highlight-yellow: "#cb911d"
669+
--highlight-green: "#2ea52e"
670+
--highlight-aqua: "#479d9d"
671+
--highlight-blue: "#1973b8"
672+
--highlight-purple: "#7135ac"
673673
dark:
674-
--red-4: 'rgba(255, 208, 208, 0.5)'
675-
--red-5: 'rgba(255,228,228,0.15)'
676-
--red-5-5: 'rgba(255,236,236,0.05)'
677-
--red-6: 'rgba(255, 243, 243, 0.2)'
678-
679-
--highlight-nav: '#2e353f'
680-
--highlight-scrollbar: '#454d59'
681-
--highlight-background: '#22272e'
682-
--highlight-current-line: '#393939'
683-
--highlight-selection: '#515151'
684-
--highlight-foreground: '#cccccc'
685-
--highlight-comment: '#999999'
686-
--highlight-red: '#f47067'
687-
--highlight-orange: '#f69d50'
688-
--highlight-yellow: '#ffcc66'
689-
--highlight-green: '#99cc99'
690-
--highlight-aqua: '#66cccc'
691-
--highlight-blue: '#54b6ff'
692-
--highlight-purple: '#dcbdfb'
674+
--red-4: "rgba(255, 208, 208, 0.5)"
675+
--red-5: "rgba(255,228,228,0.15)"
676+
--red-5-5: "rgba(255,236,236,0.05)"
677+
--red-6: "rgba(255, 243, 243, 0.2)"
678+
679+
--highlight-nav: "#2e353f"
680+
--highlight-scrollbar: "#454d59"
681+
--highlight-background: "#22272e"
682+
--highlight-current-line: "#393939"
683+
--highlight-selection: "#515151"
684+
--highlight-foreground: "#cccccc"
685+
--highlight-comment: "#999999"
686+
--highlight-red: "#f47067"
687+
--highlight-orange: "#f69d50"
688+
--highlight-yellow: "#ffcc66"
689+
--highlight-green: "#99cc99"
690+
--highlight-aqua: "#66cccc"
691+
--highlight-blue: "#54b6ff"
692+
--highlight-purple: "#dcbdfb"
693693

694694
########################################
695695
# Vendor
@@ -793,17 +793,34 @@ vendor:
793793
src: webcache|[email protected]/dist/material-theme.umd.js
794794
integrity: sha384-vLev0II0HKFaxkcm+/7kX5IGwVFBASkGchU311wmU/veIj2bB0UcBkQbW6yw2asK
795795
css:
796-
photoswipe: webcache|[email protected]/dist/photoswipe.css
797-
katex: webcache|[email protected]/dist/katex.min.css
798-
waline: webcache|@waline/[email protected]/dist/waline.css
799-
gitalk: webcache|[email protected]/dist/gitalk.css
796+
photoswipe:
797+
src: webcache|[email protected]/dist/photoswipe.css
798+
integrity: sha384-IfxC36XL/toUyJ939C73PcgMuRzAZuIzZxE38drsmO5p6jD7ei+Zx/1oA/0l8ysE
799+
katex:
800+
src: webcache|[email protected]/dist/katex.min.css
801+
integrity: sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+
802+
waline:
803+
src: webcache|@waline/[email protected]/dist/waline.css
804+
integrity: sha384-vltfZtesCdl6NYVcFVcjEaIi5RpNvZe9t7fXvq8twVtcoy+Ub9QgnxUYJmwOhYCK
805+
gitalk:
806+
src: webcache|[email protected]/dist/gitalk.css
807+
integrity: sha384-X7z7PUv2B67D8sPJyzDyGZSco1ADwmdI7ed4eCGtTKkClfyDFpPL9WgAn9XVr/Io
800808
fontawesome:
801809
high_priority:
802-
- webcache|@fortawesome/[email protected]/css/regular.min.css
803-
- webcache|@fortawesome/[email protected]/css/solid.min.css
810+
- src: webcache|@fortawesome/[email protected]/css/regular.min.css
811+
integrity: sha384-k5640LgghgAohDLPwSqVWa96yQwWouT6wsAL+J1g0CFJVITNKYkIh1XpPLYKQe7Y
812+
- src: webcache|@fortawesome/[email protected]/css/solid.min.css
813+
integrity: sha384-8yO/A/BtltnG0hDxdwmmkza8UAleyDoAD1FhXiH6rsOQQsCho1P6WZP9TpBBH3YP
804814
low_priority:
805-
- webcache|@fortawesome/[email protected]/css/brands.min.css
806-
- webcache|@fortawesome/[email protected]/css/v5-font-face.min.css
807-
- webcache|@fortawesome/[email protected]/css/v4-font-face.min.css
808-
aos: webcache|@reimujs/[email protected]/dist/aos.css
809-
aplayer: webcache|[email protected]/dist/APlayer.min.css
815+
- src: webcache|@fortawesome/[email protected]/css/brands.min.css
816+
integrity: sha384-/BRyRRN0wxxRgh/DAXU621go9pdoMHl6LFPiX5Pp8PZYZlKBQCDXj9X9DHx6LOud
817+
- src: webcache|@fortawesome/[email protected]/css/v5-font-face.min.css
818+
integrity: sha384-/mBKnLlGtog8q2qQrgugURRDV+iHWHAPvM5KulYXT1C2ErKOKkBI0vbff8ZPq7rL
819+
- src: webcache|@fortawesome/[email protected]/css/v4-font-face.min.css
820+
integrity: sha384-d2Yn1/9Iw78r3oqwk5B+EcpRcmepXR5LyhmRF2a+WoSe9mpRGvVk0ZviFwDGDOTO
821+
aos:
822+
src: webcache|@reimujs/[email protected]/dist/aos.css
823+
integrity: sha384-4NN3fZ5AokFyHuoihl7A9qWaCt+HsAtOaUsXwJGRb4/SMBtFr2vcNSHR5E8dg0Wk
824+
aplayer:
825+
src: webcache|[email protected]/dist/APlayer.min.css
826+
integrity: sha384-tLMkTWh2pfXNWGFlUS0w1TFtRG5xZ9lPWFOooj+vDDLIL+xBGQU/voDBY5XE2lVh

layout/_partial/head.ejs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
<%- vendorGoogleFont() %>
3636
<% } %>
3737
<% if (!theme.icon_font) { %>
38-
<%- css(vendorCdn(theme.vendor.css.fontawesome.high_priority)) %>
39-
<%- asyncCss(vendorCdn(theme.vendor.css.fontawesome.low_priority)) %>
38+
<%- css(theme.vendor.css.fontawesome.high_priority.map(i => ({href: vendorCdn(i)[0], integrity: vendorCdnIntegrity(i)[0], crossorigin: "anonymous"}))) %>
39+
<%- asyncCss(theme.vendor.css.fontawesome.low_priority.map(i => ({href: vendorCdn(i)[0], integrity: vendorCdnIntegrity(i)[0], crossorigin: "anonymous"}))) %>
4040
<% } else { %>
4141
<link rel="preload" href="//at.alicdn.com/t/c/font_<%- theme.icon_font %>.woff2" as="font" type="font/woff2" crossorigin="anonymous">
4242
<% } %>
@@ -55,38 +55,38 @@
5555
<%- favicon_tag(theme.favicon) %>
5656
<% } %>
5757
<%- css('css/style') %>
58-
<%- asyncCss(vendorCdn(theme.vendor.css.photoswipe)) %>
58+
<%- asyncCss({href: vendorCdn(theme.vendor.css.photoswipe)[0], integrity: vendorCdnIntegrity(theme.vendor.css.photoswipe)[0], crossorigin: "anonymous"}) %>
5959
<% if (theme.math.enable) { %>
6060
<% if (theme.math.katex.enable) { %>
6161
<% if (is_post() || is_page()) { %>
62-
<%- css(vendorCdn(theme.vendor.css.katex)) %>
62+
<%- css({href: vendorCdn(theme.vendor.css.katex)[0], integrity: vendorCdnIntegrity(theme.vendor.css.katex)[0], crossorigin: "anonymous"}) %>
6363
<% } else { %>
64-
<%- asyncCss(vendorCdn(theme.vendor.css.katex)) %>
64+
<%- asyncCss({href: vendorCdn(theme.vendor.css.katex)[0], integrity: vendorCdnIntegrity(theme.vendor.css.katex)[0], crossorigin: "anonymous"}) %>
6565
<% } %>
6666
<% } %>
6767
<% } %>
6868
<% if (theme.waline.enable && theme.waline.serverURL) { %>
6969
<% if (is_post() || is_page()) { %>
70-
<%- css(vendorCdn(theme.vendor.css.waline)) %>
70+
<%- css({href: vendorCdn(theme.vendor.css.waline)[0], integrity: vendorCdnIntegrity(theme.vendor.css.waline)[0], crossorigin: "anonymous"}) %>
7171
<% } else { %>
72-
<%- asyncCss(vendorCdn(theme.vendor.css.waline)) %>
72+
<%- asyncCss({href: vendorCdn(theme.vendor.css.waline)[0], integrity: vendorCdnIntegrity(theme.vendor.css.waline)[0], crossorigin: "anonymous"}) %>
7373
<% } %>
7474
<% } %>
7575
<% if (theme.gitalk.enable && theme.gitalk.clientID && theme.gitalk.clientSecret) { %>
7676
<% if (is_post() || is_page()) { %>
77-
<%- css(vendorCdn(theme.vendor.css.gitalk)) %>
77+
<%- css({href: vendorCdn(theme.vendor.css.gitalk)[0], integrity: vendorCdnIntegrity(theme.vendor.css.gitalk)[0], crossorigin: "anonymous"}) %>
7878
<% } else { %>
79-
<%- asyncCss(vendorCdn(theme.vendor.css.gitalk)) %>
79+
<%- asyncCss({href: vendorCdn(theme.vendor.css.gitalk)[0], integrity: vendorCdnIntegrity(theme.vendor.css.gitalk)[0], crossorigin: "anonymous"}) %>
8080
<% } %>
8181
<% } %>
8282
<% if (theme.pace.enable) { %>
8383
<%- js({src: vendorCdn(theme.vendor.js.pace)[0], integrity: vendorCdnIntegrity(theme.vendor.js.pace)[0], crossorigin: "anonymous"}) %>
8484
<% } %>
8585
<% if (theme.animation.enable) { %>
86-
<%- css(vendorCdn(theme.vendor.css.aos)) %>
86+
<%- css({href: vendorCdn(theme.vendor.css.aos)[0], integrity: vendorCdnIntegrity(theme.vendor.css.aos)[0], crossorigin: "anonymous"}) %>
8787
<% } %>
8888
<% if (theme.player.aplayer.enable) { %>
89-
<%- css(vendorCdn(theme.vendor.css.aplayer)) %>
89+
<%- css({href: vendorCdn(theme.vendor.css.aplayer)[0], integrity: vendorCdnIntegrity(theme.vendor.css.aplayer)[0], crossorigin: "anonymous"}) %>
9090
<% } %>
9191
<% if (theme.injector.head_end) { %>
9292
<%- render(theme.injector.head_end, 'html'); %>

scripts/helper/asyncCss.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
const { htmlTag } = require("hexo-util");
12
hexo.extend.helper.register("asyncCss", (content) => {
23
if (!Array.isArray(content)) {
34
content = [content];
45
}
56

67
return content
78
.map((item) => {
8-
if (!item.endsWith(".css")) {
9-
item += ".css";
9+
if (typeof item === "string") {
10+
let path = item;
11+
if (!path.endsWith(".css")) {
12+
path += ".css";
13+
}
14+
return `<link rel="preload" href="${item}" as="style" onload="this.onload=null;this.rel='stylesheet'">`;
15+
} else {
16+
if (!item.href.endsWith(".css")) item.href += ".css";
17+
return htmlTag("link", {
18+
rel: "preload",
19+
as: "style",
20+
onload: "this.onload=null;this.rel='stylesheet'",
21+
...item,
22+
});
1023
}
11-
return `<link rel="preload" href="${item}" as="style" onload="this.onload=null;this.rel='stylesheet'">`;
1224
})
1325
.join("\n");
1426
});

0 commit comments

Comments
 (0)