hexo-offline 0.2.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -34
- package/README.md +41 -30
- package/lib/index.js +4 -5
- package/lib/lib/constants.js +4 -2
- package/lib/lib/index.js +9 -15
- package/lib/lib/inject-sw-register.js +26 -28
- package/lib/lib/run-workbox-build.js +85 -0
- package/lib/lib/template.js +1 -1
- package/package.json +26 -29
- package/.babelrc +0 -18
- package/.editorconfig +0 -9
- package/.npmignore +0 -47
- package/.nycrc +0 -7
- package/.travis.yml +0 -13
- package/.yaspellerrc +0 -30
- package/lib/lib/run-sw-precache.js +0 -57
- package/yarn.lock +0 -3863
package/CHANGELOG.md
CHANGED
|
@@ -1,90 +1,174 @@
|
|
|
1
|
+
#### 2.0.1 (2022-01-06)
|
|
2
|
+
|
|
3
|
+
##### Chores
|
|
4
|
+
|
|
5
|
+
* support Hexo v6 (#143) (2ad4305)
|
|
6
|
+
* update renovate config (3fe78f7f)
|
|
7
|
+
* **deps:** update coverallsapp/github-action action to v1.1.3 (#144) (05269257)
|
|
8
|
+
|
|
9
|
+
## 2.0.0 (2021-03-12)
|
|
10
|
+
|
|
11
|
+
##### Breaking Changes
|
|
12
|
+
|
|
13
|
+
- use workbox-build (#138) (8208bef7)
|
|
14
|
+
- drop node < 10 support (4711dad5)
|
|
15
|
+
|
|
16
|
+
#### 1.0.1 (2018-12-06)
|
|
17
|
+
|
|
18
|
+
##### Chores
|
|
19
|
+
|
|
20
|
+
- **package:**
|
|
21
|
+
- update yarn lockfiles (0225b25c)
|
|
22
|
+
- update devDependencies (638f390a)
|
|
23
|
+
- **deps:**
|
|
24
|
+
- update babel monorepo to v7.2.0 (#57) (9d9babcd)
|
|
25
|
+
- update dependency prettier to v1.15.3 (#56) (845477f6)
|
|
26
|
+
- update dependency lint-staged to v8.1.0 (#54) (b0abea6f)
|
|
27
|
+
- update dependency prettier to v1.15.2 (bf02d99e)
|
|
28
|
+
- update dependency husky to v1.2.0 (0cf31bee)
|
|
29
|
+
- update babel monorepo (d1c93593)
|
|
30
|
+
- pin dependencies (#51) (b305ad1f)
|
|
31
|
+
|
|
32
|
+
##### Code Style Changes
|
|
33
|
+
|
|
34
|
+
- format whole project (15deac7a)
|
|
35
|
+
|
|
36
|
+
## 1.0.0 (2018-06-09)
|
|
37
|
+
|
|
38
|
+
##### Chores
|
|
39
|
+
|
|
40
|
+
- **package:**
|
|
41
|
+
- drop node.js 4 support (66b55e0e)
|
|
42
|
+
- update dependencies (4b983894)
|
|
43
|
+
- **npmignore:** include lib only in package (9c6bcbd6)
|
|
44
|
+
|
|
45
|
+
#### 0.2.3 (2018-03-15)
|
|
46
|
+
|
|
47
|
+
##### Chores
|
|
48
|
+
|
|
49
|
+
- **package:**
|
|
50
|
+
- update standard to version 11.0.1 (e68823a0)
|
|
51
|
+
- use yaspeller-ci (159bacc4)
|
|
52
|
+
- does not spellcheck CHANGELOG.md (017b5d40)
|
|
53
|
+
- update lockfile (9599ee3f)
|
|
54
|
+
- update tap to version 11.0.1 (7bb8fad0)
|
|
55
|
+
- remove package-lock (d2fa713b)
|
|
56
|
+
- update yarn lockfile (6164d774)
|
|
57
|
+
- update lockfile (7dfc5419)
|
|
58
|
+
- update yaspeller to version 4.0.0 (eb7b6a11)
|
|
59
|
+
- upgrade dependencies to latest version (5f1bb1a0)
|
|
60
|
+
- update nyc to version 11.0.2 (f075611c)
|
|
61
|
+
- add package-lock (53d1f274)
|
|
62
|
+
- upgrade dependencies (e1bc34b4)
|
|
63
|
+
- update babel-preset-babili to version 0.1.1 (ccabd582)
|
|
64
|
+
- update cross-env to version 5.0.0 (f7180935)
|
|
65
|
+
- regenerate yarn lockfile (b97f7d6a)
|
|
66
|
+
- update standard to version 10.0.0 (3c209f06)
|
|
67
|
+
- **appveyor:**
|
|
68
|
+
- use yarn cache in appveyor (f34bbd51)
|
|
69
|
+
- use bundled npm version (8fd7e21d)
|
|
70
|
+
- **travis:**
|
|
71
|
+
- add greenkeeper lockfile (6bdc17b6)
|
|
72
|
+
- use node as latest node.js build target (178aac46)
|
|
73
|
+
- **yaspeller:** add vuejs to dictionary (46dce2db)
|
|
74
|
+
|
|
75
|
+
##### Documentation Changes
|
|
76
|
+
|
|
77
|
+
- **README:** fix typo (ad34600c)
|
|
78
|
+
- **readme:** add vuejs.org as demo site (7c89bf62)
|
|
79
|
+
|
|
80
|
+
##### Bug Fixes
|
|
81
|
+
|
|
82
|
+
- **run-sw-precache:** remove hardcoded public directory (c178610e)
|
|
83
|
+
- **inject-sw-register:** remove async attribute on script (9d735e04)
|
|
84
|
+
- **appveyor:** use yarn as install process (e6526892)
|
|
85
|
+
|
|
1
86
|
#### 0.2.2 (2017-3-31)
|
|
2
87
|
|
|
3
88
|
##### Chores
|
|
4
89
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
90
|
+
- **yaspeller:** update dictionary (1793a9f5)
|
|
91
|
+
- **package:**
|
|
92
|
+
- upgrade sw-precache to version 5.1.0 (dc7feb09)
|
|
93
|
+
- update babel-preset-env to version 1.3.2 (6f1b0f49)
|
|
94
|
+
- update cross-env to version 4.0.0 (09b6024d)
|
|
95
|
+
- update standard to version 9.0.0 (67a28e13)
|
|
96
|
+
- re-generate yarn lockfile using default registry (4b9e5d55)
|
|
97
|
+
- update cross-env to version 3.2.3 (c0e4b6ef)
|
|
98
|
+
- update babel-preset-babili to version 0.0.12 (f172fa6e)
|
|
14
99
|
|
|
15
100
|
#### 0.2.1 (2017-2-20)
|
|
16
101
|
|
|
17
102
|
##### Chores
|
|
18
103
|
|
|
19
|
-
|
|
104
|
+
- **package:** update babel-plugin-istanbul to version 4.0.0 (87589b23)
|
|
20
105
|
|
|
21
106
|
##### Documentation Changes
|
|
22
107
|
|
|
23
|
-
|
|
108
|
+
- **readme:** add CDN contents usage (4432e0b4)
|
|
24
109
|
|
|
25
110
|
##### Bug Fixes
|
|
26
111
|
|
|
27
|
-
|
|
112
|
+
- **inject-sw-register:** early return when injected before (7d4b61fd)
|
|
28
113
|
|
|
29
114
|
##### Tests
|
|
30
115
|
|
|
31
|
-
|
|
116
|
+
- **inject-sw-register:** add test case on duplicated injection (bfa88df9)
|
|
32
117
|
|
|
33
118
|
### 0.2.0 (2017-2-17)
|
|
34
119
|
|
|
35
120
|
##### Chores
|
|
36
121
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
122
|
+
- **yaspeller:** add words to dictionary (316eac55)
|
|
123
|
+
- **package:**
|
|
124
|
+
- update babel-preset-babili to version 0.0.11 (333e85e1)
|
|
125
|
+
- update tap to version 10.0.1 (672ecc66)
|
|
126
|
+
- update babel-preset-babili to version 0.0.10 (6a082c0d)
|
|
42
127
|
|
|
43
128
|
##### Bug Fixes
|
|
44
129
|
|
|
45
|
-
|
|
130
|
+
- **package:** update sw-precache to version 5.0.0 (6d5719a1)
|
|
46
131
|
|
|
47
132
|
#### 0.1.3 (2017-1-17)
|
|
48
133
|
|
|
49
134
|
##### Chores
|
|
50
135
|
|
|
51
|
-
|
|
136
|
+
- **yaspeller:** add words to dictionary (40775e56)
|
|
52
137
|
|
|
53
138
|
#### 0.1.2 (2017-1-17)
|
|
54
139
|
|
|
55
140
|
##### Chores
|
|
56
141
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
142
|
+
- **package:**
|
|
143
|
+
- update sw-precache to version 4.3.0 (e95ac9b3)
|
|
144
|
+
- remove unused babel-core (2ed41655)
|
|
145
|
+
- remove unused babel-register (5a08426f)
|
|
61
146
|
|
|
62
147
|
##### Bug Fixes
|
|
63
148
|
|
|
64
|
-
|
|
149
|
+
- **package:** change prepublish script to prepublishOnly (4470a438)
|
|
65
150
|
|
|
66
151
|
##### Tests
|
|
67
152
|
|
|
68
|
-
|
|
153
|
+
- **yaspeller:** add yaspeller (31191a97)
|
|
69
154
|
|
|
70
155
|
#### 0.1.1 (2017-1-15)
|
|
71
156
|
|
|
72
157
|
##### Chores
|
|
73
158
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
159
|
+
- **package:**
|
|
160
|
+
- update tap to version 9.0.3 (ed45acd4)
|
|
161
|
+
- update tap to version 9.0.1 (b6a451bd)
|
|
77
162
|
|
|
78
163
|
##### Documentation Changes
|
|
79
164
|
|
|
80
|
-
|
|
165
|
+
- **readme:** add more badges (b579c93e)
|
|
81
166
|
|
|
82
167
|
##### Other Changes
|
|
83
168
|
|
|
84
|
-
|
|
169
|
+
- **package:** revise package description (9bce29c5)
|
|
85
170
|
|
|
86
171
|
##### Tests
|
|
87
172
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
173
|
+
- **travis:** add fast_finish (78f14250)
|
|
174
|
+
- **appveyor:** initial test configuration (59186cf8)
|
package/README.md
CHANGED
|
@@ -1,61 +1,72 @@
|
|
|
1
1
|
# hexo-offline
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/hexo-offline)
|
|
3
|
-
|
|
4
|
-
[](https://ci.appveyor.com/project/JLHwung/hexo-offline)
|
|
4
|
+

|
|
5
5
|
[](https://coveralls.io/github/JLHwung/hexo-offline)
|
|
6
|
-
[](https://david-dm.org/JLHwung/hexo-offline)
|
|
7
|
-
[](https://david-dm.org/JLHwung/hexo-offline?type=dev)
|
|
8
6
|
|
|
9
|
-
hexo-offline is intended to provide offline experience for [hexo](https://hexo.io) built static website. It uses
|
|
7
|
+
hexo-offline is intended to provide [offline experience](https://web.dev/progressive-web-apps/) for [hexo](https://hexo.io) built static website. It uses _ServiceWorker_ under the hood. Simply install this plugin to your website and it should be offline ready by caching most of static assets.
|
|
8
|
+
|
|
9
|
+
See [here](https://github.com/JLHwung/hexo-offline/tree/v1) for v1 docs.
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
|
|
13
|
+
- [徑庭](https://jhuang.me)
|
|
10
14
|
|
|
11
15
|
## Install
|
|
16
|
+
|
|
12
17
|
```bash
|
|
13
18
|
npm i hexo-offline --save
|
|
14
19
|
```
|
|
20
|
+
|
|
15
21
|
Once installed, run `hexo clean && hexo generate` to activate offline experience.
|
|
16
22
|
|
|
17
23
|
## Usage
|
|
24
|
+
|
|
18
25
|
If the website serves all content from the origin server, you don't have to add any config. Simply install and run `hexo clean && hexo generate`.
|
|
19
26
|
|
|
20
|
-
While hexo-offline aims to provide zero-config offline enhancement to your hexo project, it does offer full list of options control from [
|
|
27
|
+
While hexo-offline aims to provide zero-config offline enhancement to your hexo project, it does offer full list of options control from [workbox-build](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build?hl=en#.generateSW). Create a `hexo-offline.config.cjs` in the hexo root directory
|
|
21
28
|
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
verbose: true
|
|
29
|
+
```js
|
|
30
|
+
// offline config passed to workbox-build.
|
|
31
|
+
module.exports = {
|
|
32
|
+
globPatterns: ["**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}"],
|
|
33
|
+
globDirectory: "/path/to/hexo/public",
|
|
34
|
+
swDest: "/path/to/hexo/service-worker.js",
|
|
35
|
+
},
|
|
30
36
|
```
|
|
31
37
|
|
|
32
|
-
Again, the config is
|
|
38
|
+
Again, the config is demo only and you don't have to copy and paste if you serves all contents from the origin server.
|
|
33
39
|
|
|
34
|
-
###
|
|
40
|
+
### What if content is served via CDN?
|
|
35
41
|
|
|
36
42
|
Suppose that you have used two CDN scripts:
|
|
43
|
+
|
|
37
44
|
```yaml
|
|
38
45
|
- https://cdn.example.com/script-name/script-version.js
|
|
39
46
|
- http://cdn.another-example.org/script-name/script-version.css
|
|
40
47
|
```
|
|
41
48
|
|
|
42
|
-
Add this config to root `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
Add this config to root `hexo-offline.config.cjs`
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// offline config passed to workbox-build.
|
|
53
|
+
module.exports = {
|
|
54
|
+
runtimeCaching: [
|
|
55
|
+
{
|
|
56
|
+
urlPattern: /^https:\/\/cdn\.example\.com\/.*/,
|
|
57
|
+
handler: "CacheFirst"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
urlPattern: /^https:\/\/cdn\.another-example\.org\/.*/,
|
|
61
|
+
handler: "CacheFirst"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
54
65
|
```
|
|
55
66
|
|
|
67
|
+
For more information, see [Workbox Runtime Caching Entry](https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build?hl=en#.RuntimeCachingEntry).
|
|
68
|
+
|
|
56
69
|
Note:
|
|
57
70
|
|
|
58
71
|
1. As the CDN resources is runtime cached, it means that the resource will be cached only after a user-agent visit the page where the resource is referenced. Therefore, if you have included a CDN resource `example.com/script.js` in `some-page.html` only, the user who visit `index.html` only would not have `example.com/script.js` in cache.
|
|
59
72
|
1. we use `cacheFirst` handler as CDN resources with specific version are not supposed to change in the future.
|
|
60
|
-
|
|
61
|
-
## [Demo](https://jhuang.me)
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var _lib = require(
|
|
4
|
-
|
|
5
|
-
var _lib2 = _interopRequireDefault(_lib);
|
|
3
|
+
var _lib = _interopRequireDefault(require("./lib"));
|
|
6
4
|
|
|
7
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
/* global hexo */
|
|
8
|
+
hexo.extend.filter.register("before_exit", _lib.default);
|
package/lib/lib/constants.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
6
|
+
exports.workerName = void 0;
|
|
7
|
+
const workerName = "service-worker.js";
|
|
8
|
+
exports.workerName = workerName;
|
package/lib/lib/index.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = _default;
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
var _this = this;
|
|
8
|
+
var _runWorkboxBuild = _interopRequireDefault(require("./run-workbox-build"));
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
return (0, _injectSwRegister2.default)(_this.public_dir);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
10
|
+
var _injectSwRegister = _interopRequireDefault(require("./inject-sw-register"));
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var _injectSwRegister2 = _interopRequireDefault(_injectSwRegister);
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
async function _default() {
|
|
15
|
+
await _runWorkboxBuild.default.call(this);
|
|
16
|
+
return (0, _injectSwRegister.default)(this.public_dir);
|
|
17
|
+
}
|
|
@@ -1,47 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _fs = require(
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _path2 = _interopRequireDefault(_path);
|
|
14
|
-
|
|
15
|
-
var _constants = require('./constants');
|
|
12
|
+
var _constants = require("./constants");
|
|
16
13
|
|
|
17
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
const template = _fs.default.readFileSync(_path.default.join(__dirname, "./template.js"), "utf-8");
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return `<script
|
|
18
|
+
const helperSWRegister = function () {
|
|
19
|
+
const registerContent = template.replace("__workerName__", _constants.workerName);
|
|
20
|
+
return `<script>${registerContent}</script>`;
|
|
24
21
|
};
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const injectSWRegisterWithContent = script => publicDir => {
|
|
24
|
+
const indexHTMLPath = _path.default.join(publicDir, "index.html"); // early return when no index.html presets in public directory
|
|
25
|
+
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
27
|
+
if (!_fs.default.existsSync(indexHTMLPath)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
34
30
|
|
|
35
|
-
|
|
31
|
+
const fileContent = _fs.default.readFileSync(indexHTMLPath, "utf-8"); // early return if it has been injected before
|
|
36
32
|
|
|
37
|
-
// early return if it has been injected before
|
|
38
|
-
if (fileContent.includes(`${ script }</body></html>`)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
34
|
+
if (fileContent.includes(`${script}</body></html>`)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const injectedContent = fileContent.replace(/<\/body>\s*<\/html>\s*$/, `${script}</body></html>`);
|
|
39
|
+
|
|
40
|
+
_fs.default.writeFileSync(indexHTMLPath, injectedContent);
|
|
45
41
|
};
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
var _default = injectSWRegisterWithContent(helperSWRegister());
|
|
44
|
+
|
|
45
|
+
exports.default = _default;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = runWorkboxBuild;
|
|
7
|
+
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
+
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
12
|
+
var _workboxBuild = require("workbox-build");
|
|
13
|
+
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function generateSWPrecacheConfig({
|
|
19
|
+
publicDir
|
|
20
|
+
}, extraWorkboxBuildConfig) {
|
|
21
|
+
const hexoPublicDir = publicDir;
|
|
22
|
+
return {
|
|
23
|
+
globPatterns: ["**/*.{js,mjs,html,css,png,jpg,gif,webp,svg,eot,ttf,woff,woff2}"],
|
|
24
|
+
globDirectory: hexoPublicDir,
|
|
25
|
+
swDest: _path.default.join(publicDir, _constants.workerName),
|
|
26
|
+
...extraWorkboxBuildConfig
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function formatNumber(number) {
|
|
31
|
+
try {
|
|
32
|
+
return new Intl.NumberFormat().format(number);
|
|
33
|
+
} catch {
|
|
34
|
+
return number;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function printSWResult({
|
|
39
|
+
count,
|
|
40
|
+
size,
|
|
41
|
+
warnings
|
|
42
|
+
}, logger) {
|
|
43
|
+
for (const warning of warnings) {
|
|
44
|
+
logger.warn(warnings);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
logger.info(`Generated manifests for ${formatNumber(count)} files. Total size: ${formatNumber(size)} bytes.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function runWorkboxBuild() {
|
|
51
|
+
const {
|
|
52
|
+
public_dir: publicDir,
|
|
53
|
+
base_dir: baseDir,
|
|
54
|
+
config,
|
|
55
|
+
log: logger
|
|
56
|
+
} = this; // early return when no index.html presets in public directory
|
|
57
|
+
|
|
58
|
+
const indexHTMLPath = _path.default.join(publicDir, "index.html");
|
|
59
|
+
|
|
60
|
+
if (!_fs.default.existsSync(indexHTMLPath)) {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let offline;
|
|
65
|
+
|
|
66
|
+
if ("offline" in config) {
|
|
67
|
+
logger.warn(`
|
|
68
|
+
Starting from hexo-offline v2 the 'offline' config in _config.yaml is
|
|
69
|
+
deprecated. Please create 'hexo-offline.config.cjs' in hexo root directory.
|
|
70
|
+
See https://github.com/JLHwung/hexo-offline#usage for more info.
|
|
71
|
+
`);
|
|
72
|
+
offline = config.offline;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
offline = require(_path.default.resolve(baseDir, "hexo-offline.config.cjs"));
|
|
77
|
+
} catch {}
|
|
78
|
+
|
|
79
|
+
const SWPrecacheConfig = generateSWPrecacheConfig({
|
|
80
|
+
publicDir
|
|
81
|
+
}, offline);
|
|
82
|
+
const result = await (0, _workboxBuild.generateSW)(SWPrecacheConfig);
|
|
83
|
+
printSWResult(result, logger);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
package/lib/lib/template.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";if("serviceWorker"in navigator){navigator.serviceWorker.register("__workerName__").then((function(reg){reg.onupdatefound=function(){var installingWorker=reg.installing;installingWorker.onstatechange=function(){switch(installingWorker.state){case"installed":if(navigator.serviceWorker.controller){console.log("New or updated content is available.")}else{console.log("Content is now available offline!")}break;case"redundant":console.error("The installing service worker became redundant.");break}}}}))["catch"]((function(e){console.error("Error during service worker registration:",e)}))}
|
package/package.json
CHANGED
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hexo-offline",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Out-of-the-box hexo offline experience",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "https://github.com/JLHwung/hexo-offline.git",
|
|
7
|
-
"author": "
|
|
7
|
+
"author": "Huáng Jùnliàng <hexo-offline@jhuang.me>",
|
|
8
8
|
"license": "BSD-2-Clause",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"clean": "rimraf lib",
|
|
11
|
-
"build:template": "babel src/lib/template.js --out-file lib/lib/template.js
|
|
10
|
+
"clean": "rimraf lib && rimraf run-workbox-build.spec",
|
|
11
|
+
"build:template": "babel src/lib/template.js --out-file lib/lib/template.js && terser lib/lib/template.js -o lib/lib/template.js",
|
|
12
12
|
"build:lib": "babel src --out-dir lib",
|
|
13
13
|
"build": "npm run build:lib && npm run build:template",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"spellcheck": "yaspeller .",
|
|
18
|
-
"prepublishOnly": "npm run lint && npm run test && npm run clean && npm run build"
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"spellcheck": "yaspeller-ci README.md",
|
|
16
|
+
"prepublishOnly": "npm run test && npm run clean && npm run build"
|
|
19
17
|
},
|
|
20
18
|
"dependencies": {
|
|
21
|
-
"
|
|
19
|
+
"workbox-build": "^6.4.2"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
24
|
-
"babel
|
|
25
|
-
"babel
|
|
26
|
-
"babel
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"rimraf": "^
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"yaspeller": "^3.0.0"
|
|
22
|
+
"@babel/cli": "^7.8.0",
|
|
23
|
+
"@babel/core": "^7.8.0",
|
|
24
|
+
"@babel/preset-env": "^7.8.0",
|
|
25
|
+
"husky": "^7.0.4",
|
|
26
|
+
"jest": "^27.4.7",
|
|
27
|
+
"lint-staged": "^12.1.5",
|
|
28
|
+
"prettier": "^2.5.1",
|
|
29
|
+
"rimraf": "^3.0.2",
|
|
30
|
+
"terser": "^5.10.0",
|
|
31
|
+
"yaspeller-ci": "^1.0.2"
|
|
35
32
|
},
|
|
36
33
|
"peerDependencies": {
|
|
37
|
-
"hexo": "^
|
|
34
|
+
"hexo": "^5.0.0 || ^6.0.0"
|
|
38
35
|
},
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=12"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"lib"
|
|
41
|
+
]
|
|
42
|
+
}
|
package/.babelrc
DELETED