Open funnycoderstar opened 6 years ago
使用hexo插件使博客支持pwa功能,目前我所知道的有两种插件均可实现该功能 hexo-pwa hexo-offline 前提(HTTPS) 全站支持HTTPS. 目前本人使用的是腾讯云的免费证书
使用hexo插件使博客支持pwa功能,目前我所知道的有两种插件均可实现该功能
npm i --save hexo-pwa
hexo的配置文件采用yml语言, 想要了解该语言的可以去看看
在根目录的_config.yml中添加
_config.yml
pwa: manifest: path: /manifest.json body: "name": "funnycoderstar" "short_name": "star" "theme_color": "rgba(203,7,83,0.86)" "background_color": "#FAFAFA" "display": "standalone" "Scope": "/" "start_url": "/" icons: - src: https://cdn.wangyaxing.cn/icon-144x144.png?v=1 sizes: 144x144 type: image/png - src: https://cdn.wangyaxing.cn/icon-128x128.png sizes: 128x128 type: image/png - src: https://cdn.wangyaxing.cn/icon-96x96.png sizes: 96x96 type: image/png serviceWorker: path: /sw.js preload: urls: - / posts: 5 opts: networkTimeoutSeconds: 5 routes: - pattern: !!js/regexp /hm.baidu.com/ strategy: networkOnly - pattern: !!js/regexp /.*\.(js|css|jpg|jpeg|png|gif)$/ strategy: cacheFirst - pattern: !!js/regexp /\// strategy: networkFirst priority: 5
参数含义可以去hexo-pwa文档中查看
manifest.json
sw.js
这两个文件放的位置要和配置中的路径一致, 我是放在跟目录的 sw.js
importScripts('https://g.alicdn.com/kg/workbox/3.3.0/workbox-sw.js'); if (workbox) { workbox.setConfig({ modulePathPrefix: 'https://g.alicdn.com/kg/workbox/3.3.0/' }); workbox.precaching.precache(['/', '/index.html']); workbox.routing.registerRoute(new RegExp('^https?://wangyaxing.cn/?$'), workbox.strategies.networkFirst()); workbox.routing.registerRoute(new RegExp('.*.html'), workbox.strategies.networkFirst()); workbox.routing.registerRoute(new RegExp('.*.(?:js|css)'), workbox.strategies.staleWhileRevalidate()); workbox.routing.registerRoute(new RegExp('https://cdn.wangyaxing.cn/'), workbox.strategies.cacheFirst()); }
{ "name": "funnycoderstar", "short_name": "star", "theme_color": "rgba(203,7,83,0.86)", "background_color": "#FAFAFA", "display": "standalone", "Scope": "/", "start_url": "/", "icons": [ { "src": "/source/images/icons/icon-96x96.png", "sizes": "96x96", "type": "image/png" }, { "src": "/source/images/icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }, { "src": "/source/images/icons/icon-144x144.png", "sizes": "144x144", "type": "image/png" }, ], "splash_pages": null }
manifest生成地址: https://app-manifest.firebaseapp.com/
funnycoderstar
在桌面上即可看到博客的小图标
感兴趣的小伙伴可以来我的博客体验一下, 哈哈~~ https://.wangyaxing.cn/
使用基本与hexo-pwa相同, 下面简述一下过程
npm i --save hexo-offline
# Offline ## Config passed to sw-precache ## https://github.com/JLHwung/hexo-offline offline: maximumFileSizeToCacheInBytes: 10485760 staticFileGlobs: - public/**/*.{js,html,css,png,jpg,jpeg,gif,svg,json,xml} stripPrefix: public verbose: true runtimeCaching: - urlPattern: /* handler: cacheFirst options: origin: cdn.example.com - urlPattern: /* handler: cacheFirst options: origin: cdn.another-example.org
manifest.json放到 source目录下
next主题在 layout/_partials/head.swig添加
layout/_partials/head.swig
<link rel="manifest" href="/manifest.json">
serviceWorker
非常感谢呀~~ 已经按照你的方法成功了,请问你的这个教程,可以转载吗?
使用hexo-pwa
1.安装hexo-pwa
2.修改配置文件
在根目录的
_config.yml
中添加参数含义可以去hexo-pwa文档中查看
3.添加
manifest.json
和sw.js
这两个文件放的位置要和配置中的路径一致, 我是放在跟目录的 sw.js
manifest.json
manifest生成地址: https://app-manifest.firebaseapp.com/
4.将
funnycoderstar
安装到主屏(PWA)在桌面上即可看到博客的小图标
使用hexo-offline
使用基本与hexo-pwa相同, 下面简述一下过程
1. 安装
2. 修改配置文件
3. 添加
manifest.json
manifest.json放到 source目录下
4. 引入
manifest.json
next主题在
layout/_partials/head.swig
添加注意
serviceWorker
是否已加载参考