@contentbit/studio 0.4.0 → 0.4.1
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/LICENSE +21 -0
- package/components.json +25 -0
- package/dist/client/assets/{api-C-Xwc2aB.js → api-MWiK2l_P.js} +1 -1
- package/dist/client/assets/{document-Yk8nlK-k.js → document-w62o-wDp.js} +1 -1
- package/dist/client/assets/{index-BwvfKCmy.js → index-DTXIZgkK.js} +2 -2
- package/dist/client/assets/{routes-DHIbdBYB.js → routes-Dg9spe-7.js} +1 -1
- package/dist/client/assets/{styles-BGHadX26.css → styles-DxZJz8Oi.css} +1 -1
- package/dist/server/assets/_tanstack-start-manifest_v-wPlN1Hjy.js +25 -0
- package/dist/server/assets/{router-D3JhQdql.js → router-D4DnWGjU.js} +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +13 -2
- package/dist/server/server.js +2 -2
- package/package.json +23 -18
- package/public/favicon.ico +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/src/components/ui/button.tsx +67 -0
- package/src/lib/api.ts +22 -0
- package/src/lib/utils.ts +6 -0
- package/src/logo.svg +12 -0
- package/src/routeTree.gen.ts +86 -0
- package/src/router.tsx +20 -0
- package/src/routes/__root.tsx +48 -0
- package/src/routes/document.tsx +268 -0
- package/src/routes/index.tsx +465 -0
- package/src/server/api.ts +58 -0
- package/src/server/index.ts +151 -0
- package/src/server/preview.ts +46 -0
- package/src/server/scan.test.ts +283 -0
- package/src/server/scan.ts +460 -0
- package/src/server/types.ts +109 -0
- package/src/styles.css +222 -0
- package/tsconfig.json +27 -0
- package/vite.config.ts +11 -0
- package/dist/server/assets/_tanstack-start-manifest_v-Djlrg1a7.js +0 -25
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
|
|
5
|
+
// noinspection JSUnusedGlobalSymbols
|
|
6
|
+
|
|
7
|
+
// This file was automatically generated by TanStack Router.
|
|
8
|
+
// You should NOT make any changes in this file as it will be overwritten.
|
|
9
|
+
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
|
10
|
+
|
|
11
|
+
import { Route as rootRouteImport } from './routes/__root'
|
|
12
|
+
import { Route as DocumentRouteImport } from './routes/document'
|
|
13
|
+
import { Route as IndexRouteImport } from './routes/index'
|
|
14
|
+
|
|
15
|
+
const DocumentRoute = DocumentRouteImport.update({
|
|
16
|
+
id: '/document',
|
|
17
|
+
path: '/document',
|
|
18
|
+
getParentRoute: () => rootRouteImport,
|
|
19
|
+
} as any)
|
|
20
|
+
const IndexRoute = IndexRouteImport.update({
|
|
21
|
+
id: '/',
|
|
22
|
+
path: '/',
|
|
23
|
+
getParentRoute: () => rootRouteImport,
|
|
24
|
+
} as any)
|
|
25
|
+
|
|
26
|
+
export interface FileRoutesByFullPath {
|
|
27
|
+
'/': typeof IndexRoute
|
|
28
|
+
'/document': typeof DocumentRoute
|
|
29
|
+
}
|
|
30
|
+
export interface FileRoutesByTo {
|
|
31
|
+
'/': typeof IndexRoute
|
|
32
|
+
'/document': typeof DocumentRoute
|
|
33
|
+
}
|
|
34
|
+
export interface FileRoutesById {
|
|
35
|
+
__root__: typeof rootRouteImport
|
|
36
|
+
'/': typeof IndexRoute
|
|
37
|
+
'/document': typeof DocumentRoute
|
|
38
|
+
}
|
|
39
|
+
export interface FileRouteTypes {
|
|
40
|
+
fileRoutesByFullPath: FileRoutesByFullPath
|
|
41
|
+
fullPaths: '/' | '/document'
|
|
42
|
+
fileRoutesByTo: FileRoutesByTo
|
|
43
|
+
to: '/' | '/document'
|
|
44
|
+
id: '__root__' | '/' | '/document'
|
|
45
|
+
fileRoutesById: FileRoutesById
|
|
46
|
+
}
|
|
47
|
+
export interface RootRouteChildren {
|
|
48
|
+
IndexRoute: typeof IndexRoute
|
|
49
|
+
DocumentRoute: typeof DocumentRoute
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare module '@tanstack/react-router' {
|
|
53
|
+
interface FileRoutesByPath {
|
|
54
|
+
'/document': {
|
|
55
|
+
id: '/document'
|
|
56
|
+
path: '/document'
|
|
57
|
+
fullPath: '/document'
|
|
58
|
+
preLoaderRoute: typeof DocumentRouteImport
|
|
59
|
+
parentRoute: typeof rootRouteImport
|
|
60
|
+
}
|
|
61
|
+
'/': {
|
|
62
|
+
id: '/'
|
|
63
|
+
path: '/'
|
|
64
|
+
fullPath: '/'
|
|
65
|
+
preLoaderRoute: typeof IndexRouteImport
|
|
66
|
+
parentRoute: typeof rootRouteImport
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const rootRouteChildren: RootRouteChildren = {
|
|
72
|
+
IndexRoute: IndexRoute,
|
|
73
|
+
DocumentRoute: DocumentRoute,
|
|
74
|
+
}
|
|
75
|
+
export const routeTree = rootRouteImport
|
|
76
|
+
._addFileChildren(rootRouteChildren)
|
|
77
|
+
._addFileTypes<FileRouteTypes>()
|
|
78
|
+
|
|
79
|
+
import type { getRouter } from './router.tsx'
|
|
80
|
+
import type { createStart } from '@tanstack/react-start'
|
|
81
|
+
declare module '@tanstack/react-start' {
|
|
82
|
+
interface Register {
|
|
83
|
+
ssr: true
|
|
84
|
+
router: Awaited<ReturnType<typeof getRouter>>
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/router.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRouter as createTanStackRouter } from '@tanstack/react-router'
|
|
2
|
+
import { routeTree } from './routeTree.gen'
|
|
3
|
+
|
|
4
|
+
export function getRouter() {
|
|
5
|
+
const router = createTanStackRouter({
|
|
6
|
+
routeTree,
|
|
7
|
+
|
|
8
|
+
scrollRestoration: true,
|
|
9
|
+
defaultPreload: 'intent',
|
|
10
|
+
defaultPreloadStaleTime: 0,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return router
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module '@tanstack/react-router' {
|
|
17
|
+
interface Register {
|
|
18
|
+
router: ReturnType<typeof getRouter>
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HeadContent, Scripts, createRootRoute } from '@tanstack/react-router'
|
|
2
|
+
import type { ReactNode } from 'react'
|
|
3
|
+
|
|
4
|
+
import appCss from '../styles.css?url'
|
|
5
|
+
|
|
6
|
+
export const Route = createRootRoute({
|
|
7
|
+
head: () => ({
|
|
8
|
+
meta: [
|
|
9
|
+
{
|
|
10
|
+
charSet: 'utf-8',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'viewport',
|
|
14
|
+
content: 'width=device-width, initial-scale=1',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
title: 'contentbit Studio',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
links: [
|
|
21
|
+
{
|
|
22
|
+
rel: 'stylesheet',
|
|
23
|
+
href: appCss,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
}),
|
|
27
|
+
notFoundComponent: () => (
|
|
28
|
+
<main className="container mx-auto p-4 pt-16">
|
|
29
|
+
<h1>404</h1>
|
|
30
|
+
<p>The requested page could not be found.</p>
|
|
31
|
+
</main>
|
|
32
|
+
),
|
|
33
|
+
shellComponent: RootDocument,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
function RootDocument({ children }: { children: ReactNode }) {
|
|
37
|
+
return (
|
|
38
|
+
<html lang="en">
|
|
39
|
+
<head>
|
|
40
|
+
<HeadContent />
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
{children}
|
|
44
|
+
<Scripts />
|
|
45
|
+
</body>
|
|
46
|
+
</html>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { createFileRoute, Link } from '@tanstack/react-router'
|
|
2
|
+
import {
|
|
3
|
+
AlertTriangle,
|
|
4
|
+
ArrowLeft,
|
|
5
|
+
BarChart3,
|
|
6
|
+
Braces,
|
|
7
|
+
FileCode2,
|
|
8
|
+
Link2,
|
|
9
|
+
RefreshCw,
|
|
10
|
+
Search,
|
|
11
|
+
} from 'lucide-react'
|
|
12
|
+
import type { ReactNode } from 'react'
|
|
13
|
+
import { useEffect, useState } from 'react'
|
|
14
|
+
|
|
15
|
+
import { Button } from '@/components/ui/button'
|
|
16
|
+
import { fetchDocument } from '@/lib/api'
|
|
17
|
+
import type { StudioDocument, StudioFinding } from '@/server/types'
|
|
18
|
+
|
|
19
|
+
interface DocumentSearch {
|
|
20
|
+
path: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Route = createFileRoute('/document')({
|
|
24
|
+
validateSearch: (search: Record<string, unknown>): DocumentSearch => ({
|
|
25
|
+
path: typeof search.path === 'string' ? search.path : '',
|
|
26
|
+
}),
|
|
27
|
+
component: DocumentDetail,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
function DocumentDetail() {
|
|
31
|
+
const search = Route.useSearch()
|
|
32
|
+
const [document, setDocument] = useState<StudioDocument | null>(null)
|
|
33
|
+
const [error, setError] = useState<string | null>(null)
|
|
34
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
35
|
+
|
|
36
|
+
async function refresh() {
|
|
37
|
+
if (!search.path) {
|
|
38
|
+
setError('Missing document path.')
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
setRefreshing(true)
|
|
42
|
+
setError(null)
|
|
43
|
+
try {
|
|
44
|
+
setDocument(await fetchDocument(search.path))
|
|
45
|
+
} catch (err) {
|
|
46
|
+
setError(err instanceof Error ? err.message : String(err))
|
|
47
|
+
} finally {
|
|
48
|
+
setRefreshing(false)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
void refresh()
|
|
54
|
+
}, [search.path])
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<main className="min-h-svh bg-background text-foreground">
|
|
58
|
+
<header className="border-b bg-muted/30">
|
|
59
|
+
<div className="mx-auto flex max-w-7xl flex-col gap-5 px-5 py-5">
|
|
60
|
+
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
|
61
|
+
<Button asChild variant="outline" className="w-fit gap-2">
|
|
62
|
+
<Link to="/" search={{ q: '', status: 'all', sort: 'status', dir: 'asc' }}>
|
|
63
|
+
<ArrowLeft className="size-4" />
|
|
64
|
+
Dashboard
|
|
65
|
+
</Link>
|
|
66
|
+
</Button>
|
|
67
|
+
<Button onClick={refresh} disabled={refreshing} className="w-fit gap-2">
|
|
68
|
+
<RefreshCw className={refreshing ? 'size-4 animate-spin' : 'size-4'} />
|
|
69
|
+
Refresh
|
|
70
|
+
</Button>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
{document ? (
|
|
74
|
+
<div>
|
|
75
|
+
<p className="font-mono text-xs text-muted-foreground">
|
|
76
|
+
{document.file.relativePath}
|
|
77
|
+
</p>
|
|
78
|
+
<h1 className="mt-1 break-words text-3xl font-semibold tracking-tight">
|
|
79
|
+
{document.file.title}
|
|
80
|
+
</h1>
|
|
81
|
+
<div className="mt-3 flex flex-wrap gap-2 text-xs">
|
|
82
|
+
<Badge>{document.file.status}</Badge>
|
|
83
|
+
<Badge>{document.file.words} words</Badge>
|
|
84
|
+
<Badge>{document.file.blocks} blocks</Badge>
|
|
85
|
+
<Badge>{document.file.links} links</Badge>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
) : (
|
|
89
|
+
<div>
|
|
90
|
+
<p className="font-mono text-xs text-muted-foreground">contentbit studio</p>
|
|
91
|
+
<h1 className="mt-1 text-3xl font-semibold tracking-tight">Document detail</h1>
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
</div>
|
|
95
|
+
</header>
|
|
96
|
+
|
|
97
|
+
<section className="mx-auto grid max-w-7xl gap-5 px-5 py-5 xl:grid-cols-[minmax(0,1fr)_360px]">
|
|
98
|
+
<div className="min-w-0 space-y-5">
|
|
99
|
+
{error && (
|
|
100
|
+
<Panel title="Error" icon={<AlertTriangle className="size-4" />}>
|
|
101
|
+
{error}
|
|
102
|
+
</Panel>
|
|
103
|
+
)}
|
|
104
|
+
{!document && !error && (
|
|
105
|
+
<Panel title="Loading" icon={<RefreshCw className="size-4" />}>
|
|
106
|
+
Scanning document...
|
|
107
|
+
</Panel>
|
|
108
|
+
)}
|
|
109
|
+
{document && (
|
|
110
|
+
<>
|
|
111
|
+
<Panel title="Preview" icon={<Search className="size-4" />}>
|
|
112
|
+
<div
|
|
113
|
+
className="studio-preview"
|
|
114
|
+
dangerouslySetInnerHTML={{ __html: document.previewHtml }}
|
|
115
|
+
/>
|
|
116
|
+
</Panel>
|
|
117
|
+
|
|
118
|
+
<Panel title="Source" icon={<FileCode2 className="size-4" />}>
|
|
119
|
+
<pre className="max-h-[34rem] overflow-auto whitespace-pre-wrap break-words bg-muted p-4 font-mono text-xs leading-5">
|
|
120
|
+
{document.source}
|
|
121
|
+
</pre>
|
|
122
|
+
</Panel>
|
|
123
|
+
</>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
{document && (
|
|
128
|
+
<aside className="space-y-5">
|
|
129
|
+
<Panel title="Stats" icon={<BarChart3 className="size-4" />}>
|
|
130
|
+
<MetricGrid
|
|
131
|
+
items={[
|
|
132
|
+
['words', document.stats.length.words],
|
|
133
|
+
['reading', `${document.stats.length.readingMinutes} min`],
|
|
134
|
+
['sections', document.stats.outline.length],
|
|
135
|
+
['images', document.stats.images.total],
|
|
136
|
+
['missing alt', document.stats.images.missingAlt],
|
|
137
|
+
['external', document.stats.links.external],
|
|
138
|
+
]}
|
|
139
|
+
/>
|
|
140
|
+
</Panel>
|
|
141
|
+
|
|
142
|
+
<Panel title="Links" icon={<Link2 className="size-4" />}>
|
|
143
|
+
<LinkList title="Outgoing" items={document.linksTo} />
|
|
144
|
+
<LinkList title="Backlinks" items={document.linkedFrom} />
|
|
145
|
+
</Panel>
|
|
146
|
+
|
|
147
|
+
<Panel title="Keywords" icon={<Braces className="size-4" />}>
|
|
148
|
+
{document.file.keywords ? (
|
|
149
|
+
<div className="space-y-3 text-sm">
|
|
150
|
+
{document.file.keywords.primary && (
|
|
151
|
+
<div>
|
|
152
|
+
<p className="text-xs uppercase text-muted-foreground">Primary</p>
|
|
153
|
+
<p className="mt-1 font-medium">{document.file.keywords.primary}</p>
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
{(document.file.keywords.secondary?.length ?? 0) > 0 && (
|
|
157
|
+
<div>
|
|
158
|
+
<p className="text-xs uppercase text-muted-foreground">Secondary</p>
|
|
159
|
+
<div className="mt-2 flex flex-wrap gap-1">
|
|
160
|
+
{document.file.keywords.secondary?.map((keyword) => (
|
|
161
|
+
<Badge key={keyword}>{keyword}</Badge>
|
|
162
|
+
))}
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
)}
|
|
166
|
+
</div>
|
|
167
|
+
) : (
|
|
168
|
+
<p className="text-sm text-muted-foreground">No keyword frontmatter found.</p>
|
|
169
|
+
)}
|
|
170
|
+
</Panel>
|
|
171
|
+
|
|
172
|
+
<Panel title="Findings" icon={<AlertTriangle className="size-4" />}>
|
|
173
|
+
{document.findings.length > 0 ? (
|
|
174
|
+
<ul className="space-y-3">
|
|
175
|
+
{document.findings.map((finding, index) => (
|
|
176
|
+
<FindingItem
|
|
177
|
+
key={`${finding.code}-${finding.line ?? 0}-${index}`}
|
|
178
|
+
finding={finding}
|
|
179
|
+
/>
|
|
180
|
+
))}
|
|
181
|
+
</ul>
|
|
182
|
+
) : (
|
|
183
|
+
<p className="text-sm text-muted-foreground">No findings for this document.</p>
|
|
184
|
+
)}
|
|
185
|
+
</Panel>
|
|
186
|
+
</aside>
|
|
187
|
+
)}
|
|
188
|
+
</section>
|
|
189
|
+
</main>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function Panel({ title, icon, children }: { title: string; icon: ReactNode; children: ReactNode }) {
|
|
194
|
+
return (
|
|
195
|
+
<section className="border bg-background">
|
|
196
|
+
<div className="flex items-center gap-2 border-b bg-muted/40 px-4 py-3">
|
|
197
|
+
{icon}
|
|
198
|
+
<h2 className="text-sm font-semibold">{title}</h2>
|
|
199
|
+
</div>
|
|
200
|
+
<div className="p-4">{children}</div>
|
|
201
|
+
</section>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function Badge({ children }: { children: ReactNode }) {
|
|
206
|
+
return <span className="inline-flex border bg-background px-2 py-0.5 text-xs">{children}</span>
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function MetricGrid({ items }: { items: Array<[string, number | string]> }) {
|
|
210
|
+
return (
|
|
211
|
+
<div className="grid grid-cols-2 gap-px overflow-hidden border bg-border">
|
|
212
|
+
{items.map(([label, value]) => (
|
|
213
|
+
<div key={label} className="bg-background p-3">
|
|
214
|
+
<div className="font-mono text-lg font-semibold">{value}</div>
|
|
215
|
+
<div className="text-[0.65rem] uppercase text-muted-foreground">{label}</div>
|
|
216
|
+
</div>
|
|
217
|
+
))}
|
|
218
|
+
</div>
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function LinkList({ title, items }: { title: string; items: StudioDocument['linksTo'] }) {
|
|
223
|
+
return (
|
|
224
|
+
<div className="mb-4 last:mb-0">
|
|
225
|
+
<p className="mb-2 text-xs uppercase text-muted-foreground">{title}</p>
|
|
226
|
+
{items.length > 0 ? (
|
|
227
|
+
<ul className="space-y-1 text-sm">
|
|
228
|
+
{items.map((item, index) => (
|
|
229
|
+
<li
|
|
230
|
+
key={`${linkLabel(item)}-${index}`}
|
|
231
|
+
className="truncate border bg-muted/40 px-2 py-1"
|
|
232
|
+
>
|
|
233
|
+
{linkLabel(item)}
|
|
234
|
+
</li>
|
|
235
|
+
))}
|
|
236
|
+
</ul>
|
|
237
|
+
) : (
|
|
238
|
+
<p className="text-sm text-muted-foreground">None</p>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function FindingItem({ finding }: { finding: StudioFinding }) {
|
|
245
|
+
const tone =
|
|
246
|
+
finding.severity === 'error'
|
|
247
|
+
? 'text-destructive'
|
|
248
|
+
: finding.severity === 'warning'
|
|
249
|
+
? 'text-amber-700'
|
|
250
|
+
: 'text-blue-700'
|
|
251
|
+
return (
|
|
252
|
+
<li className="border bg-muted/30 p-3 text-sm">
|
|
253
|
+
<div className="flex items-start justify-between gap-3">
|
|
254
|
+
<span className={`font-medium ${tone}`}>{finding.code}</span>
|
|
255
|
+
{finding.line && (
|
|
256
|
+
<span className="font-mono text-xs text-muted-foreground">:{finding.line}</span>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
<p className="mt-1">{finding.message}</p>
|
|
260
|
+
{finding.hint && <p className="mt-2 text-xs text-muted-foreground">{finding.hint}</p>}
|
|
261
|
+
</li>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function linkLabel(item: StudioDocument['linksTo'][number]): string {
|
|
266
|
+
if (typeof item === 'string') return item
|
|
267
|
+
return item.target ?? item.key ?? item.slug
|
|
268
|
+
}
|