Giter VIP home page Giter VIP logo

hexo-swpp's Introduction

嗨嗨~ 这里是空梦哦ww

统计信息

EmptyDreams's GitHub stats

Top Langs

hexo-swpp's People

Contributors

emptydreams avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hexo-swpp's Issues

config中的dom为undefined时报错

默认配置项为

module.exports.config = {
dom: {
      onsuccess: undefined,
  }
}

但执行hexo g时出现TypeError: Cannot read properties of undefined (reading 'toString') 的错误
如果写成

dom: {
      onsuccess:  () => console.log("Service Worker 注册成功!"),
},

则不会报错

构建时拉取静态文件的问题

image

  1. 从 StaticFile 与 BootCDN 上拉取资源时会出现大量的超时错误,然而我的 timeout 是 5000……

  2. 从对象存储上拉取东西总是出错,这个该怎么设置?

// sw-rules.js
module.exports.config = {
    serviceWorker: {
        escape: 0,
        cacheName: 'LCTTBlogCache'
    },
    register: {
        onsuccess: undefined,
        onerror: () => console.error('Service Worker 注册失败,可能是由于您的浏览器不支持该功能!'),
        builder: (root, framework, pluginConfig) => {
            const { onerror, onsuccess } = pluginConfig.register;
            return `
            <script>
                (() => {
                    const sw = navigator.serviceWorker;
                    const error = ${onerror && onerror.toString()};
                    if (!sw?.register('${new URL(root).pathname}sw.js')
                        ${onsuccess ? `?.then(${onsuccess.toString()})` : ''}
                        ?.catch(error)
                    ) error()
                })()
            </script>`;
        }
    },
    dom: {
        onsuccess: () => {
            caches.match(location.href).then(res => {
                if (res)
                    res.json().then(json => {
                        utils && utils.snackbarShow(`已刷新缓存,更新为${json.global + '.' + json.local}版本最新内容`, false, 2000)
                    })
                else
                    console.info('未找到缓存')
            }).catch((error) => console.error("缓存匹配出错", error))
        }
    },
    json: {
        maxHtml: 15,
        charLimit: 1024,
        merge: ['index', 'tags', 'categories'],
        exclude: {
            localhost: [],
            other: []
        }
    },
    external: {
        timeout: 5000,
        concurrencyLimit: 100,
        js: [],
        stable: [],
        replacer: srcUrl => {
            if (srcUrl.startsWith('https://cdn.jsdelivr.net/npm/')) {
                const pathname = new URL(srcUrl).pathname;
                return [
                    srcUrl,
                    `https://cdn.cbd.int/${pathname}`,
                    `https://npm.elemecdn.com/${pathname}`,
                    `https://fastly.jsdelivr.net/npm/${pathname}`,
                ];
            } else {
                return srcUrl;
            }
        }
    }
};

module.exports.cacheRules = {
    simple: {
        clean: true,
        search: false,
        match: (url, $eject) => (url.host.includes('lynx') || url.host.includes('lctt')) && url.pathname.match(/\.(html|js|css|xml)$/), //主站缓存
    },
    cdn: {
        clean: true,
        match: url => [
            // 此处略去部分 CDN 节点
            "cdn.staticfile.net",
            "cdn.bootcdn.net",
        ].includes(url.host) && url.pathname.match(/\.(js|css|woff2|woff|ttf|json|png|jpg|webp)$/), //CDN 缓存
    }
};

module.exports.getSpareUrls = srcUrl => {
    if (srcUrl.startsWith("https://npm.elemecdn.com")) {
        return {
            timeout: 3000,
            list: [srcUrl, `https://fastly.jsdelivr.net/${new URL(srcUrl).pathname}`, `https://cdn.cbd.int/${new URL(srcUrl).pathname}`],
        };
    }
}

module.exports.isMemoryQueue = request => {
    // do something...
}

module.exports.ejectValues = (hexo, rules) => {
    return {
        domain: {
            prefix: "const",
            value: new URL(hexo.config.url).host,
        },
    };
};

在一篇文章有多个分类的情况下,hexo-swpp 会打乱显示的分类

首先明确一点:问题出现在以下两处:

image

image

问题描述

不启用 swpp:

image

按照一级分类-二级分类-三级分类排序,文章与 Home 同样

启用 swpp:

image

按照231或321排序,文章与 Home 同样,翻阅源代码后发现相关HTML生成错误,但侧边栏与/categories/文件夹内结构均正确。

问题排查

依次尝试停用无关插件,发现问题出现在 swpp 身上。

变化历史

Github 存储库 Commit记录

最后一个正常时间点:LynxCatTheThird/lynxcatthethird.github.io@af49e66

第一个失常时间点:LynxCatTheThird/lynxcatthethird.github.io@0811a3f

Vercel 部署历史

最后一个正常时间点:https://person-m1ler6vkk-lynxcatthethird.vercel.app/

第一个失常时间点:https://person-88ldqv2g7-lynxcatthethird.vercel.app/

其它信息

存储库

https://github.com/LynxCatTheThird/lynxcatthethird.github.io

https://github.com/LynxCatTheThird/web-now

文章信息

title: 生物备战-难题分析(1)
categories:
  - 科学与技术
  - 生物
  - 典题分析
tags:
  - 生物
  - 典题分析
cover: "https://s2.hdslb.com/bfs/article/0b9dfd3e95fb368fe4f5e52534e6035910466bb3.jpg@1e_1c.webp"
abbrlink: 409e60fe
date: 2023-06-02 16:09:05
updated: 2023-06-02 16:09:05
katex: false
mathjax: false
mermaid: false
description: 潍坊的题真难……
title: 类原生优化计划
tags: 刷机
categories:
  - 科学与技术
  - 计算机
  - 刷机
abbrlink: 4097fa9
date: 2023-07-08 16:27:55
updated: 2023-07-08 16:27:55
cover: https://s2.hdslb.com/bfs/article/eecc20f3eb6a274a1a46c985c1706df57bfde092.jpg@1e_1c.webp
katex: false
mathjax: false
mermaid: false
description: 类原生真好用~

package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "build": "hexo generate",
    "clean": "hexo clean",
    "deploy": "hexo deploy",
    "server": "hexo server"
  },
  "hexo": {
    "version": "6.3.0"
  },
  "dependencies": {
    "@renbaoshuo/markdown-it-katex": "^2.0.2",
    "hexo": "^6.3.0",
    "hexo-abbrlink": "^2.2.1",
    "hexo-deployer-git": "^4.0.0",
    "hexo-filter-nofollow": "^2.0.2",
    "hexo-generator-archive": "^2.0.0",
    "hexo-generator-category": "^2.0.0",
    "hexo-generator-index": "^3.0.0",
    "hexo-generator-searchdb": "^1.4.1",
    "hexo-generator-tag": "^2.0.0",
    "hexo-minify": "^1.8.1",
    "hexo-pangu": "^0.2.2",
    "hexo-renderer-ejs": "^2.0.0",
    "hexo-renderer-markdown-it": "^7.1.0",
    "hexo-renderer-pug": "^3.0.0",
    "hexo-renderer-stylus": "^3.0.0",
    "hexo-server": "^3.0.0",
    "hexo-swpp": "^2.7.0",
    "hexo-tag-mmedia": "^1.2.1",
    "hexo-wordcount": "^6.0.1",
    "katex": "^0.16.8"
  }
}

sw-rules.js(以下两个均出错)

/**
 * 缓存列表
 * @param clean 清理全站时是否删除其缓存
 * @param match {function(URL)} 匹配规则
 */
module.exports.cacheList = {
    // 这个 [simple] 就是规则的名称,该对象下可以包含多个规则,名称不影响缓存匹配
    // 缓存匹配时按声明顺序进行匹配
    simple: {
        // [clean] 项用于声明符合该规则的缓存在进行全局清理时是否清除
        // 如果你无法确定是否需要声明为 false 的话写 true 即可
        clean: true,
        // 该项用于匹配缓存,传入的参数是 URL 类型的,返回一个 boolean
        match: url => {
            const allowedHosts = [
                'lynxcatthethird.github.io', 'ara1145.github.io',
                'lynx3.netlify.app', 'nl.lynxcatthethird.eu.org', 'nl.lctt.eu.org',
                'lynx3-2.netlify.app', 'nl2.lynxcatthethird.eu.org', 'nl2.lctt.eu.org',
                'lynx3.vercel.app', 'vc.lynxcatthethird.eu.org', 'vc.lctt.eu.org',
                'lynx3-2.vercel.app', 'vc2.lynxcatthethird.eu.org', 'vc2.lctt.eu.org',
                'lynx3.pages.dev', 'cf.lynxcatthethird.eu.org', 'cf.lctt.eu.org',
                'lynx3-2.pages.dev', 'cf2.lynxcatthethird.eu.org', 'cf2.lctt.eu.org',
                'localhost', '127.0.0.1'
            ];
            if (!allowedHosts.includes(url.host)) {
                return false;
            }
            return url.pathname.match(/.(woff2|png|jpg|web|js|css|json|xml)$/);
        }
    }
}

module.exports.config = {
    /**
     * 与 ServiceWorker 有关的配置项
     * 若想禁止插件自动生成 sw,此项填 false 即可
     * @type ?Object|boolean
     */
    serviceWorker: {
        /**
         * 逃生门
         * @type number
         * @see https://kmar.top/posts/73014407/#6c7c33f0
         */
        escape: 0,
        /**
         * 缓存库名称
         * 发布网站后 **切勿修改** 该配置项!
         * @type string
         */
        cacheName: 'LCTTBlogCache',
        /**
         * 是否启用调试,启用后会在 sw 中插入一些辅助调试的代码,不建议开启
         * @type boolean
         */
        debug: false
    },
    /**
     * 与 SW 注册有关的配置项
     * 若想禁止插件向 html 中插入注册代码,此项填 false 即可
     * @type Object|boolean
     */
    register: {
        /**
         * sw 注册成功时的动作
         * @type ?VoidFunction
         * */
        onsuccess: () => console.log("Service Worker 注册成功"),
        /**
         * sw 注册失败时的动作
         * ~若没有禁用 register,则该项为必填项,该项没有缺省值~
         * @type ?VoidFunction
         */
        onerror: () => console.error("ServiceWorker 注册失败,可能是您的浏览器不支持该功能。"),
        /**
         * 生成注册 SW 的 HTML 代码片段
         * @param root {string} 网页根目录的 URL
         * @param hexoConfig {Object} Hexo 配置项
         * @param pluginConfig {Object} SW 配置项
         * @return {string} 一个 HTML 标签的字符串形式
         */
        builder: (root, hexoConfig, pluginConfig) => {
            const { onerror, onsuccess } = pluginConfig.register
            return `<script>
                      (() => {
                          const sw = navigator.serviceWorker
                          const error = ${onerror.toString()}
                          if (!sw?.register('${new URL(root).pathname}sw.js')
                              ${onsuccess ? '?.then(' + onsuccess + ')' : ''}
                              ?.catch(error)
                              ) error()
                      })()
                  </script>`
        }
    },
    /**
     * 与 DOM 端有关的配置
     * 若想禁止插件自动生成 DOM 端 JS,此项填 false 即可
     * @type Object|boolean
     */
    dom: {
        /**
         * 缓存更新成功后触发的操作
         * @type VoidFunction
         */
        onsuccess: () => console.log("缓存更新成功")
    },
    /**
     * 与插件生成的版本文件相关的配置项
     * 该功能目前无法关闭
     */
    json: {
        /**
         * 更新缓存时允许更新的最大 HTML 页面数量,需要更新的 HTML 文件数量超过这个值后会清除所有 HTML 缓存
         * @type number
         */
        maxHtml: 15,
        /**
         * 版本文件(update.json)字符数量限制,插件将保证版本文件的字符数量不超过该值
         * @type number
         */
        charLimit: 1024,
        /**
         * 文件缓存匹配采取精确模式
         * 关闭时更新缓存时仅匹配文件名称,如 https://kmar.top/simple/a/index.html 仅匹配 /a/index.html
         * 开启后更新缓存时将会匹配完整名称,如 https://kmar.top/simple/a/index.html 将匹配 /simple/a/index.html
         * 两种方式各有优劣,开启后会增加 update.json 的空间占用,但会提升精确度
         * 如果网站内没有多级目录结构,就可以放心大胆的关闭了
         * key 值为文件拓展名,default 用于指代所有未列出的拓展名以及没有拓展名的文件
         */
        precisionMode: {
            default: true
        },
        /**
         * 是否合并指定项目
         * 例如当 tags 为 true 时(假设标签目录为 https://kmar.top/tags/...)
         * 如果标签页存在更新,则直接匹配 https://kmar.top/tags/ 目录下的所有文件
         * **推荐将此项开启**
         */
        merge: {
            index: true,
            tags: true,
            archives: true,
            categories: true,
            /**
             * 这里填写目录名称列表(不带两边的斜杠)
             * @type string[]
             */
            custom: ["link", "comment", "talk", "aboutme", "aboutsite", "thanks", "policy"]
        },
        /**
         * 生成版本文件时忽略的文件
         * 注:匹配的时候不附带域名,只有 pathname,匹配的内容一定是博客本地的文件
         * @type RegExp[]
         */
        exclude: [
            /sw\.js$/
        ]
    },
    /**
     * 外部文件更新监听
     * 该项缺省值为 false,若想允许插件监听外部文件的更新至少将值改为 `{}`
     * @type Object|boolean
     * @see https://kmar.top/posts/73014407/#c60b3060
     */
    external: {
        /**
         * 拉取网络文件时的超时时间
         * @type number
         */
        timeout: 1500,
        /**
         * 匹配 JS 代码中的 URL
         * 注意:字符串中的内容将被直接嵌入到正则表达式中,括号等特殊字符前需添加反斜杠,不允许使用括号
         * 该项的缺省值为 `[]`,下方的值仅用于标明填写格式
         * @see https://kmar.top/posts/73014407/#c60b3060
         */
        js: [
            {
                head: 'getScript\(',
                tail: '\)'
            }
        ],
        /**
         * 某些外链只要 URL 不变其内容就一定不会变
         * 可以通过正则表达式排除这些外链的文件内容监控,加快构建速度
         * 注意:当某一个文件被跳过拉取后,这个文件中包含的 URL 也会被跳过
         * @type RegExp[]
         */
        skip: [],
        /**
         * 在构建过程中替换部分链接,该替换结果不会影响文件内容
         * 该设置项是为了应对构建服务器在国外,但是网站内部分缓存资源无法在国外访问导致拉取时超时的问题
         * 该项的缺省值为 `[]`,下方的值仅用于标明填写格式
         * @type Object[]
         * @see https://kmar.top/posts/73014407/#4ea71e00
         */
        replace: [
            {
                source: ['source0', 'source1'],
                dist: 'dist'
            }
        ]
    },
    /**
     * 对 Hexo 中的变量进行排序
     * 默认插件对 posts、tags、categories、pages 四个变量进行排序
     * 排序规则为优先按照字符串长度排序,若长度一致按照字典序排序
     * 
     * 格式为 `name: value`
     * value 的可能值为:字符串、非负整数、false
     * 假定 Array<obj> 为要被排序的数据
     * 当 value 为字符串和非负整数时,插件会以 `obj[value]` 的格式读取关键字
     * 当 value 为 false 时,插件会直接以 `obj` 为关键字
     * 注意:关键字必须为含有 length 属性且支持 < 操作符的类型
     * 插件内置的 posts 规则如果用上面的格式写应该为:
     * posts: 'title'
     * 插件支持使用配置项覆盖插件内置规则
     * 
     * 该项缺省值为 `{}`,下方的值仅用于标明填写格式
     */
    sort: {
        keywords: false
    }
}
module.exports.cacheList = {}

module.exports.config = {
    register: {
        onerror: () => console.error("ServiceWorker 注册失败,可能是您的浏览器不支持该功能。")
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.