@contentbit/studio 2.0.0-next.1 → 2.0.0-next.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/dist/client/assets/{api-aCc2x-IO.js → api-D5joupdU.js} +1 -1
- package/dist/client/assets/{arrow-right-tp4VknZo.js → arrow-right-DgVH2ckT.js} +1 -1
- package/dist/client/assets/{document-DIh3ZPXr.js → document-C9j7At_d.js} +1 -1
- package/dist/client/assets/{documents-CjBZYbQ4.js → documents-IFM8-M_m.js} +1 -1
- package/dist/client/assets/{file-code-corner-Fzc5liO9.js → file-code-corner-Ea1mVVN3.js} +1 -1
- package/dist/client/assets/{file-text-B8O46COn.js → file-text-JyAIocHS.js} +1 -1
- package/dist/client/assets/index-0pGRBfyx.js +12 -0
- package/dist/client/assets/{page-BMU8eIrR.js → page-B3xqvv7Z.js} +1 -1
- package/dist/client/assets/{routes-WndCJoku.js → routes-DCV_quef.js} +1 -1
- package/dist/client/assets/{search-BnUPH8AI.js → search-Dh1jm8QA.js} +1 -1
- package/dist/client/assets/{target-BMSXP2fU.js → target-BIrWK4A2.js} +1 -1
- package/dist/client/assets/{templates-IJid1Zwh.js → templates-CyNCDlsk.js} +1 -1
- package/dist/server/api.d.ts.map +1 -1
- package/dist/server/assets/{_tanstack-start-manifest_v-WfZ3uz_l.js → _tanstack-start-manifest_v-BuI4pWk7.js} +23 -23
- package/dist/server/assets/{document-BjPXZ9gS.js → document-DOP_63d9.js} +1 -1
- package/dist/server/assets/{documents-jT4KnSkA.js → documents-DFgsCsBO.js} +1 -1
- package/dist/server/assets/{empty-plugin-adapters-Ctp1ZmyT.js → empty-plugin-adapters-CViywP8O.js} +1 -1
- package/dist/server/assets/{page--xw7NmtK.js → page-aNwYcZ_l.js} +1 -1
- package/dist/server/assets/{router-xI8HUWRI.js → router-CtNxhc0G.js} +38 -42
- package/dist/server/assets/{routes-CfwU-Ww2.js → routes-C77LqfqF.js} +1 -1
- package/dist/server/assets/start-BrmB4H5W.js +3 -0
- package/dist/server/index.js +73 -39
- package/dist/server/server.js +2790 -2344
- package/package.json +7 -7
- package/src/routeTree.gen.ts +36 -36
- package/src/server/api.ts +16 -13
- package/src/server/scan.ts +4 -4
- package/src/server/site.test.ts +32 -3
- package/dist/client/assets/index-Cd04OFZT.js +0 -11
- package/dist/server/assets/start-Dk-BJfGT.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentbit/studio",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.3",
|
|
4
4
|
"description": "Local read-only dashboard for contentbit: a site's built pages, page context, template findings, and Markdown.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"contentbit",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@fontsource-variable/inter": "^5.2.8",
|
|
41
41
|
"@tailwindcss/vite": "^4",
|
|
42
|
-
"@tanstack/react-router": "1.170.
|
|
43
|
-
"@tanstack/react-start": "1.168.
|
|
44
|
-
"@tanstack/router-plugin": "1.168.
|
|
42
|
+
"@tanstack/react-router": "1.170.41",
|
|
43
|
+
"@tanstack/react-start": "1.168.60",
|
|
44
|
+
"@tanstack/router-plugin": "1.168.42",
|
|
45
45
|
"@vitejs/plugin-react": "^6",
|
|
46
46
|
"class-variance-authority": "^0.7.1",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"tinyglobby": "^0.2.10",
|
|
58
58
|
"tw-animate-css": "^1.4.0",
|
|
59
59
|
"vite": "^8",
|
|
60
|
-
"@contentbit/blocks": "2.0.0-next.
|
|
61
|
-
"@contentbit/core": "2.0.0-next.
|
|
62
|
-
"@contentbit/react": "2.0.0-next.
|
|
60
|
+
"@contentbit/blocks": "2.0.0-next.3",
|
|
61
|
+
"@contentbit/core": "2.0.0-next.3",
|
|
62
|
+
"@contentbit/react": "2.0.0-next.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@testing-library/dom": "^10.4.2",
|
package/src/routeTree.gen.ts
CHANGED
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
|
10
10
|
|
|
11
11
|
import { Route as rootRouteImport } from './routes/__root'
|
|
12
|
-
import { Route as TemplatesRouteImport } from './routes/templates'
|
|
13
|
-
import { Route as PageRouteImport } from './routes/page'
|
|
14
|
-
import { Route as DocumentsRouteImport } from './routes/documents'
|
|
15
|
-
import { Route as DocumentRouteImport } from './routes/document'
|
|
16
12
|
import { Route as IndexRouteImport } from './routes/index'
|
|
13
|
+
import { Route as DocumentRouteImport } from './routes/document'
|
|
14
|
+
import { Route as DocumentsRouteImport } from './routes/documents'
|
|
15
|
+
import { Route as PageRouteImport } from './routes/page'
|
|
16
|
+
import { Route as TemplatesRouteImport } from './routes/templates'
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
id: '/
|
|
20
|
-
path: '/
|
|
18
|
+
const IndexRoute = IndexRouteImport.update({
|
|
19
|
+
id: '/',
|
|
20
|
+
path: '/',
|
|
21
21
|
getParentRoute: () => rootRouteImport,
|
|
22
22
|
} as any)
|
|
23
|
-
const
|
|
24
|
-
id: '/
|
|
25
|
-
path: '/
|
|
23
|
+
const DocumentRoute = DocumentRouteImport.update({
|
|
24
|
+
id: '/document',
|
|
25
|
+
path: '/document',
|
|
26
26
|
getParentRoute: () => rootRouteImport,
|
|
27
27
|
} as any)
|
|
28
28
|
const DocumentsRoute = DocumentsRouteImport.update({
|
|
@@ -30,14 +30,14 @@ const DocumentsRoute = DocumentsRouteImport.update({
|
|
|
30
30
|
path: '/documents',
|
|
31
31
|
getParentRoute: () => rootRouteImport,
|
|
32
32
|
} as any)
|
|
33
|
-
const
|
|
34
|
-
id: '/
|
|
35
|
-
path: '/
|
|
33
|
+
const PageRoute = PageRouteImport.update({
|
|
34
|
+
id: '/page',
|
|
35
|
+
path: '/page',
|
|
36
36
|
getParentRoute: () => rootRouteImport,
|
|
37
37
|
} as any)
|
|
38
|
-
const
|
|
39
|
-
id: '/',
|
|
40
|
-
path: '/',
|
|
38
|
+
const TemplatesRoute = TemplatesRouteImport.update({
|
|
39
|
+
id: '/templates',
|
|
40
|
+
path: '/templates',
|
|
41
41
|
getParentRoute: () => rootRouteImport,
|
|
42
42
|
} as any)
|
|
43
43
|
|
|
@@ -81,18 +81,18 @@ export interface RootRouteChildren {
|
|
|
81
81
|
|
|
82
82
|
declare module '@tanstack/react-router' {
|
|
83
83
|
interface FileRoutesByPath {
|
|
84
|
-
'/
|
|
85
|
-
id: '/
|
|
86
|
-
path: '/
|
|
87
|
-
fullPath: '/
|
|
88
|
-
preLoaderRoute: typeof
|
|
84
|
+
'/': {
|
|
85
|
+
id: '/'
|
|
86
|
+
path: '/'
|
|
87
|
+
fullPath: '/'
|
|
88
|
+
preLoaderRoute: typeof IndexRouteImport
|
|
89
89
|
parentRoute: typeof rootRouteImport
|
|
90
90
|
}
|
|
91
|
-
'/
|
|
92
|
-
id: '/
|
|
93
|
-
path: '/
|
|
94
|
-
fullPath: '/
|
|
95
|
-
preLoaderRoute: typeof
|
|
91
|
+
'/document': {
|
|
92
|
+
id: '/document'
|
|
93
|
+
path: '/document'
|
|
94
|
+
fullPath: '/document'
|
|
95
|
+
preLoaderRoute: typeof DocumentRouteImport
|
|
96
96
|
parentRoute: typeof rootRouteImport
|
|
97
97
|
}
|
|
98
98
|
'/documents': {
|
|
@@ -102,18 +102,18 @@ declare module '@tanstack/react-router' {
|
|
|
102
102
|
preLoaderRoute: typeof DocumentsRouteImport
|
|
103
103
|
parentRoute: typeof rootRouteImport
|
|
104
104
|
}
|
|
105
|
-
'/
|
|
106
|
-
id: '/
|
|
107
|
-
path: '/
|
|
108
|
-
fullPath: '/
|
|
109
|
-
preLoaderRoute: typeof
|
|
105
|
+
'/page': {
|
|
106
|
+
id: '/page'
|
|
107
|
+
path: '/page'
|
|
108
|
+
fullPath: '/page'
|
|
109
|
+
preLoaderRoute: typeof PageRouteImport
|
|
110
110
|
parentRoute: typeof rootRouteImport
|
|
111
111
|
}
|
|
112
|
-
'/': {
|
|
113
|
-
id: '/'
|
|
114
|
-
path: '/'
|
|
115
|
-
fullPath: '/'
|
|
116
|
-
preLoaderRoute: typeof
|
|
112
|
+
'/templates': {
|
|
113
|
+
id: '/templates'
|
|
114
|
+
path: '/templates'
|
|
115
|
+
fullPath: '/templates'
|
|
116
|
+
preLoaderRoute: typeof TemplatesRouteImport
|
|
117
117
|
parentRoute: typeof rootRouteImport
|
|
118
118
|
}
|
|
119
119
|
}
|
package/src/server/api.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
2
|
+
import { pathsFromRoot } from '@contentbit/project'
|
|
2
3
|
|
|
3
4
|
import { scanDocument, scanProject } from './scan.js'
|
|
4
5
|
import { scanPage, scanSite } from './site.js'
|
|
@@ -12,63 +13,65 @@ export async function handleStudioApiRequest(
|
|
|
12
13
|
if (!req.url) return false
|
|
13
14
|
const url = new URL(req.url, 'http://contentbit.local')
|
|
14
15
|
if (!url.pathname.startsWith('/api/')) return false
|
|
16
|
+
const root = options.cwd ?? process.cwd()
|
|
15
17
|
|
|
16
18
|
try {
|
|
17
19
|
if (req.method !== 'GET') {
|
|
18
|
-
sendJson(res, 405, { error: 'Studio API is read-only.' })
|
|
20
|
+
sendJson(res, root, 405, { error: 'Studio API is read-only.' })
|
|
19
21
|
return true
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
if (url.pathname === '/api/project') {
|
|
23
|
-
sendJson(res, 200, await scanProject(options))
|
|
25
|
+
sendJson(res, root, 200, await scanProject(options))
|
|
24
26
|
return true
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
if (url.pathname === '/api/site') {
|
|
28
|
-
sendJson(res, 200, await scanSite(options))
|
|
30
|
+
sendJson(res, root, 200, await scanSite(options))
|
|
29
31
|
return true
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
if (url.pathname === '/api/page') {
|
|
33
35
|
const path = url.searchParams.get('path')
|
|
34
36
|
if (!path) {
|
|
35
|
-
sendJson(res, 400, { error: 'Missing ?path=' })
|
|
37
|
+
sendJson(res, root, 400, { error: 'Missing ?path=' })
|
|
36
38
|
return true
|
|
37
39
|
}
|
|
38
40
|
const page = await scanPage(options, path)
|
|
39
41
|
if (!page) {
|
|
40
|
-
sendJson(res, 404, { error: `The build has no page ${path}.` })
|
|
42
|
+
sendJson(res, root, 404, { error: `The build has no page ${path}.` })
|
|
41
43
|
return true
|
|
42
44
|
}
|
|
43
|
-
sendJson(res, 200, page)
|
|
45
|
+
sendJson(res, root, 200, page)
|
|
44
46
|
return true
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
if (url.pathname === '/api/document') {
|
|
48
50
|
const path = url.searchParams.get('path')
|
|
49
51
|
if (!path) {
|
|
50
|
-
sendJson(res, 400, { error: 'Missing ?path=' })
|
|
52
|
+
sendJson(res, root, 400, { error: 'Missing ?path=' })
|
|
51
53
|
return true
|
|
52
54
|
}
|
|
53
55
|
const document = await scanDocument(options, path)
|
|
54
56
|
if (!document) {
|
|
55
|
-
sendJson(res, 404, { error: 'Document is not in the configured content set.' })
|
|
57
|
+
sendJson(res, root, 404, { error: 'Document is not in the configured content set.' })
|
|
56
58
|
return true
|
|
57
59
|
}
|
|
58
|
-
sendJson(res, 200, document)
|
|
60
|
+
sendJson(res, root, 200, document)
|
|
59
61
|
return true
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
sendJson(res, 404, { error: 'Unknown Studio API route.' })
|
|
64
|
+
sendJson(res, root, 404, { error: 'Unknown Studio API route.' })
|
|
63
65
|
return true
|
|
64
66
|
} catch (err) {
|
|
65
|
-
sendJson(res, 500, { error: err instanceof Error ? err.message : String(err) })
|
|
67
|
+
sendJson(res, root, 500, { error: err instanceof Error ? err.message : String(err) })
|
|
66
68
|
return true
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
/** The UI shows and copies the paths a response holds, so each is from the project root. */
|
|
73
|
+
function sendJson(res: ServerResponse, root: string, status: number, body: unknown): void {
|
|
71
74
|
res.statusCode = status
|
|
72
75
|
res.setHeader('content-type', 'application/json; charset=utf-8')
|
|
73
|
-
res.end(JSON.stringify(body,
|
|
76
|
+
res.end(JSON.stringify(body, pathsFromRoot(root), 2))
|
|
74
77
|
}
|
package/src/server/scan.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type SeoPage,
|
|
7
7
|
} from '@contentbit/core'
|
|
8
8
|
import { relativeInside } from '@contentbit/project'
|
|
9
|
-
import { basename } from 'node:path'
|
|
9
|
+
import { basename, normalize } from 'node:path'
|
|
10
10
|
|
|
11
11
|
import { renderStudioPreview } from './preview.js'
|
|
12
12
|
import { loadSiteOrJoinInFlight, pagesByFile } from './site.js'
|
|
@@ -248,10 +248,10 @@ function statusFor(findings: StudioFileSummary['findings']): StudioStatus {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
function findAllowedFile(context: ScanContext, cwd: string, requestedPath: string): string | null {
|
|
251
|
+
const requested = normalize(requestedPath)
|
|
251
252
|
return (
|
|
252
|
-
context.files.find(
|
|
253
|
-
|
|
254
|
-
) ?? null
|
|
253
|
+
context.files.find((file) => file === requested || relativePath(cwd, file) === requested) ??
|
|
254
|
+
null
|
|
255
255
|
)
|
|
256
256
|
}
|
|
257
257
|
|
package/src/server/site.test.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { afterEach, assert, expect, test } from 'vitest'
|
|
|
5
5
|
|
|
6
6
|
import { startStudio, type StudioServer } from './index'
|
|
7
7
|
import { scanDocument, scanProject } from './scan'
|
|
8
|
-
import { scanPage, scanSite } from './site'
|
|
9
|
-
import type { StudioOptions } from './types'
|
|
8
|
+
import { scanPage, scanSite, type StudioPage, type StudioSite } from './site'
|
|
9
|
+
import type { StudioDocument, StudioOptions, StudioProject } from './types'
|
|
10
10
|
import { tempDir } from '../../../../test/temp-dir.js'
|
|
11
11
|
|
|
12
12
|
const runningServers: StudioServer[] = []
|
|
@@ -298,7 +298,7 @@ test('startStudio serves the site and page context endpoints from the build fold
|
|
|
298
298
|
expect(await site.json()).toMatchObject({
|
|
299
299
|
kind: 'built',
|
|
300
300
|
context: {
|
|
301
|
-
build:
|
|
301
|
+
build: 'web',
|
|
302
302
|
origin: { url: 'https://www.bakery.example', source: 'flag' },
|
|
303
303
|
pages: { length: 5 },
|
|
304
304
|
},
|
|
@@ -310,6 +310,35 @@ test('startStudio serves the site and page context endpoints from the build fold
|
|
|
310
310
|
expect(noPath.status).toBe(400)
|
|
311
311
|
})
|
|
312
312
|
|
|
313
|
+
test('every path in a Studio API response is from the project root, and a document opens by it', async () => {
|
|
314
|
+
const dir = await fixture(bakery)
|
|
315
|
+
const server = await startStudio({ ...options(dir), port: 0, open: false })
|
|
316
|
+
runningServers.push(server)
|
|
317
|
+
const get = async (path: string) => {
|
|
318
|
+
const response = await fetch(new URL(path, server.url))
|
|
319
|
+
expect(response.status, path).toBe(200)
|
|
320
|
+
return response.text()
|
|
321
|
+
}
|
|
322
|
+
const query = (route: string, path: string) => `${route}?path=${encodeURIComponent(path)}`
|
|
323
|
+
|
|
324
|
+
const project = await get('/api/project')
|
|
325
|
+
const site = await get('/api/site')
|
|
326
|
+
const built = JSON.parse(site) as Extract<StudioSite, { kind: 'built' }>
|
|
327
|
+
const pages = await Promise.all(
|
|
328
|
+
built.context.pages.map(({ path }) => get(query('/api/page', path))),
|
|
329
|
+
)
|
|
330
|
+
const files = (JSON.parse(project) as StudioProject).files.map(({ path }) => path)
|
|
331
|
+
const documents = await Promise.all(files.map((file) => get(query('/api/document', file))))
|
|
332
|
+
const sourdough = JSON.parse(await get(query('/api/page', '/blog/sourdough/'))) as StudioPage
|
|
333
|
+
const rye = JSON.parse(await get(query('/api/document', 'content/blog/rye.md'))) as StudioDocument
|
|
334
|
+
|
|
335
|
+
expect(sourdough.context.source?.file).toBe('content/blog/sourdough.md')
|
|
336
|
+
await get(query('/api/document', sourdough.context.source?.file ?? ''))
|
|
337
|
+
expect(rye.seoBrief?.target.path).toBe('content/blog/rye.md')
|
|
338
|
+
expect(rye.seoBrief?.relatedPages.map(({ path }) => path)).toEqual(['content/blog/spelt.md'])
|
|
339
|
+
for (const body of [project, site, ...pages, ...documents]) expect(body).not.toContain(dir)
|
|
340
|
+
})
|
|
341
|
+
|
|
313
342
|
test('a request whose URL Studio cannot parse gets an error, and Studio keeps serving', async () => {
|
|
314
343
|
const dir = await fixture(bakery)
|
|
315
344
|
const server = await startStudio({ ...options(dir), port: 0, open: false })
|