@inglorious/ssx 2.0.1 → 2.0.3
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 +4 -3
- package/src/render/html.test.js +2 -1
- package/src/render/render.test.js +1 -1
- package/src/scripts/app.js +4 -3
- package/src/store/index.js +1 -1
- package/src/utils/markdown.js +18 -4
- 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.3",
|
|
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,15 @@
|
|
|
64
64
|
"svgo": "^4.0.0",
|
|
65
65
|
"vite": "^7.1.3",
|
|
66
66
|
"vite-plugin-image-optimizer": "^2.0.3",
|
|
67
|
-
"@inglorious/
|
|
67
|
+
"@inglorious/store": "11.0.0",
|
|
68
|
+
"@inglorious/web": "6.0.0",
|
|
68
69
|
"@inglorious/utils": "3.8.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"prettier": "^3.6.2",
|
|
72
73
|
"vitest": "^1.6.1",
|
|
73
74
|
"@inglorious/eslint-config": "1.1.2",
|
|
74
|
-
"@inglorious/logo": "3.0.
|
|
75
|
+
"@inglorious/logo": "3.0.3"
|
|
75
76
|
},
|
|
76
77
|
"engines": {
|
|
77
78
|
"node": ">= 22"
|
package/src/render/html.test.js
CHANGED
package/src/scripts/app.js
CHANGED
|
@@ -48,7 +48,9 @@ export async function generateApp(pages, options = {}, loader) {
|
|
|
48
48
|
: ""
|
|
49
49
|
|
|
50
50
|
return `import "@inglorious/web/hydrate"
|
|
51
|
-
import {
|
|
51
|
+
import { createStore } from "@inglorious/store"
|
|
52
|
+
import { createDevtools } from "@inglorious/store/client/devtools"
|
|
53
|
+
import { mount } from "@inglorious/web"
|
|
52
54
|
import { Router, getRoute, setRoutes } from "@inglorious/web/router"
|
|
53
55
|
import { getLocaleFromPath } from "@inglorious/ssx/i18n"
|
|
54
56
|
|
|
@@ -123,7 +125,6 @@ ${routes.join(",\n")}
|
|
|
123
125
|
const module = await getRoute(page.pattern)()
|
|
124
126
|
const type = module[page.moduleName]
|
|
125
127
|
types[page.moduleName] = type
|
|
126
|
-
const shouldHydrate = module.hydrate !== false
|
|
127
128
|
|
|
128
129
|
const store = createStore({ types, entities, middlewares, systems, autoCreateEntities: true })
|
|
129
130
|
|
|
@@ -132,7 +133,7 @@ const root = document.getElementById("root")
|
|
|
132
133
|
mount(store, (api) => {
|
|
133
134
|
const { route } = api.getEntity("router")
|
|
134
135
|
return api.render(route)
|
|
135
|
-
}, root
|
|
136
|
+
}, root)
|
|
136
137
|
`
|
|
137
138
|
}
|
|
138
139
|
|
package/src/store/index.js
CHANGED
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
|
|
|
@@ -36,13 +40,12 @@ export function markdownPlugin(options = {}) {
|
|
|
36
40
|
import "katex/dist/katex.min.css"
|
|
37
41
|
import "highlight.js/styles/${theme}.css"
|
|
38
42
|
|
|
39
|
-
import { html
|
|
43
|
+
import { html } from "@inglorious/web"
|
|
44
|
+
import { unsafeHTML } from "@inglorious/web/directives/unsafe-html"
|
|
40
45
|
${mermaidCode}
|
|
41
46
|
|
|
42
47
|
export const metadata = ${JSON.stringify(data)}
|
|
43
|
-
export const
|
|
44
|
-
|
|
45
|
-
export default {
|
|
48
|
+
export const ${moduleName} = {
|
|
46
49
|
render() {
|
|
47
50
|
if (typeof window !== "undefined" && ${hasMermaid}) {
|
|
48
51
|
setTimeout(() => {
|
|
@@ -101,3 +104,14 @@ function createMarkdownRenderer() {
|
|
|
101
104
|
|
|
102
105
|
return md
|
|
103
106
|
}
|
|
107
|
+
|
|
108
|
+
function getMarkdownModuleName(id) {
|
|
109
|
+
const baseName = path.basename(id, path.extname(id))
|
|
110
|
+
const pascalCase = toPascalCase(baseName)
|
|
111
|
+
return /^[A-Za-z_$]/.test(pascalCase) ? pascalCase : `_${pascalCase}`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toPascalCase(input) {
|
|
115
|
+
const camelCase = toCamelCase(input.replace(/[^a-zA-Z0-9_$-]/g, "_"))
|
|
116
|
+
return camelCase.replace(/^[a-z]/, (char) => char.toUpperCase())
|
|
117
|
+
}
|
|
@@ -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
|
+
})
|