@tenjuu99/blog 0.2.6 → 0.2.7
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 +2 -1
- package/lib/pageData.js +1 -0
- package/lib/server.js +1 -1
- package/package.json +1 -1
- package/src-sample/js/editor.js +13 -5
- package/src-sample/js/error.js +7 -0
- package/src-sample/pages/500.md +5 -0
- package/src-sample/pages/editor.md +2 -0
- package/src-sample/pages/notfound.md +1 -0
- package/src-sample/server/get_editor_target.js +5 -1
- package/src-sample/server/preview.js +6 -0
- package/src-sample/template/default.html +4 -1
- package/src-sample/template/editor.html +1 -3
package/bin/dev-server
CHANGED
|
@@ -9,6 +9,7 @@ import { fileURLToPath } from 'url';
|
|
|
9
9
|
|
|
10
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
11
|
const libDir = path.dirname(__filename) + '/../lib/'
|
|
12
|
+
const binDir = path.dirname(__filename) + '/../bin/'
|
|
12
13
|
|
|
13
14
|
watchers.push({
|
|
14
15
|
paths: srcDir,
|
|
@@ -38,7 +39,7 @@ watch()
|
|
|
38
39
|
let childProcess = null
|
|
39
40
|
|
|
40
41
|
const proceed = () => {
|
|
41
|
-
const child = spawn('node', [
|
|
42
|
+
const child = spawn('node', [`${binDir}server`])
|
|
42
43
|
console.log(`start process. PID(parent): ${process.pid}, PID(child): ${child.pid}`)
|
|
43
44
|
|
|
44
45
|
child.stdout.on('data', (data) => {
|
package/lib/pageData.js
CHANGED
|
@@ -24,6 +24,7 @@ const parse = (content, name, ext) => {
|
|
|
24
24
|
site_name: config.site_name,
|
|
25
25
|
url_base: config.url_base,
|
|
26
26
|
markdown: markdownReplaced,
|
|
27
|
+
markdown_not_parsed: markdownReplaced,
|
|
27
28
|
relative_path: config.relative_path || '',
|
|
28
29
|
template: 'default.html',
|
|
29
30
|
ext: 'html',
|
package/lib/server.js
CHANGED
|
@@ -61,7 +61,7 @@ const server = () => {
|
|
|
61
61
|
} catch (e) {
|
|
62
62
|
console.log(e)
|
|
63
63
|
console.log(styleText('red', `[${request.method}] 500`), request.url)
|
|
64
|
-
const errorContent = fs.readFileSync(`${distDir}/
|
|
64
|
+
const errorContent = fs.readFileSync(`${distDir}/500.html`)
|
|
65
65
|
response.writeHead(500)
|
|
66
66
|
response.end(errorContent)
|
|
67
67
|
}
|
package/package.json
CHANGED
package/src-sample/js/editor.js
CHANGED
|
@@ -3,8 +3,15 @@ const sleep = waitTime => new Promise( resolve => setTimeout(resolve, waitTime)
|
|
|
3
3
|
const fetchData = (target) => {
|
|
4
4
|
return fetch(`/get_editor_target?md=${target}`)
|
|
5
5
|
.then(async res => {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
if (!res.ok) {
|
|
7
|
+
document.querySelector('#inputFileName').value = target
|
|
8
|
+
document.querySelector('#editorTextArea').value = `${target.split('.')[0]}についての記事を作成しましょう`
|
|
9
|
+
// submit('/preview', form)
|
|
10
|
+
throw new Error(`${target} does not exist.`)
|
|
11
|
+
} else {
|
|
12
|
+
const json = await res.json()
|
|
13
|
+
return json
|
|
14
|
+
}
|
|
8
15
|
})
|
|
9
16
|
}
|
|
10
17
|
const onloadFunction = async (e) => {
|
|
@@ -22,6 +29,9 @@ const onloadFunction = async (e) => {
|
|
|
22
29
|
inputFileName.value = json.filename
|
|
23
30
|
inputFileName.setAttribute('disabled', true)
|
|
24
31
|
submit('/preview', form)
|
|
32
|
+
}).catch(e => {
|
|
33
|
+
console.log('error!!!')
|
|
34
|
+
console.log(e)
|
|
25
35
|
})
|
|
26
36
|
}
|
|
27
37
|
select.addEventListener('change', async (event) => {
|
|
@@ -51,7 +61,7 @@ const onloadFunction = async (e) => {
|
|
|
51
61
|
formData.forEach((v, k) => {
|
|
52
62
|
obj[k] = v
|
|
53
63
|
})
|
|
54
|
-
fetch(fetchUrl, {
|
|
64
|
+
return fetch(fetchUrl, {
|
|
55
65
|
method: 'post',
|
|
56
66
|
body: JSON.stringify(obj)
|
|
57
67
|
}).then(async response => {
|
|
@@ -94,13 +104,11 @@ const sidebarToggle = (e) => {
|
|
|
94
104
|
main.classList.toggle('sidebar-close')
|
|
95
105
|
})
|
|
96
106
|
const hamburger = document.querySelector('.hamburger-menu input[type="checkbox"]')
|
|
97
|
-
console.log(hamburger)
|
|
98
107
|
hamburger.addEventListener('change', (e) => {
|
|
99
108
|
main.classList.toggle('sidebar-close')
|
|
100
109
|
})
|
|
101
110
|
}
|
|
102
111
|
document.addEventListener('DOMContentLoaded', (event) => {
|
|
103
|
-
console.log(event)
|
|
104
112
|
onloadFunction(event)
|
|
105
113
|
sidebarToggle(event)
|
|
106
114
|
})
|
|
@@ -17,7 +17,11 @@ export const get = async (req, res) => {
|
|
|
17
17
|
}
|
|
18
18
|
const file = `${pageDir}/${target}`
|
|
19
19
|
if (!fs.existsSync(`${file}`)) {
|
|
20
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
status: 404,
|
|
22
|
+
contentType: 'application/json',
|
|
23
|
+
body: JSON.stringify({ content: '', filename: target })
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
const f = fs.readFileSync(`${file}`, 'utf8')
|
|
23
27
|
return {
|
|
@@ -16,6 +16,12 @@ export const post = async (req, res) => {
|
|
|
16
16
|
.on('end', async () => {
|
|
17
17
|
const json = JSON.parse(chunks.join())
|
|
18
18
|
const filename = json.inputFileName ? json.inputFileName : json.selectDataFile
|
|
19
|
+
if (!filename) {
|
|
20
|
+
res.writeHead(400, { 'content-type': 'application/json' })
|
|
21
|
+
return res.end(JSON.stringify({
|
|
22
|
+
message: 'filename is requried.'
|
|
23
|
+
}))
|
|
24
|
+
}
|
|
19
25
|
const pageData = makePageData(filename, json.content)
|
|
20
26
|
const rendered = await render(pageData.template, pageData)
|
|
21
27
|
res.writeHead(200, { 'content-type': 'application/json' })
|
|
@@ -48,10 +48,13 @@
|
|
|
48
48
|
</main>
|
|
49
49
|
{if isEditorEnabled() }
|
|
50
50
|
<div class="container">
|
|
51
|
-
<a href="/editor?md={{name}}.{{__filetype}}">編集する</a>
|
|
51
|
+
<a href="/editor?md={{name}}.{{__filetype}}" class="editor_link">編集する</a>
|
|
52
52
|
</div>
|
|
53
53
|
{/if}
|
|
54
54
|
|
|
55
55
|
{include('template/footer.html')}
|
|
56
|
+
{if add_script}
|
|
57
|
+
<script src="{{ADD_SCRIPT}}" async></script>
|
|
58
|
+
{/if}
|
|
56
59
|
</body>
|
|
57
60
|
</html>
|