@tenjuu99/blog 0.2.15 → 0.2.16

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
@@ -61,3 +61,7 @@ const proceed = () => {
61
61
  }
62
62
 
63
63
  childProcess = proceed()
64
+
65
+ process.on('exit', () => {
66
+ childProcess.kill('SIGINT')
67
+ })
package/lib/dir.js CHANGED
@@ -68,10 +68,16 @@ const resolveDestinationPath = (path) => {
68
68
  }
69
69
  }
70
70
  watchers.push({
71
- paths: [srcDir],
71
+ paths: [srcDir, packageDir, packageDirCore],
72
72
  event: ['change', 'add', 'unlink'],
73
73
  callback: ( path ) => {
74
74
  const dest = resolveDestinationPath(path)
75
+ if (!dest) {
76
+ console.log(styleText('red', `[watcher] cannot resolve destination path: ${path}`))
77
+ alreadyCached = false
78
+ cache()
79
+ return true
80
+ }
75
81
  if (fs.existsSync(path)) {
76
82
  fs.cpSync(path, dest, { force: true })
77
83
  console.log(styleText('blue', `update ${path} => ${dest}`))
package/lib/server.js CHANGED
@@ -35,8 +35,9 @@ const server = () => {
35
35
  return http.createServer(async (request, response) => {
36
36
  request.setEncoding('utf8')
37
37
  const url = new URL(`http://${request.headers.host}${request.url}`)
38
- const isIndex = url.pathname.match(/(.+)?\/$/)
39
- let path = isIndex ? `${url.pathname}index.html` : decodeURIComponent(url.pathname)
38
+ const urlPathNameDecoded = decodeURIComponent(url.pathname)
39
+ const isIndex = urlPathNameDecoded.match(/(.+)?\/$/)
40
+ let path = isIndex ? `${urlPathNameDecoded}index.html` : urlPathNameDecoded
40
41
  if (!path.includes('.')) {
41
42
  const result = await handle(path, request, response)
42
43
  if (result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http'
2
- import fs from 'node:fs/promises'
2
+ import fs from 'node:fs'
3
3
  import { styleText } from 'node:util'
4
4
  import config from '@tenjuu99/blog/lib/config.js'
5
5
  import { watch } from '@tenjuu99/blog/lib/dir.js'
@@ -24,7 +24,13 @@ export const post = async (req, res) => {
24
24
  }))
25
25
  return
26
26
  }
27
- await fs.writeFile(`${watch.pageDir}/${file}`, json.content)
27
+ const filenameSplitted = file.split('/')
28
+ const filename = filenameSplitted.pop()
29
+ const dir = [watch.pageDir, ...filenameSplitted].join('/')
30
+ if (!fs.existsSync(dir)) {
31
+ fs.mkdirSync(dir, { recursive: true })
32
+ }
33
+ fs.writeFileSync(`${dir}/${filename}`, json.content)
28
34
  console.log(styleText('blue', '[editor/post] finished'))
29
35
 
30
36
  const href = file.split('.')[0]
@@ -58,9 +58,6 @@ header a, header a:visited {
58
58
 
59
59
  main {
60
60
  flex-grow: 1;
61
- display: flex;
62
- flex-direction: column;
63
- justify-content: space-between;
64
61
  }
65
62
 
66
63
  footer {
@@ -118,3 +118,21 @@ export function renderIndex(pages, nodate = 'nodate', headingTag = 'h3') {
118
118
  export function isEditorEnabled() {
119
119
  return allData.editor && allData.editor.distribute
120
120
  }
121
+
122
+ export function breadcrumbList(pageName) {
123
+ const pageData = allData[pageName]
124
+ const breadCrumbs = ['/']
125
+ pageData.url.split('/').reduce((prev, curr) => {
126
+ breadCrumbs.push([`/${prev}${curr}/`, curr])
127
+ return `${prev}${curr}/`
128
+ })
129
+ const last = breadCrumbs.pop()
130
+ last[0] = last[0].substring(0, last[0].length - 1)
131
+
132
+ const output = breadCrumbs.map(v => {
133
+ return `<div style="margin-left: 10px;"><a href="${v[0]}">${v[0] === '/' ? 'top' : v[1]}</a> > </div>`
134
+ }).join('') + `<div style="margin-left: 10px;">${last[1]}</div>`
135
+ return '<div style="display: flex;flex-wrap: wrap;">'
136
+ + output
137
+ + '</div>'
138
+ }
@@ -28,6 +28,9 @@
28
28
  <p class="container"><a href="{{RELATIVE_PATH}}/">{{SITE_NAME}}</a></p>
29
29
  </header>
30
30
  <main>
31
+ <div class="container">
32
+ {{ breadcrumbList(name) }}
33
+ </div>
31
34
  <article class="container">
32
35
  <h1>{{TITLE}}</h1>
33
36
  {if published != '1970-01-01'}