@inglorious/ssx 2.0.1 → 2.0.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 +5 -5
- package/src/scripts/app.js +1 -2
- package/src/utils/markdown.js +16 -3
- package/src/utils/markdown.test.js +55 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/ssx",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Server-Side-X. Xecution? Xperience? Who knows.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,14 +64,14 @@
|
|
|
64
64
|
"svgo": "^4.0.0",
|
|
65
65
|
"vite": "^7.1.3",
|
|
66
66
|
"vite-plugin-image-optimizer": "^2.0.3",
|
|
67
|
-
"@inglorious/
|
|
68
|
-
"@inglorious/
|
|
67
|
+
"@inglorious/utils": "3.8.0",
|
|
68
|
+
"@inglorious/web": "5.0.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"prettier": "^3.6.2",
|
|
72
72
|
"vitest": "^1.6.1",
|
|
73
|
-
"@inglorious/
|
|
74
|
-
"@inglorious/
|
|
73
|
+
"@inglorious/logo": "3.0.2",
|
|
74
|
+
"@inglorious/eslint-config": "1.1.2"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">= 22"
|
package/src/scripts/app.js
CHANGED
|
@@ -123,7 +123,6 @@ ${routes.join(",\n")}
|
|
|
123
123
|
const module = await getRoute(page.pattern)()
|
|
124
124
|
const type = module[page.moduleName]
|
|
125
125
|
types[page.moduleName] = type
|
|
126
|
-
const shouldHydrate = module.hydrate !== false
|
|
127
126
|
|
|
128
127
|
const store = createStore({ types, entities, middlewares, systems, autoCreateEntities: true })
|
|
129
128
|
|
|
@@ -132,7 +131,7 @@ const root = document.getElementById("root")
|
|
|
132
131
|
mount(store, (api) => {
|
|
133
132
|
const { route } = api.getEntity("router")
|
|
134
133
|
return api.render(route)
|
|
135
|
-
}, root
|
|
134
|
+
}, root)
|
|
136
135
|
`
|
|
137
136
|
}
|
|
138
137
|
|
package/src/utils/markdown.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
|
|
3
|
+
import { toCamelCase } from "@inglorious/utils/data-structures/string.js"
|
|
1
4
|
import hljs from "highlight.js"
|
|
2
5
|
import katex from "katex"
|
|
3
6
|
import MarkdownIt from "markdown-it"
|
|
@@ -24,6 +27,7 @@ export function markdownPlugin(options = {}) {
|
|
|
24
27
|
const matter = (await import("gray-matter")).default
|
|
25
28
|
const { content, data } = matter(code)
|
|
26
29
|
const htmlContent = md.render(content)
|
|
30
|
+
const moduleName = getMarkdownModuleName(id)
|
|
27
31
|
const hasMermaid =
|
|
28
32
|
content.includes('class="mermaid"') || content.includes("```mermaid")
|
|
29
33
|
|
|
@@ -40,9 +44,7 @@ export function markdownPlugin(options = {}) {
|
|
|
40
44
|
${mermaidCode}
|
|
41
45
|
|
|
42
46
|
export const metadata = ${JSON.stringify(data)}
|
|
43
|
-
export const
|
|
44
|
-
|
|
45
|
-
export default {
|
|
47
|
+
export const ${moduleName} = {
|
|
46
48
|
render() {
|
|
47
49
|
if (typeof window !== "undefined" && ${hasMermaid}) {
|
|
48
50
|
setTimeout(() => {
|
|
@@ -101,3 +103,14 @@ function createMarkdownRenderer() {
|
|
|
101
103
|
|
|
102
104
|
return md
|
|
103
105
|
}
|
|
106
|
+
|
|
107
|
+
function getMarkdownModuleName(id) {
|
|
108
|
+
const baseName = path.basename(id, path.extname(id))
|
|
109
|
+
const pascalCase = toPascalCase(baseName)
|
|
110
|
+
return /^[A-Za-z_$]/.test(pascalCase) ? pascalCase : `_${pascalCase}`
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function toPascalCase(input) {
|
|
114
|
+
const camelCase = toCamelCase(input.replace(/[^a-zA-Z0-9_$-]/g, "_"))
|
|
115
|
+
return camelCase.replace(/^[a-z]/, (char) => char.toUpperCase())
|
|
116
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
|
|
3
|
+
import { markdownPlugin, renderMarkdown } from "./markdown.js"
|
|
4
|
+
|
|
5
|
+
describe("renderMarkdown", () => {
|
|
6
|
+
it("strips frontmatter and renders markdown content", () => {
|
|
7
|
+
const html = renderMarkdown(`---
|
|
8
|
+
title: Talk 2
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Hello World
|
|
12
|
+
|
|
13
|
+
This is a markdown page.
|
|
14
|
+
`)
|
|
15
|
+
|
|
16
|
+
expect(html).toContain("<h1>Hello World</h1>")
|
|
17
|
+
expect(html).toContain("<p>This is a markdown page.</p>")
|
|
18
|
+
expect(html).not.toContain("title: Talk 2")
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe("markdownPlugin", () => {
|
|
23
|
+
it("exports a unique named page module for each markdown file", async () => {
|
|
24
|
+
const plugin = markdownPlugin()
|
|
25
|
+
const code = `---
|
|
26
|
+
title: Talk 2
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
# Hello World
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const result = await plugin.transform(
|
|
33
|
+
code,
|
|
34
|
+
"/Users/iceonfire/Projects/ic/my-app/src/pages/talk2.md",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
expect(result).toContain(`export const metadata = {"title":"Talk 2"}`)
|
|
38
|
+
expect(result).toContain("export const Talk2 = {")
|
|
39
|
+
expect(result).not.toContain("export default")
|
|
40
|
+
expect(result).not.toContain("export const hydrate = false")
|
|
41
|
+
expect(result).toContain("unsafeHTML")
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("converts kebab-case file names to PascalCase exports", async () => {
|
|
45
|
+
const plugin = markdownPlugin()
|
|
46
|
+
const code = `# Hello`
|
|
47
|
+
|
|
48
|
+
const result = await plugin.transform(
|
|
49
|
+
code,
|
|
50
|
+
"/Users/iceonfire/Projects/ic/my-app/src/pages/hello-world.md",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
expect(result).toContain("export const HelloWorld = {")
|
|
54
|
+
})
|
|
55
|
+
})
|