@tenjuu99/blog 0.2.32 → 0.2.33

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/bin/dev-server CHANGED
@@ -6,6 +6,7 @@ import { watchers, watch } from '../lib/watcher.js'
6
6
  import generate from '../lib/generate.js'
7
7
  import path from 'path'
8
8
  import { fileURLToPath } from 'url';
9
+ import { warmUpTemplateCallback } from '../lib/applyTemplate.js'
9
10
 
10
11
  const __filename = fileURLToPath(import.meta.url);
11
12
  const libDir = path.dirname(__filename) + '/../lib/'
@@ -14,8 +15,9 @@ const binDir = path.dirname(__filename) + '/../bin/'
14
15
  watchers.push({
15
16
  paths: [srcDir],
16
17
  event: ['change', 'add', 'unlink'],
17
- callback: (path) => {
18
+ callback: async (path) => {
18
19
  watchCallback(path)
20
+ await warmUpTemplateCallback()
19
21
  generate()
20
22
  },
21
23
  watchOptions: {
@@ -6,6 +6,7 @@ import { staticFile, staticFiles, warmUp, reload } from './files.js'
6
6
  import { watchers } from './watcher.js'
7
7
 
8
8
  let templates = {}
9
+ let loaded = false
9
10
 
10
11
  const applyTemplate = async (name = 'default.html') => {
11
12
  if (templates[name]) {
@@ -19,20 +20,24 @@ const applyTemplate = async (name = 'default.html') => {
19
20
  }
20
21
 
21
22
  const warmUpTemplate = async () => {
23
+ if (loaded) {
24
+ console.log('template is already warmed up.')
25
+ return
26
+ }
27
+ console.log('warming up template')
22
28
  await warmUp()
23
29
  const templates = staticFiles()
24
30
  .filter(file => file[0].indexOf('template/') === 0)
25
31
  .map(f => applyTemplate(f[0].split('/')[1]))
26
32
  await Promise.all(templates)
33
+ loaded = true
27
34
  }
28
35
 
29
- watchers.push({
30
- paths: [watch.cssDir, watch.templateDir],
31
- callback: async () => {
32
- templates = {}
33
- await reload()
34
- await warmUpTemplate()
35
- }
36
- })
36
+ const warmUpTemplateCallback = async () => {
37
+ templates = {}
38
+ loaded = false
39
+ await reload()
40
+ await warmUpTemplate()
41
+ }
37
42
 
38
- export { applyTemplate, warmUpTemplate }
43
+ export { applyTemplate, warmUpTemplate, warmUpTemplateCallback }
package/lib/distribute.js CHANGED
@@ -7,7 +7,7 @@ import render from './render.js'
7
7
  import { styleText } from 'node:util'
8
8
  import config from './config.js'
9
9
  import { cacheDir } from './dir.js'
10
- import { applyTemplate, warmUpTemplate } from './applyTemplate.js'
10
+ import { applyTemplate } from './applyTemplate.js'
11
11
 
12
12
  const indexFile = `${cacheDir}/index.json`
13
13
 
@@ -17,7 +17,6 @@ const renderPage = async (page) => {
17
17
  }
18
18
 
19
19
  const distribute = async (data, srcDir, distDir) => {
20
- await warmUpTemplate()
21
20
  const promises = []
22
21
  const newIndex = []
23
22
  for (const name in data) {
package/lib/generate.js CHANGED
@@ -2,11 +2,16 @@
2
2
  import distribute from './distribute.js'
3
3
  import { indexing, allData } from './indexer.js'
4
4
  import { srcDir, distDir, cache } from './dir.js'
5
+ import { warmUpTemplate } from './applyTemplate.js'
5
6
  import { styleText } from 'node:util'
6
7
 
8
+ const beforeGenerate = async () => {
9
+ cache()
10
+ await warmUpTemplate()
11
+ }
7
12
  const generate = async () => {
8
13
  let start = performance.now()
9
- cache()
14
+ await beforeGenerate()
10
15
  await indexing()
11
16
  let end = performance.now()
12
17
  console.log(styleText('blue', '[indexing: ' + (end - start) + "ms]"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.32",
3
+ "version": "0.2.33",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {