@tenjuu99/blog 0.2.8 → 0.2.12
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/README.md +1 -1
- package/bin/dev-server +9 -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 +36 -6
- package/lib/distribute.js +10 -5
- package/lib/files.js +2 -2
- package/lib/filter.js +1 -32
- package/lib/render.js +2 -2
- package/package.json +1 -2
- package/src-sample/helper/add.js +3 -0
- package/src-sample/helper/index.js +1 -5
- 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/README.md
CHANGED
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 = () => {
|
|
@@ -50,6 +54,7 @@ const proceed = () => {
|
|
|
50
54
|
})
|
|
51
55
|
child.on('exit', (code, signal) => {
|
|
52
56
|
console.error(`process exit: ${code}, SIGNAL: ${signal}`);
|
|
57
|
+
child.kill('SIGINT')
|
|
53
58
|
})
|
|
54
59
|
|
|
55
60
|
return child
|
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,44 @@
|
|
|
1
1
|
import config from './config.js'
|
|
2
|
+
import { watchers } from './watcher.js'
|
|
3
|
+
import fs from 'node:fs'
|
|
2
4
|
|
|
3
5
|
const rootDir = process.cwd()
|
|
4
6
|
const srcDir = `${rootDir}/${config.src_dir}`
|
|
5
7
|
const distDir = `${rootDir}/${config.dist_dir}`
|
|
6
|
-
const pageDir = `${srcDir}/pages`
|
|
7
|
-
const templateDir = `${srcDir}/template`
|
|
8
|
-
const cssDir = `${srcDir}/css`
|
|
9
8
|
const cacheDir = `${rootDir}/.cache`
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const pageDir = `${cacheDir}/pages`
|
|
10
|
+
const templateDir = `${cacheDir}/template`
|
|
11
|
+
const cssDir = `${cacheDir}/css`
|
|
12
|
+
const serverDir = `${cacheDir}/server`
|
|
13
|
+
const helperDir = `${cacheDir}/helper`
|
|
14
|
+
const packageDir = `${srcDir}/packages`
|
|
15
|
+
const watch = {
|
|
16
|
+
pageDir: `${srcDir}/pages`,
|
|
17
|
+
templateDir: `${srcDir}/template`,
|
|
18
|
+
cssDir: `${srcDir}/css`,
|
|
19
|
+
serverDir: `${srcDir}/server`,
|
|
20
|
+
helperDir: `${srcDir}/helper`,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const cache = () => {
|
|
24
|
+
if (config.packages) {
|
|
25
|
+
const packages = config.packages.split(',')
|
|
26
|
+
packages.forEach(dir => {
|
|
27
|
+
if (!fs.existsSync(`${packageDir}/${dir}`)) {
|
|
28
|
+
throw new Error(`"${dir}" package does not exist.`)
|
|
29
|
+
}
|
|
30
|
+
fs.cpSync(`${packageDir}/${dir}`, cacheDir, { recursive: true })
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
fs.cpSync(srcDir, cacheDir, { recursive: true, force: true })
|
|
34
|
+
}
|
|
35
|
+
cache()
|
|
12
36
|
|
|
37
|
+
watchers.push({
|
|
38
|
+
paths: [srcDir],
|
|
39
|
+
event: ['change', 'add', 'unlink'],
|
|
40
|
+
callback: cache
|
|
41
|
+
})
|
|
13
42
|
export {
|
|
14
43
|
rootDir,
|
|
15
44
|
srcDir,
|
|
@@ -19,5 +48,6 @@ export {
|
|
|
19
48
|
cssDir,
|
|
20
49
|
cacheDir,
|
|
21
50
|
serverDir,
|
|
22
|
-
helperDir
|
|
51
|
+
helperDir,
|
|
52
|
+
watch
|
|
23
53
|
}
|
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
|
})
|
|
@@ -57,8 +60,10 @@ const distribute = async (data, srcDir, distDir) => {
|
|
|
57
60
|
fs.writeFile(indexFile, JSON.stringify(newIndex))
|
|
58
61
|
if (deleted) {
|
|
59
62
|
for (const obj of deleted) {
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
if (existsSync(`${distDir}${obj.__output}`)) {
|
|
64
|
+
console.log(styleText('red', '[unlink]'), `${distDir}${obj.__output}`)
|
|
65
|
+
fs.unlink(`${distDir}${obj.__output}`)
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
})
|
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/filter.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import helper from '../lib/helper.js'
|
|
2
|
-
import { srcDir } from './dir.js'
|
|
3
|
-
import config from './config.js'
|
|
4
|
-
import replaceVariablesFilter from './replaceVariablesFilter.js'
|
|
5
2
|
|
|
6
3
|
/**
|
|
7
4
|
* @param {string} condition
|
|
@@ -84,30 +81,6 @@ const replaceIfFilter = (text, variables) => {
|
|
|
84
81
|
return text
|
|
85
82
|
}
|
|
86
83
|
|
|
87
|
-
/**
|
|
88
|
-
* 配列を再帰的に順不同リストに変換する
|
|
89
|
-
* @param {Array|string} arrayOrText
|
|
90
|
-
* @returns {mixed}
|
|
91
|
-
*/
|
|
92
|
-
const arrayToList = (arrayOrText) => {
|
|
93
|
-
if (typeof arrayOrText === 'string') {
|
|
94
|
-
return `<li>${arrayOrText}</li>`
|
|
95
|
-
}
|
|
96
|
-
if (Array.isArray(arrayOrText)) {
|
|
97
|
-
let resultListText = '<ul>'
|
|
98
|
-
for (const item of arrayOrText) {
|
|
99
|
-
if (Array.isArray(item)) {
|
|
100
|
-
resultListText += `<li>${arrayToList(item)}</li>`
|
|
101
|
-
} else {
|
|
102
|
-
resultListText += `<li>${item}</li>`
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
resultListText += '</ul>'
|
|
106
|
-
arrayOrText = resultListText
|
|
107
|
-
}
|
|
108
|
-
return arrayOrText
|
|
109
|
-
}
|
|
110
|
-
|
|
111
84
|
const replaceScriptFilter = async (text, variables) => {
|
|
112
85
|
let replaced = text
|
|
113
86
|
const scriptRegexp = new RegExp(/({script}|\<script\s.*type="ssg".*>)(?<script>[\s\S]*?)(\{\/script}|\<\/script>)/g)
|
|
@@ -127,9 +100,6 @@ const replaceScriptFilter = async (text, variables) => {
|
|
|
127
100
|
case 'null':
|
|
128
101
|
result = ''
|
|
129
102
|
}
|
|
130
|
-
if (Array.isArray(result)) {
|
|
131
|
-
result = helper.arrayToList(result)
|
|
132
|
-
}
|
|
133
103
|
replaced = replaced.replace(script.replace, result)
|
|
134
104
|
}
|
|
135
105
|
return replaced
|
|
@@ -137,6 +107,5 @@ const replaceScriptFilter = async (text, variables) => {
|
|
|
137
107
|
|
|
138
108
|
export {
|
|
139
109
|
replaceIfFilter,
|
|
140
|
-
replaceScriptFilter
|
|
141
|
-
replaceVariablesFilter
|
|
110
|
+
replaceScriptFilter
|
|
142
111
|
}
|
package/lib/render.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
replaceIfFilter,
|
|
3
|
-
replaceScriptFilter
|
|
4
|
-
replaceVariablesFilter
|
|
3
|
+
replaceScriptFilter
|
|
5
4
|
} from './filter.js'
|
|
5
|
+
import replaceVariablesFilter from './replaceVariablesFilter.js'
|
|
6
6
|
import includeFilter from './includeFilter.js'
|
|
7
7
|
import { marked } from "marked";
|
|
8
8
|
import { applyTemplate } from './applyTemplate.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenjuu99/blog",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
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": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { allData } from '@tenjuu99/blog/lib/indexer.js'
|
|
2
|
-
import
|
|
2
|
+
import replaceVariablesFilter from '@tenjuu99/blog/lib/replaceVariablesFilter.js'
|
|
3
3
|
import config from '@tenjuu99/blog/lib/config.js'
|
|
4
4
|
|
|
5
5
|
export function readIndex (filter = null) {
|
|
@@ -115,10 +115,6 @@ export function renderIndex(pages, nodate = 'nodate', headingTag = 'h3') {
|
|
|
115
115
|
return resultText.join('\n')
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export function additionalHelper() {
|
|
119
|
-
return 'これは追加ヘルパーによって出力されているメッセージです。'
|
|
120
|
-
}
|
|
121
|
-
|
|
122
118
|
export function isEditorEnabled() {
|
|
123
119
|
return allData.editor && allData.editor.distribute
|
|
124
120
|
}
|
|
@@ -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
|