anzhiyu博客cdn修改

最近有些cdn老是没有用,而且有可能还有投毒事件的发生,因为这些的发生,所以我打算把cdn迁移到由初七云搭建的cdnjsew

修改文件

修改preconnect.pug文件

文件位于 blog\themes\anzhiyu\layout\includes\head\preconnect.pug
在位于开头的位置添加代码,位置位于我添加+的位置上

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-
const { internal_provider, third_party_provider, custom_format } = theme.CDN
const providers = {
'jsdelivr': '//cdn.jsdelivr.net',
'cdnjs': '//cdnjs.cloudflare.com',
'unpkg': '//unpkg.com',
'elemecdn': '//npm.elemecdn.com',
'onmicrosoft': '//npm.onmicrosoft.cn',
'cbd': '//cdn.cbd.int',
'anheyu': '//cdn.anheyu.com',
+ 'smartcis': '//cdn.smartcis.cn',
'custom': custom_format && custom_format.match(/^((https?:)?(\/\/[^/]+)|([^/]+))(\/|$)/)[1]
}
-
plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-
const { internal_provider, third_party_provider, custom_format } = theme.CDN
const providers = {
'jsdelivr': '//cdn.jsdelivr.net',
'cdnjs': '//cdnjs.cloudflare.com',
'unpkg': '//unpkg.com',
'elemecdn': '//npm.elemecdn.com',
'onmicrosoft': '//npm.onmicrosoft.cn',
'cbd': '//cdn.cbd.int',
'anheyu': '//cdn.anheyu.com',
'smartcis': '//cdn.smartcis.cn',
'custom': custom_format && custom_format.match(/^((https?:)?(\/\/[^/]+)|([^/]+))(\/|$)/)[1]
}
-

修改cdn.js文件

文件位于blog\themes\anzhiyu\scripts\events\cdn.js
在位于开头的位置添加代码,位置位于我添加+的位置上,大概位于102行位置

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
      const cdnSource = {
local: cond === "internal" ? cdnjs_file : `/pluginsSrc/${name}/${file}`,
jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_file}`,
unpkg: `https://unpkg.com/${name}${verType}/${file}`,
cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`,
elemecdn: `https://npm.elemecdn.com/${name}${verType}/${file}`,
onmicrosoft: `https://npm.onmicrosoft.cn/${name}${verType}/${file}`,
cbd: `https://cdn.cbd.int/${name}${verType}/${file}`,
anheyu: `https://cdn.anheyu.com/npm/${name}${verType}/${min_file}`,
+ smartcis: `https://cdn.smartcis.cn/npm/${name}${verType}/${file}`,
custom: (CDN.custom_format || "").replace(/\$\{(.+?)\}/g, (match, $1) => value[$1]),
};
plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
const cdnSource = {
local: cond === "internal" ? cdnjs_file : `/pluginsSrc/${name}/${file}`,
jsdelivr: `https://cdn.jsdelivr.net/npm/${name}${verType}/${min_file}`,
unpkg: `https://unpkg.com/${name}${verType}/${file}`,
cdnjs: `https://cdnjs.cloudflare.com/ajax/libs/${cdnjs_name}/${version}/${min_cdnjs_file}`,
elemecdn: `https://npm.elemecdn.com/${name}${verType}/${file}`,
onmicrosoft: `https://npm.onmicrosoft.cn/${name}${verType}/${file}`,
cbd: `https://cdn.cbd.int/${name}${verType}/${file}`,
anheyu: `https://cdn.anheyu.com/npm/${name}${verType}/${min_file}`,
smartcis: `https://cdn.smartcis.cn/npm/${name}${verType}/${file}`,
custom: (CDN.custom_format || "").replace(/\$\{(.+?)\}/g, (match, $1) => value[$1]),
};

最后修改 _config.anzhiyu.yml 文件

plaintext
1
2
3
4
5
6
修改  internal_provider: 
修改为 internal_provider: smartcis

修改 third_party_provider:
修改为 third_party_provider: smartcis

结束语

结束,修改cdn完成hexo三件套结束