@tenjuu99/blog 0.2.0 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenjuu99/blog",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "blog template",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,8 +2,10 @@ import { IncomingMessage, ServerResponse } from 'http'
2
2
  import fs from 'node:fs/promises'
3
3
  import { styleText } from 'node:util'
4
4
 
5
- const config = (await import('../../lib/config.js')).default
6
- const dir = (await import('../../lib/dir.js'))
5
+ const rootDir = process.cwd()
6
+ const config = (await import(rootDir + '/lib/config.js')).default
7
+ const dir = (await import(rootDir + '/lib/dir.js'))
8
+ const helper = (await import(rootDir + '/lib/helper.js'))
7
9
 
8
10
  export const path = '/editor'
9
11
 
@@ -19,7 +21,7 @@ export const post = async (req, res) => {
19
21
  const json = JSON.parse(chunks.join())
20
22
  const file = json.inputFileName ? json.inputFileName : json.selectDataFile
21
23
  if (!file) {
22
- res.writeHead(401, { 'content-type': 'application/json' })
24
+ res.writeHead(400, { 'content-type': 'application/json' })
23
25
  res.end(JSON.stringify({
24
26
  'message': 'ファイル名がありません'
25
27
  }))
@@ -1,8 +1,9 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http'
2
2
  import fs from 'node:fs'
3
3
 
4
- const config = (await import('../../lib/config.js')).default
5
- const pageDir = (await import('../../lib/dir.js')).pageDir
4
+ const rootDir = process.cwd()
5
+ const config = (await import(rootDir + '/lib/config.js')).default
6
+ const pageDir = (await import(rootDir + '/lib/dir.js')).pageDir
6
7
 
7
8
  export const path = '/get_editor_target'
8
9
 
@@ -1,8 +1,9 @@
1
1
  import { IncomingMessage, ServerResponse } from 'http'
2
2
  import { styleText } from 'node:util'
3
3
 
4
- const render = (await import('../../lib/render.js')).default
5
- const makePageData = (await import('../../lib/pageData.js')).default
4
+ const rootDir = process.cwd()
5
+ const render = (await import(rootDir + '/lib/render.js')).default
6
+ const makePageData = (await import(rootDir + '/lib/pageData.js')).default
6
7
 
7
8
  export const path = '/preview'
8
9
 
@@ -18,7 +19,7 @@ export const post = async (req, res) => {
18
19
  const json = JSON.parse(chunks.join())
19
20
  const filename = json.inputFileName ? json.inputFileName : json.selectDataFile
20
21
  const pageData = makePageData(filename, json.content)
21
- const rendered = await render('default.html', pageData)
22
+ const rendered = await render(pageData.template, pageData)
22
23
  res.writeHead(200, { 'content-type': 'application/json' })
23
24
  res.end(JSON.stringify({
24
25
  'preview': rendered
@@ -43,15 +43,15 @@
43
43
  {/if}
44
44
  {{MARKDOWN}}
45
45
  </article>
46
+
47
+ {include('template/prevNext.html')}
48
+ </main>
46
49
  {if editor}
47
50
  <div class="container">
48
51
  <a href="/editor?md={{name}}.{{__filetype}}">編集する</a>
49
52
  </div>
50
53
  {/if}
51
54
 
52
- {include('template/prevNext.html')}
53
- </main>
54
-
55
55
  {include('template/footer.html')}
56
56
  </body>
57
57
  </html>
@@ -56,6 +56,7 @@
56
56
  height: 100%;
57
57
  border: none;
58
58
  border-radius: 0 5px 5px 0;
59
+ pointer-events: none;
59
60
  }
60
61
  @media screen and (max-width: 600px) {
61
62
  main {
@@ -114,9 +115,16 @@
114
115
  inputFileName.value = json.filename
115
116
  inputFileName.setAttribute('disabled', true)
116
117
  url.searchParams.set('md', select.value)
118
+ submit('/preview', form)
117
119
  } else {
118
120
  inputFileName.value = ""
119
121
  inputFileName.removeAttribute('disabled')
122
+ textarea.value = ''
123
+ url.searchParams.set('md', "")
124
+ const iframe = preview.querySelector('iframe')
125
+ if (iframe) {
126
+ iframe.srcdoc = ''
127
+ }
120
128
  }
121
129
  history.pushState({}, "", url)
122
130
  })
@@ -143,6 +151,7 @@
143
151
  if (json.preview) {
144
152
  const iframe = document.createElement('iframe')
145
153
  iframe.setAttribute('srcdoc', json.preview)
154
+ iframe.setAttribute('sandbox', '')
146
155
  const old = preview.querySelector('iframe')
147
156
  if (!old) {
148
157
  preview.appendChild(iframe)