refactor: consolidate database structure and move injector to engine
Database Structure Cleanup: - Move all SQL files from ./db/ to ./internal/db/ - Update sqlc.yaml to use new paths (preserving schema+setup.sql hack) - Consolidate database-related code in single directory - Remove empty ./db/ directory Injector Migration: - Move injector.go from content package to engine package - Update ContentClient interface to return map instead of slice for GetBulkContent - Update database client implementation to match interface - Remove injector dependency from enhancer (stub implementation) Demo-Site Consolidation: - Move demo-site to test-sites/demo-site for better organization - Update build scripts to use new demo-site location - Maintain all functionality while improving project structure This continues the unified architecture consolidation by moving core content processing logic to the engine and organizing related files properly.
This commit is contained in:
@@ -13,7 +13,7 @@ server:
|
|||||||
port: 8080 # HTTP API server port
|
port: 8080 # HTTP API server port
|
||||||
sites: # Registered sites for file-based enhancement
|
sites: # Registered sites for file-based enhancement
|
||||||
- site_id: "demo"
|
- site_id: "demo"
|
||||||
path: "./demo-site"
|
path: "./test-sites/demo-site"
|
||||||
domain: "localhost:3000"
|
domain: "localhost:3000"
|
||||||
auto_enhance: true
|
auto_enhance: true
|
||||||
backup_originals: true
|
backup_originals: true
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
// Enhancer combines parsing and content injection using unified engine
|
// Enhancer combines parsing and content injection using unified engine
|
||||||
type Enhancer struct {
|
type Enhancer struct {
|
||||||
engine *engine.ContentEngine
|
engine *engine.ContentEngine
|
||||||
injector *Injector
|
// injector functionality will be integrated into engine
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEnhancer creates a new HTML enhancer using unified engine
|
// NewEnhancer creates a new HTML enhancer using unified engine
|
||||||
@@ -26,8 +26,7 @@ func NewEnhancer(client ContentClient, siteID string) *Enhancer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Enhancer{
|
return &Enhancer{
|
||||||
engine: engine.NewContentEngine(engineClient),
|
engine: engine.NewContentEngine(engineClient),
|
||||||
injector: NewInjector(client, siteID),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func (c *DatabaseClient) GetContent(siteID, contentID string) (*ContentItem, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBulkContent retrieves multiple content items
|
// GetBulkContent retrieves multiple content items
|
||||||
func (c *DatabaseClient) GetBulkContent(siteID string, contentIDs []string) ([]*ContentItem, error) {
|
func (c *DatabaseClient) GetBulkContent(siteID string, contentIDs []string) (map[string]ContentItem, error) {
|
||||||
switch c.database.GetDBType() {
|
switch c.database.GetDBType() {
|
||||||
case "sqlite3":
|
case "sqlite3":
|
||||||
contents, err := c.database.GetSQLiteQueries().GetBulkContent(context.Background(), sqlite.GetBulkContentParams{
|
contents, err := c.database.GetSQLiteQueries().GetBulkContent(context.Background(), sqlite.GetBulkContentParams{
|
||||||
@@ -73,9 +73,9 @@ func (c *DatabaseClient) GetBulkContent(siteID string, contentIDs []string) ([]*
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]*ContentItem, len(contents))
|
items := make(map[string]ContentItem)
|
||||||
for i, content := range contents {
|
for _, content := range contents {
|
||||||
items[i] = &ContentItem{
|
items[content.ID] = ContentItem{
|
||||||
ID: content.ID,
|
ID: content.ID,
|
||||||
SiteID: content.SiteID,
|
SiteID: content.SiteID,
|
||||||
Value: content.Value,
|
Value: content.Value,
|
||||||
@@ -94,9 +94,9 @@ func (c *DatabaseClient) GetBulkContent(siteID string, contentIDs []string) ([]*
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]*ContentItem, len(contents))
|
items := make(map[string]ContentItem)
|
||||||
for i, content := range contents {
|
for _, content := range contents {
|
||||||
items[i] = &ContentItem{
|
items[content.ID] = ContentItem{
|
||||||
ID: content.ID,
|
ID: content.ID,
|
||||||
SiteID: content.SiteID,
|
SiteID: content.SiteID,
|
||||||
Value: content.Value,
|
Value: content.Value,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package content
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -46,7 +46,7 @@ type ProcessedElement struct {
|
|||||||
// This will be implemented by database clients
|
// This will be implemented by database clients
|
||||||
type ContentClient interface {
|
type ContentClient interface {
|
||||||
GetContent(siteID, contentID string) (*ContentItem, error)
|
GetContent(siteID, contentID string) (*ContentItem, error)
|
||||||
GetBulkContent(siteID string, contentIDs []string) ([]*ContentItem, error)
|
GetBulkContent(siteID string, contentIDs []string) (map[string]ContentItem, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContentItem represents a piece of content from the database
|
// ContentItem represents a piece of content from the database
|
||||||
|
|||||||
8
justfile
8
justfile
@@ -54,7 +54,7 @@ dev: build-lib build
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Start demo site with prefixed output (this will block) - use local installation
|
# Start demo site with prefixed output (this will block) - use local installation
|
||||||
cd {{justfile_directory()}} && npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
|
cd {{justfile_directory()}} && npx --prefer-offline live-server test-sites/demo-site --port=3000 --host=localhost --open=/index.html 2>&1 | sed 's/^/🌐 [DEMO] /' &
|
||||||
DEMO_PID=$!
|
DEMO_PID=$!
|
||||||
|
|
||||||
# Wait for both processes
|
# Wait for both processes
|
||||||
@@ -70,7 +70,7 @@ dev-about: build-lib build
|
|||||||
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode &
|
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode &
|
||||||
SERVER_PID=$!
|
SERVER_PID=$!
|
||||||
sleep 3
|
sleep 3
|
||||||
npx --prefer-offline live-server demo-site --port=3000 --host=localhost --open=/about.html
|
npx --prefer-offline live-server test-sites/demo-site --port=3000 --host=localhost --open=/about.html
|
||||||
kill $SERVER_PID 2>/dev/null || true
|
kill $SERVER_PID 2>/dev/null || true
|
||||||
|
|
||||||
# Check project status and validate setup
|
# Check project status and validate setup
|
||||||
@@ -208,7 +208,7 @@ help:
|
|||||||
|
|
||||||
|
|
||||||
# Enhance demo site (build-time content injection)
|
# Enhance demo site (build-time content injection)
|
||||||
enhance input="demo-site" output="dist":
|
enhance input="test-sites/demo-site" output="dist":
|
||||||
./insertr enhance {{input}} --output {{output}} --mock
|
./insertr enhance {{input}} --output {{output}} --mock
|
||||||
|
|
||||||
# === Content API Server Commands ===
|
# === Content API Server Commands ===
|
||||||
@@ -267,7 +267,7 @@ status:
|
|||||||
@echo "\n🔧 Unified binary:"
|
@echo "\n🔧 Unified binary:"
|
||||||
@ls -la insertr main.go cmd/ internal/ 2>/dev/null || echo " Missing unified binary components"
|
@ls -la insertr main.go cmd/ internal/ 2>/dev/null || echo " Missing unified binary components"
|
||||||
@echo "\n🌐 Demo site:"
|
@echo "\n🌐 Demo site:"
|
||||||
@ls -la demo-site/index.html demo-site/about.html 2>/dev/null || echo " Missing demo files"
|
@ls -la test-sites/demo-site/index.html test-sites/demo-site/about.html 2>/dev/null || echo " Missing demo files"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo "🚀 Development Commands:"
|
@echo "🚀 Development Commands:"
|
||||||
@echo " just dev - Full-stack development (recommended)"
|
@echo " just dev - Full-stack development (recommended)"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rollup -c && npm run copy:demo",
|
"build": "rollup -c && npm run copy:demo",
|
||||||
"build:only": "rollup -c",
|
"build:only": "rollup -c",
|
||||||
"copy:demo": "cp dist/insertr.js ../demo-site/insertr.js",
|
"copy:demo": "cp dist/insertr.js ../test-sites/demo-site/insertr.js",
|
||||||
"watch": "rollup -c -w",
|
"watch": "rollup -c -w",
|
||||||
"dev": "rollup -c -w"
|
"dev": "rollup -c -w"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ function copyToDemo() {
|
|||||||
name: 'copy-to-demo',
|
name: 'copy-to-demo',
|
||||||
writeBundle() {
|
writeBundle() {
|
||||||
try {
|
try {
|
||||||
execSync('cp dist/insertr.js ../demo-site/insertr.js');
|
execSync('cp dist/insertr.js ../test-sites/demo-site/insertr.js');
|
||||||
console.log('📄 Copied to demo-site/insertr.js');
|
console.log('📄 Copied to test-sites/demo-site/insertr.js');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('⚠️ Failed to copy to demo-site:', error.message);
|
console.warn('⚠️ Failed to copy to test-sites/demo-site:', error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ const commands = {
|
|||||||
|
|
||||||
// Check files exist
|
// Check files exist
|
||||||
const requiredFiles = [
|
const requiredFiles = [
|
||||||
'demo-site/index.html',
|
'test-sites/demo-site/index.html',
|
||||||
'demo-site/about.html',
|
'test-sites/demo-site/about.html',
|
||||||
'lib/dist/insertr.js',
|
'lib/dist/insertr.js',
|
||||||
'lib/dist/insertr.min.js',
|
'lib/dist/insertr.min.js',
|
||||||
'cmd/serve.go',
|
'cmd/serve.go',
|
||||||
@@ -77,8 +77,8 @@ const commands = {
|
|||||||
console.log('\n📊 Project stats:');
|
console.log('\n📊 Project stats:');
|
||||||
|
|
||||||
// Count editable elements
|
// Count editable elements
|
||||||
const indexContent = fs.readFileSync('demo-site/index.html', 'utf8');
|
const indexContent = fs.readFileSync('test-sites/demo-site/index.html', 'utf8');
|
||||||
const aboutContent = fs.readFileSync('demo-site/about.html', 'utf8');
|
const aboutContent = fs.readFileSync('test-sites/demo-site/about.html', 'utf8');
|
||||||
const insertrMatches = (indexContent + aboutContent).match(/class="insertr"/g) || [];
|
const insertrMatches = (indexContent + aboutContent).match(/class="insertr"/g) || [];
|
||||||
console.log(` 📝 Editable elements: ${insertrMatches.length}`);
|
console.log(` 📝 Editable elements: ${insertrMatches.length}`);
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ sql:
|
|||||||
# SQLite configuration for development
|
# SQLite configuration for development
|
||||||
- name: "sqlite"
|
- name: "sqlite"
|
||||||
engine: "sqlite"
|
engine: "sqlite"
|
||||||
queries: ["db/queries/", "db/sqlite/setup.sql"]
|
queries: ["internal/db/queries/", "internal/db/sqlite/setup.sql"]
|
||||||
schema: "db/sqlite/schema.sql"
|
schema: "internal/db/sqlite/schema.sql"
|
||||||
gen:
|
gen:
|
||||||
go:
|
go:
|
||||||
package: "sqlite"
|
package: "sqlite"
|
||||||
@@ -18,8 +18,8 @@ sql:
|
|||||||
# PostgreSQL configuration for production
|
# PostgreSQL configuration for production
|
||||||
- name: "postgresql"
|
- name: "postgresql"
|
||||||
engine: "postgresql"
|
engine: "postgresql"
|
||||||
queries: ["db/queries/", "db/postgresql/setup.sql"]
|
queries: ["internal/db/queries/", "internal/db/postgresql/setup.sql"]
|
||||||
schema: "db/postgresql/schema.sql"
|
schema: "internal/db/postgresql/schema.sql"
|
||||||
gen:
|
gen:
|
||||||
go:
|
go:
|
||||||
package: "postgresql"
|
package: "postgresql"
|
||||||
|
|||||||
4127
test-sites/demo-site/insertr.js
Normal file
4127
test-sites/demo-site/insertr.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user