@rimelight/cms 0.0.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/README.md +19 -0
- package/package.json +69 -0
- package/src/astro/BlockRenderer.astro +111 -0
- package/src/astro/PageRenderer.astro +23 -0
- package/src/astro/blocks/CalloutBlock.astro +78 -0
- package/src/astro/blocks/CardBlock.astro +43 -0
- package/src/astro/blocks/CardsBlock.astro +24 -0
- package/src/astro/blocks/CodeBlock.astro +16 -0
- package/src/astro/blocks/DialogueBlock.astro +23 -0
- package/src/astro/blocks/FileTreeBlock.astro +45 -0
- package/src/astro/blocks/ImageBlock.astro +17 -0
- package/src/astro/blocks/OrderedListBlock.astro +55 -0
- package/src/astro/blocks/ParagraphBlock.astro +65 -0
- package/src/astro/blocks/SceneBlock.astro +65 -0
- package/src/astro/blocks/ScriptBlock.astro +59 -0
- package/src/astro/blocks/SectionBlock.astro +46 -0
- package/src/astro/blocks/StepItemBlock.astro +25 -0
- package/src/astro/blocks/StepsBlock.astro +14 -0
- package/src/astro/blocks/TabItemBlock.astro +19 -0
- package/src/astro/blocks/TableBlock.astro +49 -0
- package/src/astro/blocks/TabsBlock.astro +67 -0
- package/src/astro/blocks/UnorderedListBlock.astro +55 -0
- package/src/auth/editor-guards.ts +148 -0
- package/src/auth/filter-blocks.ts +44 -0
- package/src/auth/filter-templates.ts +81 -0
- package/src/auth/permissions.ts +40 -0
- package/src/cache/purge.ts +37 -0
- package/src/client/components/RimelightBlock.tsx +487 -0
- package/src/client/components/RimelightBlockPicker.tsx +305 -0
- package/src/client/components/RimelightEditor.tsx +131 -0
- package/src/client/components/RimelightEditorLayout.tsx +143 -0
- package/src/client/components/RimelightPreview.tsx +354 -0
- package/src/client/components/RimelightPropertiesPanel.tsx +408 -0
- package/src/client/components/RimelightTemplateEditor.tsx +245 -0
- package/src/client/components/editors/CalloutEditor.tsx +185 -0
- package/src/client/components/editors/CardEditor.tsx +60 -0
- package/src/client/components/editors/CardsEditor.tsx +132 -0
- package/src/client/components/editors/CodeEditor.tsx +101 -0
- package/src/client/components/editors/DialogueEditor.tsx +52 -0
- package/src/client/components/editors/FileTreeEditor.tsx +65 -0
- package/src/client/components/editors/ImageEditor.tsx +70 -0
- package/src/client/components/editors/ParagraphEditor.tsx +314 -0
- package/src/client/components/editors/SceneEditor.tsx +245 -0
- package/src/client/components/editors/ScriptEditor.tsx +245 -0
- package/src/client/components/editors/SectionEditor.tsx +139 -0
- package/src/client/components/editors/StepItemEditor.tsx +117 -0
- package/src/client/components/editors/StepsEditor.tsx +105 -0
- package/src/client/components/editors/TabItemEditor.tsx +113 -0
- package/src/client/components/editors/TableEditor.tsx +181 -0
- package/src/client/components/editors/TabsEditor.tsx +105 -0
- package/src/client/components/index.ts +7 -0
- package/src/client/loader.ts +19 -0
- package/src/client/state/autosave.ts +122 -0
- package/src/client/state/editor-store.ts +411 -0
- package/src/client/state/history.ts +251 -0
- package/src/client/state/lock-manager.ts +89 -0
- package/src/client/styles/cms-editor.css +653 -0
- package/src/client/toast.ts +12 -0
- package/src/client/utils/sortable.ts +184 -0
- package/src/client/utils/splitpane.ts +87 -0
- package/src/client/utils/tree-sanitizer.ts +33 -0
- package/src/core/page-definitions.ts +502 -0
- package/src/core/registry.ts +99 -0
- package/src/core/template-sync.ts +75 -0
- package/src/core/types/blocks.ts +367 -0
- package/src/core/types/inline.ts +23 -0
- package/src/core/types/pages.ts +36 -0
- package/src/core/types/templates.ts +32 -0
- package/src/core/types/versioning.ts +44 -0
- package/src/core/validator.ts +28 -0
- package/src/env.d.ts +4 -0
- package/src/index.ts +47 -0
- package/src/markdown/index.ts +2 -0
- package/src/markdown/parser.ts +347 -0
- package/src/markdown/serializer.ts +219 -0
- package/src/migration.ts +155 -0
- package/src/schema/index.ts +8 -0
- package/src/schema/page_draft_locks.ts +13 -0
- package/src/schema/page_drafts.ts +18 -0
- package/src/schema/page_templates.ts +27 -0
- package/src/schema/page_version_approvals.ts +12 -0
- package/src/schema/page_version_comments.ts +14 -0
- package/src/schema/page_versions.ts +34 -0
- package/src/schema/pages.ts +42 -0
- package/src/schema/search.ts +23 -0
- package/src/search/query.ts +10 -0
- package/src/search/sync.ts +32 -0
package/src/migration.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm"
|
|
2
|
+
import { markdownToBlocks } from "./markdown/parser.ts"
|
|
3
|
+
import type { BaseBlock } from "./core/types/blocks"
|
|
4
|
+
|
|
5
|
+
export interface DocMigrationInput {
|
|
6
|
+
slug: string
|
|
7
|
+
title: string | Record<string, string>
|
|
8
|
+
description?: string | Record<string, string>
|
|
9
|
+
markdown: string
|
|
10
|
+
properties?: Record<string, any>
|
|
11
|
+
postedAt?: Date | null
|
|
12
|
+
authorIds?: string[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parseMarkdownWithFrontmatter(raw: string): {
|
|
16
|
+
frontmatter: Record<string, any>
|
|
17
|
+
body: string
|
|
18
|
+
} {
|
|
19
|
+
const frontmatter: Record<string, any> = {}
|
|
20
|
+
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/)
|
|
21
|
+
|
|
22
|
+
if (!match) {
|
|
23
|
+
return { frontmatter, body: raw.trim() }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const yamlBlock = match[1] || ""
|
|
27
|
+
const body = (match[2] || "").trim()
|
|
28
|
+
|
|
29
|
+
const lines = yamlBlock.split(/\r?\n/)
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
const trimmed = line.trim()
|
|
32
|
+
if (!trimmed || trimmed.startsWith("#")) continue
|
|
33
|
+
const colonIndex = trimmed.indexOf(":")
|
|
34
|
+
if (colonIndex !== -1) {
|
|
35
|
+
const key = trimmed.slice(0, colonIndex).trim()
|
|
36
|
+
let value: any = trimmed.slice(colonIndex + 1).trim()
|
|
37
|
+
|
|
38
|
+
if (value === "true") value = true
|
|
39
|
+
else if (value === "false") value = false
|
|
40
|
+
else if (value === "null") value = null
|
|
41
|
+
else if (!isNaN(Number(value)) && value !== "") value = Number(value)
|
|
42
|
+
else if (
|
|
43
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
44
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
45
|
+
) {
|
|
46
|
+
value = value.slice(1, -1)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
frontmatter[key] = value
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { frontmatter, body }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function convertMarkdownDocToPageRecord(input: DocMigrationInput) {
|
|
57
|
+
const blocks: BaseBlock[] = markdownToBlocks(input.markdown)
|
|
58
|
+
const titleObj =
|
|
59
|
+
typeof input.title === "string" ? { en: input.title } : input.title || { en: input.slug }
|
|
60
|
+
const descObj =
|
|
61
|
+
typeof input.description === "string"
|
|
62
|
+
? { en: input.description }
|
|
63
|
+
: input.description || undefined
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
id: crypto.randomUUID(),
|
|
67
|
+
slug: input.slug,
|
|
68
|
+
type: "doc" as const,
|
|
69
|
+
title: titleObj,
|
|
70
|
+
description: descObj,
|
|
71
|
+
tags: [],
|
|
72
|
+
authorIds: input.authorIds || [],
|
|
73
|
+
postedAt: input.postedAt !== undefined ? input.postedAt : new Date(),
|
|
74
|
+
createdAt: new Date(),
|
|
75
|
+
updatedAt: new Date(),
|
|
76
|
+
content: {
|
|
77
|
+
blocks,
|
|
78
|
+
properties: input.properties || {}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function migrateLegacyPagesToCMSv2(db: any) {
|
|
84
|
+
console.log("[Migration] Applying DDL schema updates...")
|
|
85
|
+
|
|
86
|
+
await db.execute(sql`
|
|
87
|
+
ALTER TABLE pages ADD COLUMN IF NOT EXISTS template_id UUID;
|
|
88
|
+
ALTER TABLE pages ADD COLUMN IF NOT EXISTS template_version INTEGER DEFAULT 1 NOT NULL;
|
|
89
|
+
ALTER TABLE page_versions ADD COLUMN IF NOT EXISTS version_number INTEGER DEFAULT 1 NOT NULL;
|
|
90
|
+
|
|
91
|
+
CREATE UNIQUE INDEX IF NOT EXISTS page_versions_page_id_version_idx
|
|
92
|
+
ON page_versions (page_id, version_number);
|
|
93
|
+
`)
|
|
94
|
+
|
|
95
|
+
console.log("[Migration] Transforming legacy page content in chunked batches...")
|
|
96
|
+
|
|
97
|
+
const BATCH_SIZE = 100
|
|
98
|
+
let offset = 0
|
|
99
|
+
|
|
100
|
+
async function fetchBatch(currentOffset: number) {
|
|
101
|
+
const batch = await db.execute(sql`
|
|
102
|
+
SELECT id, content FROM pages ORDER BY id LIMIT ${BATCH_SIZE} OFFSET ${currentOffset};
|
|
103
|
+
`)
|
|
104
|
+
|
|
105
|
+
if (!batch || !batch.rows || batch.rows.length === 0) {
|
|
106
|
+
return null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const rows: Array<{ id: string; content: unknown }> = batch.rows
|
|
110
|
+
return rows
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function processBatch(pagesList: Array<{ id: string; content: unknown }>) {
|
|
114
|
+
const updatePromises = pagesList.map((page) => {
|
|
115
|
+
const transformed = transformLegacyContent(page.content)
|
|
116
|
+
return db.execute(sql`
|
|
117
|
+
UPDATE pages SET content = ${JSON.stringify(transformed)}::jsonb WHERE id = ${page.id}::uuid;
|
|
118
|
+
`)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
await Promise.all(updatePromises)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function processAllBatches(currentOffset: number): Promise<void> {
|
|
125
|
+
const pagesList = await fetchBatch(currentOffset)
|
|
126
|
+
if (!pagesList) return
|
|
127
|
+
await processBatch(pagesList)
|
|
128
|
+
console.log(`[Migration] Migrated ${currentOffset + BATCH_SIZE} records...`)
|
|
129
|
+
return processAllBatches(currentOffset + BATCH_SIZE)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
await processAllBatches(offset)
|
|
133
|
+
|
|
134
|
+
console.log("[Migration] Migration completed successfully.")
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function transformLegacyContent(raw: unknown) {
|
|
138
|
+
if (typeof raw === "object" && raw !== null && "blocks" in raw) return raw
|
|
139
|
+
let textContent = ""
|
|
140
|
+
try {
|
|
141
|
+
textContent = typeof raw === "string" ? raw : JSON.stringify(raw ?? "")
|
|
142
|
+
} catch {
|
|
143
|
+
textContent = ""
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
blocks: [
|
|
147
|
+
{
|
|
148
|
+
id: crypto.randomUUID(),
|
|
149
|
+
type: "ParagraphBlock",
|
|
150
|
+
props: { text: { en: textContent } }
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
properties: {}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./pages.ts"
|
|
2
|
+
export * from "./page_drafts.ts"
|
|
3
|
+
export * from "./page_draft_locks.ts"
|
|
4
|
+
export * from "./page_versions.ts"
|
|
5
|
+
export * from "./page_version_comments.ts"
|
|
6
|
+
export * from "./page_version_approvals.ts"
|
|
7
|
+
export * from "./page_templates.ts"
|
|
8
|
+
export * from "./search.ts"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import { pages } from "./pages.ts"
|
|
3
|
+
|
|
4
|
+
export const pageDraftLocks = pgTable("page_draft_locks", {
|
|
5
|
+
pageId: uuid("page_id")
|
|
6
|
+
.notNull()
|
|
7
|
+
.primaryKey()
|
|
8
|
+
.references(() => pages.id, { onDelete: "cascade" }),
|
|
9
|
+
lockedByUserId: text("locked_by_user_id").notNull(),
|
|
10
|
+
lockedByUserName: text("locked_by_user_name").notNull(),
|
|
11
|
+
acquiredAt: timestamp("acquired_at", { withTimezone: true }).defaultNow().notNull(),
|
|
12
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull()
|
|
13
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import { pages } from "./pages.ts"
|
|
3
|
+
import type { BaseBlock } from "../core/types/blocks"
|
|
4
|
+
|
|
5
|
+
export const pageDrafts = pgTable("page_drafts", {
|
|
6
|
+
pageId: uuid("page_id")
|
|
7
|
+
.notNull()
|
|
8
|
+
.primaryKey()
|
|
9
|
+
.references(() => pages.id, { onDelete: "cascade" }),
|
|
10
|
+
content: jsonb("content")
|
|
11
|
+
.$type<{
|
|
12
|
+
blocks: BaseBlock[]
|
|
13
|
+
properties: Record<string, any>
|
|
14
|
+
}>()
|
|
15
|
+
.notNull(),
|
|
16
|
+
updatedBy: text("updated_by").notNull(),
|
|
17
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull()
|
|
18
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { integer, jsonb, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import type { BaseBlock } from "../core/types/blocks"
|
|
3
|
+
import type { Localized, PageType } from "../core/types/pages"
|
|
4
|
+
import type { TemplateApprovalRules, TemplateRolePermissions } from "../core/types/templates"
|
|
5
|
+
|
|
6
|
+
export const pageTemplates = pgTable("page_templates", {
|
|
7
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
8
|
+
slug: text("slug").notNull().unique(),
|
|
9
|
+
title: jsonb("title").$type<Localized>().notNull(),
|
|
10
|
+
description: jsonb("description").$type<Localized>(),
|
|
11
|
+
pageType: text("page_type").$type<PageType>().notNull(),
|
|
12
|
+
version: integer("version").default(1).notNull(),
|
|
13
|
+
allowedRoles: jsonb("allowed_roles").$type<string[]>().default([]).notNull(),
|
|
14
|
+
rolePermissions: jsonb("role_permissions")
|
|
15
|
+
.$type<TemplateRolePermissions>()
|
|
16
|
+
.default({ whoCanCreate: [], whoCanEdit: [], whoCanReview: [], whoCanView: [] })
|
|
17
|
+
.notNull(),
|
|
18
|
+
requiredPermission: text("required_permission"),
|
|
19
|
+
approvalRules: jsonb("approval_rules")
|
|
20
|
+
.$type<TemplateApprovalRules>()
|
|
21
|
+
.default({ allowSelfApproval: true, minApprovals: 1 })
|
|
22
|
+
.notNull(),
|
|
23
|
+
defaultProperties: jsonb("default_properties").default({}).notNull(),
|
|
24
|
+
initialBlocks: jsonb("initial_blocks").$type<BaseBlock[]>().default([]).notNull(),
|
|
25
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
26
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(() => new Date())
|
|
27
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import { pageVersions } from "./page_versions.ts"
|
|
3
|
+
|
|
4
|
+
export const pageVersionApprovals = pgTable("page_version_approvals", {
|
|
5
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
6
|
+
versionId: uuid("version_id")
|
|
7
|
+
.notNull()
|
|
8
|
+
.references(() => pageVersions.id, { onDelete: "cascade" }),
|
|
9
|
+
userId: text("user_id").notNull(),
|
|
10
|
+
userRole: text("user_role").notNull(),
|
|
11
|
+
approvedAt: timestamp("approved_at", { withTimezone: true }).defaultNow().notNull()
|
|
12
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import { pageVersions } from "./page_versions.ts"
|
|
3
|
+
|
|
4
|
+
export const pageVersionComments = pgTable("page_version_comments", {
|
|
5
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
6
|
+
versionId: uuid("version_id")
|
|
7
|
+
.notNull()
|
|
8
|
+
.references(() => pageVersions.id, { onDelete: "cascade" }),
|
|
9
|
+
userId: text("user_id").notNull(),
|
|
10
|
+
userRole: text("user_role").notNull(),
|
|
11
|
+
content: text("content").notNull(),
|
|
12
|
+
blockId: text("block_id"),
|
|
13
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull()
|
|
14
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import type { BaseBlock } from "../core/types/blocks"
|
|
3
|
+
import type { Localized, PageType } from "../core/types/pages"
|
|
4
|
+
import type { PageVersionStatus } from "../core/types/versioning"
|
|
5
|
+
|
|
6
|
+
export const pageVersions = pgTable(
|
|
7
|
+
"page_versions",
|
|
8
|
+
{
|
|
9
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
10
|
+
pageId: uuid("page_id").notNull(),
|
|
11
|
+
versionNumber: integer("version_number").notNull(),
|
|
12
|
+
status: text("status").$type<PageVersionStatus>().default("pending").notNull(),
|
|
13
|
+
slug: text("slug").notNull(),
|
|
14
|
+
type: text("type").$type<PageType>().notNull(),
|
|
15
|
+
title: jsonb("title").$type<Localized>().notNull(),
|
|
16
|
+
description: jsonb("description").$type<Localized>(),
|
|
17
|
+
tags: jsonb("tags").$type<Localized[]>().default([]).notNull(),
|
|
18
|
+
authorIds: jsonb("author_ids").$type<string[]>().default([]),
|
|
19
|
+
content: jsonb("content")
|
|
20
|
+
.$type<{
|
|
21
|
+
blocks: BaseBlock[]
|
|
22
|
+
properties: Record<string, any>
|
|
23
|
+
}>()
|
|
24
|
+
.notNull(),
|
|
25
|
+
createdBy: text("created_by").notNull(),
|
|
26
|
+
approvedBy: jsonb("approved_by").$type<string[]>().default([]).notNull(),
|
|
27
|
+
approvedAt: timestamp("approved_at", { withTimezone: true }),
|
|
28
|
+
changeSummary: text("change_summary"),
|
|
29
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull()
|
|
30
|
+
},
|
|
31
|
+
(table) => [
|
|
32
|
+
uniqueIndex("page_versions_page_id_version_idx").on(table.pageId, table.versionNumber)
|
|
33
|
+
]
|
|
34
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm"
|
|
2
|
+
import { integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core"
|
|
3
|
+
import type { BaseBlock } from "../core/types/blocks"
|
|
4
|
+
import type { Localized, PageType } from "../core/types/pages"
|
|
5
|
+
import { pageVersions } from "./page_versions.ts"
|
|
6
|
+
import { pageTemplates } from "./page_templates.ts"
|
|
7
|
+
|
|
8
|
+
export const pages = pgTable(
|
|
9
|
+
"pages",
|
|
10
|
+
{
|
|
11
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
12
|
+
slug: text("slug").notNull(),
|
|
13
|
+
type: text("type").$type<PageType>().notNull(),
|
|
14
|
+
templateId: uuid("template_id").references(() => pageTemplates.id, { onDelete: "set null" }),
|
|
15
|
+
templateVersion: integer("template_version").default(1).notNull(),
|
|
16
|
+
title: jsonb("title").$type<Localized>().notNull(),
|
|
17
|
+
description: jsonb("description").$type<Localized>(),
|
|
18
|
+
tags: jsonb("tags").$type<Localized[]>().default([]).notNull(),
|
|
19
|
+
authorIds: jsonb("author_ids").$type<string[]>().default([]),
|
|
20
|
+
/**
|
|
21
|
+
* Denormalized read-cache of the active published version content (NULL if unpublished draft)
|
|
22
|
+
*/
|
|
23
|
+
content: jsonb("content")
|
|
24
|
+
.$type<{
|
|
25
|
+
blocks: BaseBlock[]
|
|
26
|
+
properties: Record<string, any>
|
|
27
|
+
}>()
|
|
28
|
+
.notNull(),
|
|
29
|
+
publishedVersionId: uuid("published_version_id").references(() => pageVersions.id, {
|
|
30
|
+
onDelete: "set null"
|
|
31
|
+
}),
|
|
32
|
+
postedAt: timestamp("posted_at", { withTimezone: true }),
|
|
33
|
+
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
|
34
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).$onUpdate(() => new Date()),
|
|
35
|
+
deletedAt: timestamp("deleted_at", { withTimezone: true })
|
|
36
|
+
},
|
|
37
|
+
(table) => [
|
|
38
|
+
uniqueIndex("pages_slug_active_unique_idx")
|
|
39
|
+
.on(table.slug)
|
|
40
|
+
.where(sql`deleted_at IS NULL`)
|
|
41
|
+
]
|
|
42
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { customType, index, pgTable, text, uuid } from "drizzle-orm/pg-core"
|
|
2
|
+
import { pages } from "./pages.ts"
|
|
3
|
+
|
|
4
|
+
const tsvector = customType<{ data: string }>({
|
|
5
|
+
dataType() {
|
|
6
|
+
return "tsvector"
|
|
7
|
+
}
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export const contentSearchIndex = pgTable(
|
|
11
|
+
"content_search_index",
|
|
12
|
+
{
|
|
13
|
+
id: uuid("id").defaultRandom().notNull().primaryKey(),
|
|
14
|
+
pageId: uuid("page_id")
|
|
15
|
+
.notNull()
|
|
16
|
+
.references(() => pages.id, { onDelete: "cascade" }),
|
|
17
|
+
locale: text("locale").notNull(),
|
|
18
|
+
titleText: text("title_text").notNull(),
|
|
19
|
+
contentText: text("content_text").notNull(),
|
|
20
|
+
searchVector: tsvector("search_vector")
|
|
21
|
+
},
|
|
22
|
+
(table) => [index("search_vector_gin_idx").using("gin", table.searchVector)]
|
|
23
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const POSTGRES_SEARCH_CONFIGS: Record<string, string> = {
|
|
2
|
+
en: "english",
|
|
3
|
+
es: "spanish",
|
|
4
|
+
de: "german",
|
|
5
|
+
fr: "french"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getPostgresSearchConfig(locale: string): string {
|
|
9
|
+
return POSTGRES_SEARCH_CONFIGS[locale] || "simple"
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BaseBlock } from "../core/types/blocks"
|
|
2
|
+
|
|
3
|
+
export function extractPlainTextFromBlocks(blocks: BaseBlock[], locale = "en"): string {
|
|
4
|
+
const parts: string[] = []
|
|
5
|
+
|
|
6
|
+
function walk(nodes: BaseBlock[]) {
|
|
7
|
+
for (const node of nodes) {
|
|
8
|
+
if (node.props) {
|
|
9
|
+
if (typeof node.props.text === "object" && node.props.text !== null) {
|
|
10
|
+
const locText = node.props.text[locale] || node.props.text.en
|
|
11
|
+
if (locText) parts.push(String(locText))
|
|
12
|
+
} else if (typeof node.props.text === "string") {
|
|
13
|
+
parts.push(node.props.text)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof node.props.title === "object" && node.props.title !== null) {
|
|
17
|
+
const locTitle = node.props.title[locale] || node.props.title.en
|
|
18
|
+
if (locTitle) parts.push(String(locTitle))
|
|
19
|
+
} else if (typeof node.props.title === "string") {
|
|
20
|
+
parts.push(node.props.title)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (node.children?.length) {
|
|
25
|
+
walk(node.children)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
walk(blocks)
|
|
31
|
+
return parts.join(" ")
|
|
32
|
+
}
|