From d01ab1522b4ae00c7d84c0f9f7e7f47869fe2132 Mon Sep 17 00:00:00 2001 From: 186526 Date: Thu, 29 Apr 2021 18:29:50 +0800 Subject: [PATCH] Update --- .drone.yml | 4 +- Readme.MD | 8 +- package.json | 11 +- source/_posts/pwa-transformation.md | 2 +- themes/suka/scripts/index.js | 2 +- themes/suka/source/js/blog-186.js | 195 +++++++++++++++------------- 6 files changed, 120 insertions(+), 102 deletions(-) diff --git a/.drone.yml b/.drone.yml index 215a791..42f3e58 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,13 +7,13 @@ steps: image: node:lts-buster commands: - apt-get update -y && apt-get install git -y - - yarn install + - yarn init-build - yarn drone-build - name: git-push image: appleboy/drone-git-push settings: - path: "public/" + path: "./public/" force: true ssh_key: from_secret: ssh_key diff --git a/Readme.MD b/Readme.MD index c153734..3f96b37 100644 --- a/Readme.MD +++ b/Readme.MD @@ -1,7 +1,7 @@ # blog.186526.xyz -Use GPL-3.0 open source on git.186526.xyz -Unless otherwise specified, the articles will be signed-non-commercial use-shared in the same way +Use GPL-3.0 open source on git.186526.xyz. +Unless otherwise specified, the articles will be signed-non-commercial use-shared (CC BY-NC-SA 4.0) in the same way. -在git.186526.xyz上使用GPL-3.0的开源 -除非另有说明,否则文章将以相同方式使用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议 +在git.186526.xyz上使用GPL-3.0的开源。 +除非另有说明,否则文章将以相同方式使用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议。 diff --git a/package.json b/package.json index c4e66f9..64d194d 100644 --- a/package.json +++ b/package.json @@ -3,16 +3,17 @@ "version": "0.0.0", "private": true, "scripts": { + "init-build": "yarn;yarn --cwd ./themes/suka", "build": "hexo generate", "clean": "hexo clean", "deploy": "hexo deploy", "server": "hexo server", - "build-cloudflare": "yarn;yarn --cwd ./themes/suka;hexo generate;node cleancache.js", - "vercel-build": "yarn build-cloudflare", - "drone-build": "yarn;yarn --cwd ./themes/suka;hexo generate" + "build-cloudflare": "yarn build", + "vercel-build": "yarn build;node cleancache.js", + "drone-build": "yarn build" }, "hexo": { - "version": "5.3.0" + "version": "5.4.0" }, "dependencies": { "autoprefixer": "^10.2.5", @@ -41,4 +42,4 @@ "spectre.css": "^0.5.9", "yarn": "^1.22.10" } -} +} \ No newline at end of file diff --git a/source/_posts/pwa-transformation.md b/source/_posts/pwa-transformation.md index 53f3603..a59f92f 100644 --- a/source/_posts/pwa-transformation.md +++ b/source/_posts/pwa-transformation.md @@ -164,7 +164,7 @@ window.addEventListener("load", () => { 由于在同一页面中,同时只能存在一个 `Service Worker`,所以我们需要考虑到 `Service Worker` 的更新情况。 -你可以通过监听 `navigator.serviceWorker` 的 `controllerchange` 时间来更新 `Service Worker`。 +你可以通过监听 `navigator.serviceWorker` 的 `controllerchange` 事件来更新 `Service Worker`。 ```js window.addEventListener("load", () => { diff --git a/themes/suka/scripts/index.js b/themes/suka/scripts/index.js index 46333a2..4757210 100644 --- a/themes/suka/scripts/index.js +++ b/themes/suka/scripts/index.js @@ -26,13 +26,13 @@ async function main() { } setTimeout(function () { globalThis.buildEnvironment = a; + console.log(globalThis.buildEnvironment); },100); })); }else{ return `Amazon Linux 2 (Karoo) @ Node.js ${process.version}`; } })() - console.log(globalThis.buildEnvironment); } main(); diff --git a/themes/suka/source/js/blog-186.js b/themes/suka/source/js/blog-186.js index 09dfbe9..2f92aac 100644 --- a/themes/suka/source/js/blog-186.js +++ b/themes/suka/source/js/blog-186.js @@ -1,101 +1,118 @@ (function () { + if (typeof globalThis === 'undefined') { + var globalThis = window; + } + console.log('\n %c 186526\'s Blog | © 186526 \n', 'color: #fff; background: #444; padding:5px 0;'); - window.addEventListener("load", () => { - whenAvailable("Pjax", () => { - const pjax = new Pjax({ - elements: "a:not([target=_blank])", - selectors: [ - "title", - "meta[name=description]", - ".pjax", - ], - cacheBust: !1 - }); + window.addEventListener("load", function () { + whenAvailable("Pjax", function () { + var pjax = new Pjax({ + elements: "a:not([target=_blank])", + selectors: ["title", "meta[name=description]", ".pjax"], + cacheBust: !1 }); - document.addEventListener("pjax:send", send); - document.addEventListener("pjax:success", suc); + }); + document.addEventListener("pjax:send", send); + document.addEventListener("pjax:success", suc); }); - window.addEventListener('load', () => { - if ('serviceWorker' in navigator) { - navigator.serviceWorker - .register('/sw.js', { - scope: '/', - }) - .then(function (registration) { - console.log( - 'ServiceWorker registration successful with scope: ', - registration.scope, - ); - }) - .catch(function (err) { - console.warn('ServiceWorker registration failed: ', err); - }); - navigator.serviceWorker.addEventListener('controllerchange', () => { - let d = document.querySelector("title"); - d.innerText = "Need update Service Worker - " + d.innerText; - //d=document.body; - //d.innerHTML = `
Service Worker已经更新 请刷新页面进行安装
` + d.innerHTML; - }); + window.addEventListener('load', function () { + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js', { + scope: '/' + }).then(function (registration) { + console.log('ServiceWorker registration successful with scope: ', registration.scope); + }).catch(function (err) { + console.warn('ServiceWorker registration failed: ', err); + }); + navigator.serviceWorker.addEventListener('controllerchange', function () { + var d = document.querySelector("title"); + d.innerText = "Need update Service Worker - " + d.innerText; //d=document.body; + //d.innerHTML = `
Service Worker已经更新 请刷新页面进行安装
` + d.innerHTML; + }); + } + + if (/HeadlessChrome/.test(window.navigator.userAgent)) { + return; + } + + if (!window.dataLayer) { + var d = document, + a = d.createElement("script"); + a.async = true; + a.src = "https://www.googletagmanager.com/gtag/js?id=G-ENYRL7T64N"; + d.head.appendChild(a); + } + + if (typeof navigator.connection !== "undefined") { + if (navigator.connection.rtt <= 600 & navigator.connection.downlink >= 0.5) { + fontsInit(); + } else { + setTimeout(fontsInit, 5000); } - if (/HeadlessChrome/.test(window.navigator.userAgent)) { return; } - if (!window.dataLayer) { - let d = document, a = d.createElement("script"); - a.async = true; - a.src = "https://www.googletagmanager.com/gtag/js?id=G-ENYRL7T64N"; - d.head.appendChild(a); - } - if(typeof navigator.connection !== "undefined") { - if (navigator.connection.rtt <= 600 & navigator.connection.downlink >= 0.5) { - fontsInit(); - } else { - setTimeout(fontsInit, 5000); - } - }else { - setTimeout(fontsInit,1000); - } - window.dataLayer = window.dataLayer || []; - function gtag() { dataLayer.push(arguments); } - gtag('js', new Date()); - gtag('config', 'G-ENYRL7T64N'); + } else { + setTimeout(fontsInit, 1000); + } + + window.dataLayer = window.dataLayer || []; + + function gtag() { + dataLayer.push(arguments); + } + + gtag('js', new Date()); + gtag('config', 'G-ENYRL7T64N'); }); - let fontsInit = () => { - let d = document, url = "/css/fonts.min.css"; - d.head.innerHTML += ``; + + var fontsInit = function fontsInit() { + var d = document, + url = "/css/fonts.min.css"; + d.head.innerHTML += ""); }; - let send = () => { - whenAvailable("NProgress", () => { - NProgress.inc(); - }); + + var send = function send() { + whenAvailable("NProgress", function () { + NProgress.inc(); + }); }; - let suc = () => { - whenAvailable("NProgress", () => { - NProgress.done(); - }); - whenAvailable("LazyLoad", () => { - new LazyLoad(globalThis.lazyLoadOptions) - }); - window.dataLayer = window.dataLayer || []; - function gtag() { dataLayer.push(arguments); } - gtag('js', new Date()); - gtag('config', 'G-ENYRL7T64N'); + + var suc = function suc() { + whenAvailable("NProgress", function () { + NProgress.done(); + }); + whenAvailable("LazyLoad", function () { + new LazyLoad(globalThis.lazyLoadOptions); + }); + window.dataLayer = window.dataLayer || []; + + function gtag() { + dataLayer.push(arguments); + } + + gtag('js', new Date()); + gtag('config', 'G-ENYRL7T64N'); }; - document.addEventListener('LoadValine', () => { - if (document.querySelector("#vcomments")) { - valinedo(); - } + + document.addEventListener('LoadValine', function () { + if (document.querySelector("#vcomments")) { + valinedo(); + } }); - let whenAvailable = (name, callback) => { - var interval = 100; - window.setTimeout(function () { - if (window[name]) { - callback(window[name]); - } else { - window.setTimeout(arguments.callee, interval); - } - }, interval); + + globalThis.whenAvailable = function (name, callback) { + var interval = 100; + window.setTimeout(function () { + if (window[name]) { + callback(window[name]); + } else { + window.setTimeout(arguments.callee, interval); + } + }, interval); }; - globalThis.__BLOG__ = (() => new Object({ + + globalThis.__BLOG__ = function () { + return new Object({ name: "186526's Blog", - use: "hexo@^5.0", - }))(); -})(); \ No newline at end of file + use: "hexo@^5.0" + }); + }(); + })(); \ No newline at end of file