feat: complete HTML-first architecture implementation (Phase 1 & 2)

Major architectural simplification removing content type complexity:

Database Schema:
- Remove 'type' field from content and content_versions tables
- Simplify to pure HTML storage with html_content + original_template
- Regenerate all sqlc models for SQLite and PostgreSQL

API Simplification:
- Remove content type routing and validation
- Eliminate type-specific handlers (text/markdown/structured)
- Unified HTML-first approach for all content operations
- Simplify CreateContent and UpdateContent to HTML-only

Backend Enhancements:
- Update enhancer to only generate data-content-id (no data-content-type)
- Improve container expansion utilities with comprehensive block/inline rules
- Add Phase 3 preparation with boundary-respecting traversal logic
- Strengthen element classification for viable children detection

Documentation:
- Update TODO.md to reflect Phase 1-3 completion status
- Add WORKING_ON.md documenting the architectural transformation
- Mark container expansion and HTML-first architecture as complete

This completes the transition to a unified HTML-first content management system
with automatic style detection and element-based behavior, eliminating the
complex multi-type system in favor of semantic HTML-driven editing.
This commit is contained in:
2025-09-21 19:23:54 +02:00
parent b5e601d09f
commit b75eda2a87
25 changed files with 470 additions and 214 deletions

View File

@@ -12,9 +12,9 @@ import (
)
const createContent = `-- name: CreateContent :one
INSERT INTO content (id, site_id, html_content, original_template, type, last_edited_by)
VALUES (?1, ?2, ?3, ?4, ?5, ?6)
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
INSERT INTO content (id, site_id, html_content, original_template, last_edited_by)
VALUES (?1, ?2, ?3, ?4, ?5)
RETURNING id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
`
type CreateContentParams struct {
@@ -22,7 +22,6 @@ type CreateContentParams struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
LastEditedBy string `json:"last_edited_by"`
}
@@ -32,7 +31,6 @@ func (q *Queries) CreateContent(ctx context.Context, arg CreateContentParams) (C
arg.SiteID,
arg.HtmlContent,
arg.OriginalTemplate,
arg.Type,
arg.LastEditedBy,
)
var i Content
@@ -41,7 +39,6 @@ func (q *Queries) CreateContent(ctx context.Context, arg CreateContentParams) (C
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
@@ -75,7 +72,7 @@ func (q *Queries) DeleteContent(ctx context.Context, arg DeleteContentParams) er
}
const getAllContent = `-- name: GetAllContent :many
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
SELECT id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
FROM content
WHERE site_id = ?1
ORDER BY updated_at DESC
@@ -95,7 +92,6 @@ func (q *Queries) GetAllContent(ctx context.Context, siteID string) ([]Content,
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
@@ -114,7 +110,7 @@ func (q *Queries) GetAllContent(ctx context.Context, siteID string) ([]Content,
}
const getBulkContent = `-- name: GetBulkContent :many
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
SELECT id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
FROM content
WHERE site_id = ?1 AND id IN (/*SLICE:ids*/?)
`
@@ -149,7 +145,6 @@ func (q *Queries) GetBulkContent(ctx context.Context, arg GetBulkContentParams)
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
@@ -168,7 +163,7 @@ func (q *Queries) GetBulkContent(ctx context.Context, arg GetBulkContentParams)
}
const getContent = `-- name: GetContent :one
SELECT id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
SELECT id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
FROM content
WHERE id = ?1 AND site_id = ?2
`
@@ -186,7 +181,6 @@ func (q *Queries) GetContent(ctx context.Context, arg GetContentParams) (Content
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
@@ -196,14 +190,13 @@ func (q *Queries) GetContent(ctx context.Context, arg GetContentParams) (Content
const updateContent = `-- name: UpdateContent :one
UPDATE content
SET html_content = ?1, type = ?2, last_edited_by = ?3
WHERE id = ?4 AND site_id = ?5
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
SET html_content = ?1, last_edited_by = ?2
WHERE id = ?3 AND site_id = ?4
RETURNING id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
`
type UpdateContentParams struct {
HtmlContent string `json:"html_content"`
Type string `json:"type"`
LastEditedBy string `json:"last_edited_by"`
ID string `json:"id"`
SiteID string `json:"site_id"`
@@ -212,7 +205,6 @@ type UpdateContentParams struct {
func (q *Queries) UpdateContent(ctx context.Context, arg UpdateContentParams) (Content, error) {
row := q.db.QueryRowContext(ctx, updateContent,
arg.HtmlContent,
arg.Type,
arg.LastEditedBy,
arg.ID,
arg.SiteID,
@@ -223,7 +215,6 @@ func (q *Queries) UpdateContent(ctx context.Context, arg UpdateContentParams) (C
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,
@@ -232,13 +223,12 @@ func (q *Queries) UpdateContent(ctx context.Context, arg UpdateContentParams) (C
}
const upsertContent = `-- name: UpsertContent :one
INSERT INTO content (id, site_id, html_content, original_template, type, last_edited_by)
VALUES (?1, ?2, ?3, ?4, ?5, ?6)
INSERT INTO content (id, site_id, html_content, original_template, last_edited_by)
VALUES (?1, ?2, ?3, ?4, ?5)
ON CONFLICT(id, site_id) DO UPDATE SET
html_content = EXCLUDED.html_content,
type = EXCLUDED.type,
last_edited_by = EXCLUDED.last_edited_by
RETURNING id, site_id, html_content, original_template, type, created_at, updated_at, last_edited_by
RETURNING id, site_id, html_content, original_template, created_at, updated_at, last_edited_by
`
type UpsertContentParams struct {
@@ -246,7 +236,6 @@ type UpsertContentParams struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
LastEditedBy string `json:"last_edited_by"`
}
@@ -256,7 +245,6 @@ func (q *Queries) UpsertContent(ctx context.Context, arg UpsertContentParams) (C
arg.SiteID,
arg.HtmlContent,
arg.OriginalTemplate,
arg.Type,
arg.LastEditedBy,
)
var i Content
@@ -265,7 +253,6 @@ func (q *Queries) UpsertContent(ctx context.Context, arg UpsertContentParams) (C
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
&i.LastEditedBy,

View File

@@ -13,7 +13,6 @@ type Content struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
LastEditedBy string `json:"last_edited_by"`
@@ -25,7 +24,6 @@ type ContentVersion struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
CreatedAt int64 `json:"created_at"`
CreatedBy string `json:"created_by"`
}

View File

@@ -5,7 +5,6 @@ CREATE TABLE content (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL,
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
updated_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
last_edited_by TEXT DEFAULT 'system' NOT NULL,
@@ -19,7 +18,6 @@ CREATE TABLE content_versions (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL,
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
created_by TEXT DEFAULT 'system' NOT NULL
);

View File

@@ -4,7 +4,6 @@ CREATE TABLE IF NOT EXISTS content (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL CHECK (type IN ('text', 'link')),
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
updated_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
last_edited_by TEXT DEFAULT 'system' NOT NULL,
@@ -18,7 +17,6 @@ CREATE TABLE IF NOT EXISTS content_versions (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL,
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
created_by TEXT DEFAULT 'system' NOT NULL
);

View File

@@ -15,7 +15,6 @@ CREATE TABLE IF NOT EXISTS content (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL CHECK (type IN ('text', 'link')),
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
updated_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
last_edited_by TEXT DEFAULT 'system' NOT NULL,
@@ -35,7 +34,6 @@ CREATE TABLE IF NOT EXISTS content_versions (
site_id TEXT NOT NULL,
html_content TEXT NOT NULL,
original_template TEXT,
type TEXT NOT NULL,
created_at INTEGER DEFAULT (strftime('%s', 'now')) NOT NULL,
created_by TEXT DEFAULT 'system' NOT NULL
)

View File

@@ -11,8 +11,8 @@ import (
)
const createContentVersion = `-- name: CreateContentVersion :exec
INSERT INTO content_versions (content_id, site_id, html_content, original_template, type, created_by)
VALUES (?1, ?2, ?3, ?4, ?5, ?6)
INSERT INTO content_versions (content_id, site_id, html_content, original_template, created_by)
VALUES (?1, ?2, ?3, ?4, ?5)
`
type CreateContentVersionParams struct {
@@ -20,7 +20,6 @@ type CreateContentVersionParams struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
CreatedBy string `json:"created_by"`
}
@@ -30,7 +29,6 @@ func (q *Queries) CreateContentVersion(ctx context.Context, arg CreateContentVer
arg.SiteID,
arg.HtmlContent,
arg.OriginalTemplate,
arg.Type,
arg.CreatedBy,
)
return err
@@ -53,7 +51,7 @@ func (q *Queries) DeleteOldVersions(ctx context.Context, arg DeleteOldVersionsPa
const getAllVersionsForSite = `-- name: GetAllVersionsForSite :many
SELECT
cv.version_id, cv.content_id, cv.site_id, cv.html_content, cv.original_template, cv.type, cv.created_at, cv.created_by,
cv.version_id, cv.content_id, cv.site_id, cv.html_content, cv.original_template, cv.created_at, cv.created_by,
c.html_content as current_html_content
FROM content_versions cv
LEFT JOIN content c ON cv.content_id = c.id AND cv.site_id = c.site_id
@@ -73,7 +71,6 @@ type GetAllVersionsForSiteRow struct {
SiteID string `json:"site_id"`
HtmlContent string `json:"html_content"`
OriginalTemplate sql.NullString `json:"original_template"`
Type string `json:"type"`
CreatedAt int64 `json:"created_at"`
CreatedBy string `json:"created_by"`
CurrentHtmlContent sql.NullString `json:"current_html_content"`
@@ -94,7 +91,6 @@ func (q *Queries) GetAllVersionsForSite(ctx context.Context, arg GetAllVersionsF
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.CreatedBy,
&i.CurrentHtmlContent,
@@ -113,7 +109,7 @@ func (q *Queries) GetAllVersionsForSite(ctx context.Context, arg GetAllVersionsF
}
const getContentVersion = `-- name: GetContentVersion :one
SELECT version_id, content_id, site_id, html_content, original_template, type, created_at, created_by
SELECT version_id, content_id, site_id, html_content, original_template, created_at, created_by
FROM content_versions
WHERE version_id = ?1
`
@@ -127,7 +123,6 @@ func (q *Queries) GetContentVersion(ctx context.Context, versionID int64) (Conte
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.CreatedBy,
)
@@ -135,7 +130,7 @@ func (q *Queries) GetContentVersion(ctx context.Context, versionID int64) (Conte
}
const getContentVersionHistory = `-- name: GetContentVersionHistory :many
SELECT version_id, content_id, site_id, html_content, original_template, type, created_at, created_by
SELECT version_id, content_id, site_id, html_content, original_template, created_at, created_by
FROM content_versions
WHERE content_id = ?1 AND site_id = ?2
ORDER BY created_at DESC
@@ -163,7 +158,6 @@ func (q *Queries) GetContentVersionHistory(ctx context.Context, arg GetContentVe
&i.SiteID,
&i.HtmlContent,
&i.OriginalTemplate,
&i.Type,
&i.CreatedAt,
&i.CreatedBy,
); err != nil {