@tenjuu99/blog 0.1.0 → 0.1.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/.env.prod.sample CHANGED
@@ -1,7 +1,7 @@
1
1
  SITE_NAME=test_blog
2
2
  GTAG_ID=
3
3
  URL_BASE=https://amashigeseiji.github.io/blog_template
4
- RELATIVE_PATH=/blog_template
4
+ RELATIVE_PATH=/tenjuu99-blog
5
5
  SRC_DIR=src-sample
6
6
  DIST_DIR=dist
7
7
  DISTRIBUTE_RAW=image
@@ -30,7 +30,7 @@ jobs:
30
30
  uses: actions/checkout@master
31
31
 
32
32
  - name: npm install
33
- run: npm install --production
33
+ run: npm install --omit=dev
34
34
 
35
35
  - name: Build
36
36
  run: cp .env.prod.sample .env && npm run generate
package/generate.js CHANGED
@@ -1,11 +1,2 @@
1
- "use strict"
2
- import distribute from './lib/distribute.js'
3
- import { indexing } from './lib/indexer.js'
4
- import { srcDir, distDir } from './lib/dir.js'
5
-
6
- const start = performance.now()
7
- const data = await indexing(srcDir + '/pages/')
8
-
9
- await distribute(data, srcDir, distDir)
10
- const end = performance.now()
11
- console.log('build: ' + (end - start) + "ms")
1
+ import generate from './lib/generate.js'
2
+ generate()
@@ -1,6 +1,6 @@
1
1
  "use strict"
2
2
  import fs from "node:fs/promises";
3
- import applyCss from './cssGenerator.js'
3
+ import { applyCss, watchCss } from './cssGenerator.js'
4
4
  import {
5
5
  replaceIfFilter,
6
6
  replaceScriptFilter,
@@ -8,9 +8,10 @@ import {
8
8
  includeFilter
9
9
  } from './filter.js'
10
10
  import { marked } from "marked";
11
- import { templateDir } from './dir.js'
11
+ import { templateDir, cssDir } from './dir.js'
12
+ import chokidar from 'chokidar'
12
13
 
13
- const templates = {}
14
+ let templates = {}
14
15
 
15
16
  const applyTemplate = async (name = 'default.html') => {
16
17
  if (templates[name]) {
@@ -38,4 +39,11 @@ const render = async (templateName, data) => {
38
39
  return replaceVariablesFilter(template, data)
39
40
  }
40
41
 
41
- export default render
42
+ const watchTemplate = () => {
43
+ chokidar.watch([cssDir, templateDir]).on('change', () => {
44
+ templates = {}
45
+ })
46
+ watchCss()
47
+ }
48
+
49
+ export { render, watchTemplate }
@@ -4,8 +4,9 @@ import { minifyCss } from './minify.js'
4
4
  import { createHash } from 'crypto'
5
5
  import path from 'path'
6
6
  import { distDir as distRoot, cssDir } from './dir.js'
7
+ import chokidar from 'chokidar'
7
8
 
8
- const cacheBuster = {}
9
+ let cacheBuster = {}
9
10
  const cacheBusterQuery = 't'
10
11
 
11
12
  /**
@@ -58,4 +59,10 @@ const applyCss = async (text) => {
58
59
  return text
59
60
  }
60
61
 
61
- export default applyCss
62
+ const watchCss = () => {
63
+ chokidar.watch([cssDir]).on('change', (path) => {
64
+ cacheBuster = {}
65
+ })
66
+ }
67
+
68
+ export { applyCss, watchCss }
package/lib/dir.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const rootDir = process.cwd()
2
2
  const srcDir = `${rootDir}/${process.env.SRC_DIR}`
3
3
  const distDir = `${rootDir}/${process.env.DIST_DIR}`
4
- const templateDir = `${rootDir}/${process.env.SRC_DIR}/template`
5
- const cssDir = `${rootDir}/${process.env.SRC_DIR}/css`
4
+ const templateDir = `${srcDir}/template`
5
+ const cssDir = `${srcDir}/css`
6
6
  const cacheDir = `${rootDir}/.cache`
7
7
 
8
8
  export {
package/lib/distribute.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import fs from "node:fs/promises";
3
3
  import path from 'path'
4
4
  import { minifyHtml } from './minify.js'
5
- import render from './applyTemplate.js'
5
+ import { render, watchTemplate } from './applyTemplate.js'
6
6
 
7
7
  const distribute = async (data, srcDir, distDir) => {
8
8
  if (data['__deleted']) {
@@ -32,4 +32,4 @@ const distribute = async (data, srcDir, distDir) => {
32
32
  })
33
33
  }
34
34
 
35
- export default distribute
35
+ export { distribute, watchTemplate }
@@ -0,0 +1,15 @@
1
+ "use strict"
2
+ import { distribute } from './distribute.js'
3
+ import { indexing } from './indexer.js'
4
+ import { srcDir, distDir } from './dir.js'
5
+
6
+ const generate = async () => {
7
+ const start = performance.now()
8
+ const data = await indexing(srcDir + '/pages/')
9
+
10
+ await distribute(data, srcDir, distDir)
11
+ const end = performance.now()
12
+ console.log('build: ' + (end - start) + "ms")
13
+ }
14
+
15
+ export default generate
package/package.json CHANGED
@@ -1,40 +1,26 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "build": "npm run generate && npm run serve",
8
7
  "serve": "eval $(cat .env | tr \"\n\" \" \") node server.js",
9
8
  "generate": "eval $(cat .env | tr \"\n\" \" \") node generate.js",
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "watch": "npm-watch build"
9
+ "test": "echo \"Error: no test specified\" && exit 1"
12
10
  },
13
- "watch": {
14
- "build": {
15
- "patterns": [
16
- "src/",
17
- "src-sample/",
18
- "../src/",
19
- "helper/",
20
- "lib/",
21
- "generate.js"
22
- ],
23
- "extensions": "html,md,css,js",
24
- "quite": true
25
- }
11
+ "bin": {
12
+ "generate": "generate.js",
13
+ "server": "server.js"
26
14
  },
27
15
  "author": "AmashigeSeiji",
28
16
  "repository": {
29
17
  "type": "git",
30
- "url": "git+https://github.com/amashigeseiji/blog_template.git"
18
+ "url": "git+https://github.com/amashigeseiji/tenjuu99-blog.git"
31
19
  },
32
20
  "license": "MIT",
33
21
  "dependencies": {
22
+ "chokidar": "^3.6.0",
34
23
  "marked": "^13.x"
35
24
  },
36
- "devDependencies": {
37
- "npm-watch": "^0.x"
38
- },
39
25
  "type": "module"
40
26
  }
package/server.js CHANGED
@@ -1,8 +1,16 @@
1
1
  import http from 'http'
2
2
  import url from 'url'
3
3
  import fs from 'node:fs/promises'
4
- import { distDir } from './lib/dir.js'
4
+ import { srcDir, distDir } from './lib/dir.js'
5
+ import chokidar from 'chokidar'
6
+ import generate from './lib/generate.js'
7
+ import { watchTemplate } from './lib/applyTemplate.js'
5
8
 
9
+ chokidar.watch(srcDir).on('change', (event, path) => {
10
+ generate()
11
+ })
12
+ watchTemplate()
13
+ generate()
6
14
  const contentType = (ext) => {
7
15
  switch (ext) {
8
16
  case 'html':
@@ -3,3 +3,4 @@ title: abc
3
3
  url: /abc
4
4
  published: 2024-08-31
5
5
  ---
6
+ hoge