@tenjuu99/blog 0.2.40 → 0.2.42
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/lib/contentTypes.js +33 -0
- package/lib/pageData.js +11 -0
- package/lib/server.js +1 -28
- package/package.json +1 -1
- package/src-sample/template/csstest.html +1 -1
- package/src-sample/template/default.html +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import helper from './helper.js'
|
|
2
|
+
|
|
3
|
+
const contentTypes = {
|
|
4
|
+
'text': 'text/plain',
|
|
5
|
+
'html': 'text/html',
|
|
6
|
+
'css': 'text/css',
|
|
7
|
+
'js': 'text/javascript',
|
|
8
|
+
'jpg': 'image/jpeg',
|
|
9
|
+
'jpeg': 'image/jpeg',
|
|
10
|
+
'png': 'image/png',
|
|
11
|
+
'webp': 'image/webp',
|
|
12
|
+
'avif': 'image/avif',
|
|
13
|
+
'svg': 'image/svg+xml',
|
|
14
|
+
'json': 'application/json',
|
|
15
|
+
'xml': 'application/xml',
|
|
16
|
+
'rdf': 'application/rdf+xml',
|
|
17
|
+
'rss': 'application/rss+xml',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const contentType = (ext) => {
|
|
21
|
+
if (helper['contentTypes']) {
|
|
22
|
+
const additionalContentTypes = helper['contentTypes']
|
|
23
|
+
if (additionalContentTypes[ext]) {
|
|
24
|
+
return additionalContentTypes[ext]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (contentTypes[ext]) {
|
|
28
|
+
return contentTypes[ext]
|
|
29
|
+
}
|
|
30
|
+
return 'application/octet-stream'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default contentType
|
package/lib/pageData.js
CHANGED
|
@@ -10,6 +10,15 @@ const parse = (content, name, ext) => {
|
|
|
10
10
|
const regexp = new RegExp(/^(<!|-)--(?<variables>[\s\S]*?)--(-|>)/)
|
|
11
11
|
const matched = content.match(regexp)
|
|
12
12
|
const markdownReplaced = content.replace(regexp, '')
|
|
13
|
+
const fullUrl = (data) => {
|
|
14
|
+
const base = data.url_base + (data.relative_path ?? '')
|
|
15
|
+
let url = data.url
|
|
16
|
+
url = url.replace(/\/index$/, '/')
|
|
17
|
+
if (data.ext !== 'html') {
|
|
18
|
+
url = url + '.' + data.ext
|
|
19
|
+
}
|
|
20
|
+
return base + encodeURI(url)
|
|
21
|
+
}
|
|
13
22
|
const metaDataDefault = Object.assign({
|
|
14
23
|
name,
|
|
15
24
|
title: name,
|
|
@@ -32,6 +41,7 @@ const parse = (content, name, ext) => {
|
|
|
32
41
|
__filetype: ext,
|
|
33
42
|
}, config)
|
|
34
43
|
if (!matched) {
|
|
44
|
+
metaDataDefault.full_url = fullUrl(metaDataDefault)
|
|
35
45
|
return metaDataDefault
|
|
36
46
|
}
|
|
37
47
|
const metaData = Object.fromEntries(
|
|
@@ -52,6 +62,7 @@ const parse = (content, name, ext) => {
|
|
|
52
62
|
})
|
|
53
63
|
)
|
|
54
64
|
const metaDataMerged = Object.assign(metaDataDefault, metaData)
|
|
65
|
+
metaDataMerged.full_url = fullUrl(metaDataMerged)
|
|
55
66
|
metaDataMerged['__output'] = name === 'index' ? '/index.html' : `${metaDataMerged.url}.${metaDataMerged.ext}`
|
|
56
67
|
|
|
57
68
|
return metaDataMerged
|
package/lib/server.js
CHANGED
|
@@ -4,34 +4,7 @@ import fs from 'node:fs'
|
|
|
4
4
|
import { distDir, serverDir } from './dir.js'
|
|
5
5
|
import { styleText } from 'node:util'
|
|
6
6
|
import handle from './tryServer.js'
|
|
7
|
-
|
|
8
|
-
const contentType = (ext) => {
|
|
9
|
-
switch (ext) {
|
|
10
|
-
case 'txt':
|
|
11
|
-
return 'text/plain'
|
|
12
|
-
case 'html':
|
|
13
|
-
case 'css':
|
|
14
|
-
return `text/${ext}`
|
|
15
|
-
case 'js':
|
|
16
|
-
return 'text/javascript'
|
|
17
|
-
case 'jpeg':
|
|
18
|
-
case 'png':
|
|
19
|
-
case 'webp':
|
|
20
|
-
case 'avif':
|
|
21
|
-
return `image/${ext}`
|
|
22
|
-
case 'jpg':
|
|
23
|
-
return 'image/jpeg'
|
|
24
|
-
case 'svg':
|
|
25
|
-
return 'image/svg+xml'
|
|
26
|
-
case 'xml':
|
|
27
|
-
case 'json':
|
|
28
|
-
return `application/${ext}`
|
|
29
|
-
case 'rdf':
|
|
30
|
-
return 'application/rdf+xml.rdf'
|
|
31
|
-
default:
|
|
32
|
-
return 'application/octet-stream'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
7
|
+
import contentType from './contentType.js'
|
|
35
8
|
|
|
36
9
|
const server = () => {
|
|
37
10
|
return http.createServer(async (request, response) => {
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{if noindex}
|
|
8
8
|
<meta name="robots" content="noindex" />
|
|
9
9
|
{/if}
|
|
10
|
-
<meta property="og:url" content="{{
|
|
10
|
+
<meta property="og:url" content="{{FULL_URL}}">
|
|
11
11
|
<meta property="og:title" content="{{TITLE}}">
|
|
12
12
|
{if og_image}
|
|
13
13
|
<meta property="og:image" content="{{OG_IMAGE}}">
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
{if noindex}
|
|
8
8
|
<meta name="robots" content="noindex" />
|
|
9
9
|
{/if}
|
|
10
|
-
<meta property="og:url" content="{{
|
|
10
|
+
<meta property="og:url" content="{{FULL_URL}}">
|
|
11
11
|
<meta property="og:title" content="{{TITLE}}">
|
|
12
12
|
{if og_image}
|
|
13
13
|
<meta property="og:image" content="{{OG_IMAGE}}">
|