Skip to content

Commit 231787a

Browse files
authored
feat: 更新cdnjs到mirrors.sustech.edu.cn,并支持SRI
1 parent 5f68ecd commit 231787a

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

functions.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ function biji_enqueue_scripts() {
3232

3333
// 禁用jQuery
3434
wp_deregister_script( 'jquery' );
35-
// 咱们的主题使用Vue
36-
wp_enqueue_script( 'vue', '//cdn.staticfile.net/vue/2.6.14/vue.min.js', [], THEME_VERSION, true );
35+
// Vue
36+
wp_enqueue_script( 'vue', '//mirrors.sustech.edu.cn/cdnjs/ajax/libs/vue/2.6.14/vue.min.js', [], THEME_VERSION, true );
3737
// 开启代码高亮
3838
if ( get_theme_mod( 'biji_setting_prettify', true ) ) {
39-
wp_enqueue_script( 'prettify', '//cdn.staticfile.net/prettify/r298/prettify.min.js', [], THEME_VERSION, true );
39+
wp_enqueue_script( 'prettify', '//mirrors.sustech.edu.cn/cdnjs/ajax/libs/prettify/r298/prettify.min.js', [], THEME_VERSION, true );
4040
}
4141
wp_enqueue_script( 'helper', get_template_directory_uri() . '/static/helper.js', [], THEME_VERSION, false );
4242
wp_enqueue_script( 'package', get_template_directory_uri() . '/static/package.js', [], THEME_VERSION, false );
@@ -54,9 +54,21 @@ function biji_enqueue_scripts() {
5454
'lang' => get_locale(),
5555
] );
5656
}
57-
5857
add_action( 'wp_enqueue_scripts', 'biji_enqueue_scripts', 1 );
5958

59+
function add_sri_to_script( $html, $handle ) {
60+
if ( 'vue' === $handle ) {
61+
$integrity_hash = 'sha512-XdUZ5nrNkVySQBnnM5vzDqHai823Spoq1W3pJoQwomQja+o4Nw0Ew1ppxo5bhF2vMug6sfibhKWcNJsG8Vj9tg==';
62+
$html = str_replace( 'src=', 'integrity="' . $integrity_hash . '" crossorigin="anonymous" src=', $html );
63+
}
64+
if ( 'prettify' === $handle ) {
65+
$integrity_hash = 'sha512-/9uQgrROuVyGVQMh4f61rF2MTLjDVN+tFGn20kq66J+kTZu/q83X8oJ6i4I9MCl3psbB5ByQfIwtZcHDHc2ngQ==';
66+
$html = str_replace( 'src=', 'integrity="' . $integrity_hash . '" crossorigin="anonymous" src=', $html );
67+
}
68+
return $html;
69+
}
70+
add_filter( 'script_loader_tag', 'add_sri_to_script', 10, 2 );
71+
6072
// 添加特色缩略图支持
6173
if ( function_exists( 'add_theme_support' ) ) {
6274
add_theme_support( 'post-thumbnails' );

style.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Description: Simple, smooth, data-driven, responsive WordPress theme
66
Author: Tokin
77
Author URI: https://biji.io
8-
Version: 0.8.14
9-
Tested up to: 5.9.3
10-
Requires at least: 5.8
11-
Requires PHP: 7.0
8+
Version: 0.8.15
9+
Tested up to: 6.8.2
10+
Requires at least: 6.0
11+
Requires PHP: 7.4
1212
*/
1313
/* Trigger workflow */
1414
/* Manually forked from Normalize.css */

0 commit comments

Comments
 (0)