@tenjuu99/blog 0.2.9 → 0.2.13
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 +8 -4
- package/bin/new +3 -2
- package/lib/applyTemplate.js +2 -2
- package/lib/config.js +2 -1
- package/lib/cssGenerator.js +2 -2
- package/lib/dir.js +75 -6
- package/lib/distribute.js +27 -18
- package/lib/files.js +2 -2
- package/lib/generate.js +2 -1
- package/package.json +1 -2
- package/src-sample/{js → packages/editor/js}/editor.js +4 -1
- package/src-sample/{js → packages/editor/js}/error.js +1 -1
- package/src-sample/{server → packages/editor/server}/editor.js +2 -2
- package/src-sample/template/default.html +0 -2
- /package/src-sample/{css → packages/editor/css}/editor.css +0 -0
- /package/src-sample/{pages → packages/editor/pages}/editor.md +0 -0
- /package/src-sample/{server → packages/editor/server}/get_editor_target.js +0 -0
- /package/src-sample/{server → packages/editor/server}/preview.js +0 -0
- /package/src-sample/{template → packages/editor/template}/editor.html +0 -0
package/bin/dev-server
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawn } from 'child_process'
|
|
4
|
-
import { srcDir,
|
|
4
|
+
import { srcDir, watch as watchDir } from '../lib/dir.js'
|
|
5
5
|
import { watchers, watch } from '../lib/watcher.js'
|
|
6
6
|
import generate from '../lib/generate.js'
|
|
7
7
|
import path from 'path'
|
|
@@ -14,12 +14,12 @@ const binDir = path.dirname(__filename) + '/../bin/'
|
|
|
14
14
|
watchers.push({
|
|
15
15
|
paths: srcDir,
|
|
16
16
|
watchOptions: {
|
|
17
|
-
ignored: [pageDir, serverDir, helperDir],
|
|
17
|
+
ignored: [watchDir.pageDir, watchDir.serverDir, watchDir.helperDir],
|
|
18
18
|
},
|
|
19
19
|
callback: generate
|
|
20
20
|
})
|
|
21
21
|
watchers.push({
|
|
22
|
-
paths: pageDir,
|
|
22
|
+
paths: watchDir.pageDir,
|
|
23
23
|
callback: generate,
|
|
24
24
|
watchOptions: {
|
|
25
25
|
ignoreInitial: true
|
|
@@ -27,7 +27,7 @@ watchers.push({
|
|
|
27
27
|
event: ['change', 'unlink', 'add']
|
|
28
28
|
})
|
|
29
29
|
watchers.push({
|
|
30
|
-
paths: [serverDir, helperDir, libDir],
|
|
30
|
+
paths: [watchDir.serverDir, watchDir.helperDir, libDir],
|
|
31
31
|
callback: () => {
|
|
32
32
|
childProcess.kill('SIGINT')
|
|
33
33
|
childProcess = proceed()
|
|
@@ -36,6 +36,10 @@ watchers.push({
|
|
|
36
36
|
})
|
|
37
37
|
watch()
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @type { import("child_process").ChildProcess }
|
|
41
|
+
* @var {ChildProcess} childProcess
|
|
42
|
+
*/
|
|
39
43
|
let childProcess = null
|
|
40
44
|
|
|
41
45
|
const proceed = () => {
|
package/bin/new
CHANGED
|
@@ -15,8 +15,9 @@ echo '{
|
|
|
15
15
|
"src_dir": "src",
|
|
16
16
|
"dist_dir": "dist",
|
|
17
17
|
"distribute_raw": "image,js",
|
|
18
|
-
"helper": "index.js",
|
|
19
|
-
"editor_enable": true
|
|
18
|
+
"helper": "index.js,add.js",
|
|
19
|
+
"editor_enable": true,
|
|
20
|
+
"packages": "editor"
|
|
20
21
|
}' > "$(pwd)/blog.json"
|
|
21
22
|
echo "create blog.json"
|
|
22
23
|
|
package/lib/applyTemplate.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
import applyCss from './cssGenerator.js'
|
|
3
3
|
import includeFilter from './includeFilter.js'
|
|
4
|
-
import {
|
|
4
|
+
import { watch } from './dir.js'
|
|
5
5
|
import { staticFile, staticFiles, warmUp } from './files.js'
|
|
6
6
|
import { watchers } from './watcher.js'
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ const warmUpTemplate = async () => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
watchers.push({
|
|
30
|
-
paths: [cssDir, templateDir],
|
|
30
|
+
paths: [watch.cssDir, watch.templateDir],
|
|
31
31
|
callback: () => { templates = {} }
|
|
32
32
|
})
|
|
33
33
|
|
package/lib/config.js
CHANGED
package/lib/cssGenerator.js
CHANGED
|
@@ -4,7 +4,7 @@ import { staticFile } from './files.js'
|
|
|
4
4
|
import { minifyCss } from './minify.js'
|
|
5
5
|
import { createHash } from 'crypto'
|
|
6
6
|
import path from 'path'
|
|
7
|
-
import { distDir,
|
|
7
|
+
import { distDir, watch } from './dir.js'
|
|
8
8
|
import { watchers } from './watcher.js'
|
|
9
9
|
import { styleText } from 'node:util'
|
|
10
10
|
import config from './config.js'
|
|
@@ -63,7 +63,7 @@ const applyCss = async (text) => {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
watchers.push({
|
|
66
|
-
paths: cssDir,
|
|
66
|
+
paths: watch.cssDir,
|
|
67
67
|
callback: () => { cacheBuster = {} }
|
|
68
68
|
})
|
|
69
69
|
|
package/lib/dir.js
CHANGED
|
@@ -1,15 +1,82 @@
|
|
|
1
1
|
import config from './config.js'
|
|
2
|
+
import { watchers } from './watcher.js'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import { styleText } from 'node:util'
|
|
2
5
|
|
|
3
6
|
const rootDir = process.cwd()
|
|
4
7
|
const srcDir = `${rootDir}/${config.src_dir}`
|
|
5
8
|
const distDir = `${rootDir}/${config.dist_dir}`
|
|
6
|
-
const pageDir = `${srcDir}/pages`
|
|
7
|
-
const templateDir = `${srcDir}/template`
|
|
8
|
-
const cssDir = `${srcDir}/css`
|
|
9
9
|
const cacheDir = `${rootDir}/.cache`
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const pageDir = `${cacheDir}/pages`
|
|
11
|
+
const templateDir = `${cacheDir}/template`
|
|
12
|
+
const cssDir = `${cacheDir}/css`
|
|
13
|
+
const serverDir = `${cacheDir}/server`
|
|
14
|
+
const helperDir = `${cacheDir}/helper`
|
|
15
|
+
const packageDir = `${srcDir}/packages`
|
|
16
|
+
const watch = {
|
|
17
|
+
pageDir: `${srcDir}/pages`,
|
|
18
|
+
templateDir: `${srcDir}/template`,
|
|
19
|
+
cssDir: `${srcDir}/css`,
|
|
20
|
+
serverDir: `${srcDir}/server`,
|
|
21
|
+
helperDir: `${srcDir}/helper`,
|
|
22
|
+
jsDir: `${srcDir}/js`,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let alreadyCached = false
|
|
12
26
|
|
|
27
|
+
const cache = () => {
|
|
28
|
+
if (alreadyCached) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
if (config.packages) {
|
|
32
|
+
const packages = config.packages.split(',')
|
|
33
|
+
packages.forEach(dir => {
|
|
34
|
+
if (!fs.existsSync(`${packageDir}/${dir}`)) {
|
|
35
|
+
throw new Error(`"${dir}" package does not exist.`)
|
|
36
|
+
}
|
|
37
|
+
console.log(styleText('blue', `[cache] enable package: ${dir}`))
|
|
38
|
+
fs.cpSync(`${packageDir}/${dir}`, cacheDir, { recursive: true })
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
fs.cpSync(srcDir, cacheDir, {
|
|
42
|
+
recursive: true,
|
|
43
|
+
force: true,
|
|
44
|
+
filter: (src, dist) => !src.startsWith(packageDir)
|
|
45
|
+
})
|
|
46
|
+
console.log(styleText('blue', '[cache] finish copy'))
|
|
47
|
+
alreadyCached = true
|
|
48
|
+
}
|
|
49
|
+
// import パスの解決の関係上、関数コールより前にファイルが読まれることがあるためここで呼んでおく
|
|
50
|
+
// 子プロセスで起動する場合は二度呼ばれることになる
|
|
51
|
+
// generate の中でもコールしているが、同一プロセスであれば alreadyCached 変数で制御される
|
|
52
|
+
cache()
|
|
53
|
+
|
|
54
|
+
const resolveDestinationPath = (path) => {
|
|
55
|
+
for (const key of Object.keys(watch)) {
|
|
56
|
+
if (path.startsWith(watch[key])) {
|
|
57
|
+
const dir = watch[key].split('/').pop()
|
|
58
|
+
const srcFile = `${dir}${path.replace(watch[key], '')}`
|
|
59
|
+
return `${cacheDir}/${srcFile}`
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
watchers.push({
|
|
64
|
+
paths: [srcDir],
|
|
65
|
+
event: ['change', 'add', 'unlink'],
|
|
66
|
+
callback: ( path ) => {
|
|
67
|
+
const dest = resolveDestinationPath(path)
|
|
68
|
+
if (fs.existsSync(path)) {
|
|
69
|
+
fs.cpSync(path, dest, { force: true })
|
|
70
|
+
console.log(styleText('blue', `update ${path} => ${dest}`))
|
|
71
|
+
} else {
|
|
72
|
+
fs.unlinkSync(dest)
|
|
73
|
+
console.log(styleText('red', `unlink ${dest}`))
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
watchOptions: {
|
|
77
|
+
ignoreInitial: true
|
|
78
|
+
}
|
|
79
|
+
})
|
|
13
80
|
export {
|
|
14
81
|
rootDir,
|
|
15
82
|
srcDir,
|
|
@@ -19,5 +86,7 @@ export {
|
|
|
19
86
|
cssDir,
|
|
20
87
|
cacheDir,
|
|
21
88
|
serverDir,
|
|
22
|
-
helperDir
|
|
89
|
+
helperDir,
|
|
90
|
+
watch,
|
|
91
|
+
cache
|
|
23
92
|
}
|
package/lib/distribute.js
CHANGED
|
@@ -38,11 +38,14 @@ const distribute = async (data, srcDir, distDir) => {
|
|
|
38
38
|
}
|
|
39
39
|
const distributeRaw = config.distribute_raw.split(',')
|
|
40
40
|
distributeRaw.forEach((copyDir) => {
|
|
41
|
-
|
|
41
|
+
if (!existsSync(`${cacheDir}/${copyDir}`)) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
fs.readdir(`${cacheDir}/${copyDir}/`).then(async files => {
|
|
42
45
|
await fs.stat(`${distDir}/${copyDir}/`).catch(async err => await fs.mkdir(`${distDir}/${copyDir}/`))
|
|
43
46
|
files.forEach(file => {
|
|
44
|
-
fs.copyFile(`${
|
|
45
|
-
console.log(styleText('green', '[copy]'), `${
|
|
47
|
+
fs.copyFile(`${cacheDir}/${copyDir}/${file}`, `${distDir}/${copyDir}/${file}`)
|
|
48
|
+
console.log(styleText('green', '[copy]'), `${cacheDir}/${copyDir}/${file} => ${distDir}/${copyDir}/${file}`)
|
|
46
49
|
})
|
|
47
50
|
})
|
|
48
51
|
})
|
|
@@ -50,22 +53,28 @@ const distribute = async (data, srcDir, distDir) => {
|
|
|
50
53
|
if (!existsSync(cacheDir)) {
|
|
51
54
|
mkdirSync(cacheDir)
|
|
52
55
|
}
|
|
53
|
-
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (existsSync(indexFile)) {
|
|
57
|
+
fs.readFile(indexFile, 'utf8')
|
|
58
|
+
.then(text => {
|
|
59
|
+
const oldIndex = JSON.parse(text)
|
|
60
|
+
let deleted = oldIndex.filter(oi => !newIndex.map(ni => ni.__output).includes(oi.__output))
|
|
61
|
+
fs.writeFile(indexFile, JSON.stringify(newIndex))
|
|
62
|
+
if (deleted) {
|
|
63
|
+
for (const obj of deleted) {
|
|
64
|
+
if (existsSync(`${distDir}${obj.__output}`)) {
|
|
65
|
+
console.log(styleText('red', '[unlink]'), `${distDir}${obj.__output}`)
|
|
66
|
+
fs.unlink(`${distDir}${obj.__output}`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
})
|
|
71
|
+
.catch(error => {
|
|
72
|
+
console.log(error)
|
|
73
|
+
fs.writeFile(indexFile, JSON.stringify(newIndex))
|
|
74
|
+
})
|
|
75
|
+
} else {
|
|
76
|
+
fs.writeFile(indexFile, JSON.stringify(newIndex))
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
export default distribute
|
package/lib/files.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
-
import { templateDir, cssDir } from './dir.js'
|
|
2
|
+
import { templateDir, cssDir, watch } from './dir.js'
|
|
3
3
|
import { watchers } from './watcher.js'
|
|
4
4
|
|
|
5
5
|
let staticFilesContainer = {}
|
|
@@ -33,7 +33,7 @@ const staticFiles = () => {
|
|
|
33
33
|
return Object.entries(staticFilesContainer)
|
|
34
34
|
}
|
|
35
35
|
watchers.push({
|
|
36
|
-
paths: [cssDir, templateDir],
|
|
36
|
+
paths: [watch.cssDir, watch.templateDir],
|
|
37
37
|
callback: async () => {
|
|
38
38
|
loaded = false
|
|
39
39
|
await warmUp()
|
package/lib/generate.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
import distribute from './distribute.js'
|
|
3
3
|
import { indexing, allData } from './indexer.js'
|
|
4
|
-
import { srcDir, distDir } from './dir.js'
|
|
4
|
+
import { srcDir, distDir, cache } from './dir.js'
|
|
5
5
|
import { styleText } from 'node:util'
|
|
6
6
|
|
|
7
7
|
const generate = async () => {
|
|
8
8
|
let start = performance.now()
|
|
9
|
+
cache()
|
|
9
10
|
await indexing()
|
|
10
11
|
let end = performance.now()
|
|
11
12
|
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.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "blog template",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"lib",
|
|
36
36
|
"bin",
|
|
37
|
-
"helper",
|
|
38
37
|
"src-sample"
|
|
39
38
|
],
|
|
40
39
|
"publishConfig": {
|
|
@@ -5,7 +5,10 @@ const fetchData = (target) => {
|
|
|
5
5
|
.then(async res => {
|
|
6
6
|
if (!res.ok) {
|
|
7
7
|
document.querySelector('#inputFileName').value = target
|
|
8
|
-
document.querySelector('#editorTextArea').value =
|
|
8
|
+
document.querySelector('#editorTextArea').value = `---
|
|
9
|
+
title: ${target.split('.')[0].split('/').pop()}
|
|
10
|
+
---
|
|
11
|
+
${target.split('.')[0].split('/').pop()} についての記事を作成しましょう`
|
|
9
12
|
// submit('/preview', form)
|
|
10
13
|
throw new Error(`${target} does not exist.`)
|
|
11
14
|
} else {
|
|
@@ -4,5 +4,5 @@ const url = new URL(location)
|
|
|
4
4
|
if (url.pathname !== '/editor') {
|
|
5
5
|
const link = document.querySelector('.editor_link')
|
|
6
6
|
link.href = `/editor?md=${url.pathname.replace('/', '')}.md`
|
|
7
|
-
link.innerHTML =
|
|
7
|
+
link.innerHTML = `[${decodeURI(url.pathname).replace('/', '')}]のページを作成する`
|
|
8
8
|
}
|
|
@@ -2,7 +2,7 @@ import { IncomingMessage, ServerResponse } from 'http'
|
|
|
2
2
|
import fs from 'node:fs/promises'
|
|
3
3
|
import { styleText } from 'node:util'
|
|
4
4
|
import config from '@tenjuu99/blog/lib/config.js'
|
|
5
|
-
import {
|
|
5
|
+
import { watch } from '@tenjuu99/blog/lib/dir.js'
|
|
6
6
|
|
|
7
7
|
export const path = '/editor'
|
|
8
8
|
|
|
@@ -24,7 +24,7 @@ export const post = async (req, res) => {
|
|
|
24
24
|
}))
|
|
25
25
|
return
|
|
26
26
|
}
|
|
27
|
-
await fs.writeFile(`${pageDir}/${file}`, json.content)
|
|
27
|
+
await fs.writeFile(`${watch.pageDir}/${file}`, json.content)
|
|
28
28
|
console.log(styleText('blue', '[editor/post] finished'))
|
|
29
29
|
|
|
30
30
|
const href = file.split('.')[0]
|
|
@@ -12,9 +12,7 @@
|
|
|
12
12
|
{if og_image}
|
|
13
13
|
<meta property="og:image" content="{{OG_IMAGE}}">
|
|
14
14
|
{/if}
|
|
15
|
-
{if og_description}
|
|
16
15
|
<meta property="og:description" content="{{OG_DESCRIPTION}}">
|
|
17
|
-
{/if}
|
|
18
16
|
<meta property="og:type" content="article">
|
|
19
17
|
<meta property="og:site_name" content="{{SITE_NAME}}">
|
|
20
18
|
{script}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|