@tenjuu99/blog 0.2.9 → 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/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, pageDir, serverDir, helperDir } from '../lib/dir.js'
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
 
@@ -1,7 +1,7 @@
1
1
  "use strict"
2
2
  import applyCss from './cssGenerator.js'
3
3
  import includeFilter from './includeFilter.js'
4
- import { templateDir, cssDir } from './dir.js'
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
@@ -8,7 +8,8 @@ const config = {
8
8
  "dist_dir": "dist",
9
9
  "distribute_raw": "image",
10
10
  "relative_path": "",
11
- "helper": ""
11
+ "helper": "",
12
+ "package": ""
12
13
  }
13
14
  try {
14
15
  const file = rootDir + '/blog.json'
@@ -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, cssDir } from './dir.js'
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 serverDir = `${srcDir}/server`
11
- const helperDir = `${srcDir}/helper`
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
- fs.readdir(`${srcDir}/${copyDir}/`).then(async files => {
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(`${srcDir}/${copyDir}/${file}`, `${distDir}/${copyDir}/${file}`)
45
- console.log(styleText('green', '[copy]'), `${srcDir}/${copyDir}/${file} => ${distDir}/${copyDir}/${file}`)
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
- console.log(styleText('red', '[unlink]'), `${distDir}${obj.__output}`)
61
- fs.unlink(`${distDir}${obj.__output}`)
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.9",
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": {
@@ -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 = `${target.split('.')[0]}についての記事を作成しましょう`
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 = `${url.pathname.replace('/', '')}のページを作成する`
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 { pageDir } from '@tenjuu99/blog/lib/dir.js'
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}