@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
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
|
|
39
|
-
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from 'http'
|
|
2
|
-
import fs from 'node:fs
|
|
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
|
-
|
|
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]
|
|
@@ -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
|
+
}
|