@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 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', ['bin/server'])
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}/404.html`)
64
+ const errorContent = fs.readFileSync(`${distDir}/500.html`)
65
65
  response.writeHead(500)
66
66
  response.end(errorContent)
67
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- const json = await res.json()
7
- return json
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
  })
@@ -0,0 +1,7 @@
1
+ document.addEventListener('DOMContentLoaded', (e) => {
2
+ })
3
+ const url = new URL(location)
4
+ if (url.pathname !== '/editor') {
5
+ const link = document.querySelector('.editor_link')
6
+ link.href = `/editor?md=${url.pathname.replace('/', '')}.md`
7
+ }
@@ -0,0 +1,5 @@
1
+ ---
2
+ index: false
3
+ noindex: true
4
+ ---
5
+ 問題が発生しました。
@@ -3,3 +3,5 @@ template: editor.html
3
3
  index: false
4
4
  distribute: config.editor_enable
5
5
  ---
6
+
7
+ 新規に記事を作成しましょう。
@@ -3,6 +3,7 @@ title: 404 not found
3
3
  url: /404
4
4
  index: false
5
5
  noindex: true
6
+ add_script: /js/error.js
6
7
  ---
7
8
 
8
9
  記事が見つかりませんでした。
@@ -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 false
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>
@@ -42,9 +42,7 @@
42
42
  </select>
43
43
  <div class="textareaAndPreview">
44
44
  <textarea id="editorTextArea" name="content" cols="30" rows="10">
45
- # H1
46
-
47
- ここにマークダウンを入力してください。
45
+ {{ MARKDOWN_NOT_PARSED }}
48
46
  </textarea>
49
47
  <div class="preview">
50
48
  <div id="previewContent"></div>