1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
module.exports.config = { serviceWorker: { escape: 0, cacheName: 'MarcusBlogCache' }, register: { onsuccess: () => console.log("Service Worker 注册成功!"), onerror: () => GLOBAL_CONFIG.Snackbar !== undefined && mar.snackbarShow('Service Worker 注册失败!可能是由于您的浏览器不支持该功能!'), builder: (root, framework, pluginConfig) => { const registerConfig = pluginConfig.register const {onerror, onsuccess} = registerConfig return `<script> (() => { let sw = navigator.serviceWorker let error = ${onerror.toString()} if (!sw?.register('${new URL(root).pathname}sw.js') ${onsuccess ? '?.then(' + onsuccess.toString() + ')' : ''} ?.catch(error) ) error() })() </script>` } }, dom: { onsuccess: () => { caches.match('https://id.v3/').then(function(response) { if (response) { response.json().then(function(data) { GLOBAL_CONFIG.Snackbar !== undefined && mar.snackbarShow('通知📢', `已刷新缓存,更新为${data.global + "." + data.local}版本最新内容`); }); } else { console.info('未找到匹配的缓存响应'); } }).catch(function(error) { console.error('缓存匹配出错:', error); }); }, }, json: { maxHtml: 15, charLimit: 1024, precisionMode: { default: false }, merge: [], exclude: [ /sw\.js$/ ] }, external: { timeout: 10000, js: [ { head: "getScript\(", tail: "\)", }, ], skip: [], replace: [ { source: ["cdn.jsdelivr.net","cdnjs.cloudflare.com","cdn1.tianli0.top"], dist: "cdn.chuqis.com", }, { source: ["unpkg.com"], dist: "npm.elemecdn.com" } ], }, sort: { keywords: false, } } module.exports.cacheRules = { simple: { clean: true, search: false, match: (url, $eject) => { const allowedHost = $eject.domain; return url.host === allowedHost && url.pathname.match(/\.(woff2|woff|ttf|cur)$/) } }, cdn: { clean: true, match: url => [ "cdn.cbd.int", "lf26-cdn-tos.bytecdntp.com", "lf6-cdn-tos.bytecdntp.com", "lf3-cdn-tos.bytecdntp.com", "lf9-cdn-tos.bytecdntp.com", "cdn.staticfile.org", "npm.elemecdn.com", "jsd.onmicrosoft.cn", "cdn.chuqis.com", ].includes(url.host) && url.pathname.match(/\.(js|css|woff2|woff|ttf|cur)$/), }, };
module.exports.getSpareUrls = srcUrl => { if (srcUrl.startsWith('https://cdn.chuqis.com')) { return { timeout: 3000, list: [ srcUrl, `https://jsd.onmicrosoft.cn/${new URL(srcUrl).pathname}` ] } } } module.exports.ejectValues = (hexo) => { return { domain: { prefix: 'const', value: new URL(hexo.config.url).host } } }
|