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
|
||||
sites: # Registered sites for file-based enhancement
|
||||
- site_id: "demo"
|
||||
path: "./demo-site"
|
||||
path: "./test-sites/demo-site"
|
||||
domain: "localhost:3000"
|
||||
auto_enhance: true
|
||||
backup_originals: true
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// Enhancer combines parsing and content injection using unified engine
|
||||
type Enhancer struct {
|
||||
engine *engine.ContentEngine
|
||||
injector *Injector
|
||||
// injector functionality will be integrated into engine
|
||||
}
|
||||
|
||||
// NewEnhancer creates a new HTML enhancer using unified engine
|
||||
@@ -27,7 +27,6 @@ func NewEnhancer(client ContentClient, siteID string) *Enhancer {
|
||||
|
||||
return &Enhancer{
|
||||
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
|
||||
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() {
|
||||
case "sqlite3":
|
||||
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
|
||||
}
|
||||
|
||||
items := make([]*ContentItem, len(contents))
|
||||
for i, content := range contents {
|
||||
items[i] = &ContentItem{
|
||||
items := make(map[string]ContentItem)
|
||||
for _, content := range contents {
|
||||
items[content.ID] = ContentItem{
|
||||
ID: content.ID,
|
||||
SiteID: content.SiteID,
|
||||
Value: content.Value,
|
||||
@@ -94,9 +94,9 @@ func (c *DatabaseClient) GetBulkContent(siteID string, contentIDs []string) ([]*
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]*ContentItem, len(contents))
|
||||
for i, content := range contents {
|
||||
items[i] = &ContentItem{
|
||||
items := make(map[string]ContentItem)
|
||||
for _, content := range contents {
|
||||
items[content.ID] = ContentItem{
|
||||
ID: content.ID,
|
||||
SiteID: content.SiteID,
|
||||
Value: content.Value,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package content
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -46,7 +46,7 @@ type ProcessedElement struct {
|
||||
// This will be implemented by database clients
|
||||
type ContentClient interface {
|
||||
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
|
||||
|
||||
8
justfile
8
justfile
@@ -54,7 +54,7 @@ dev: build-lib build
|
||||
echo ""
|
||||
|
||||
# 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=$!
|
||||
|
||||
# Wait for both processes
|
||||
@@ -70,7 +70,7 @@ dev-about: build-lib build
|
||||
INSERTR_DATABASE_PATH=./dev.db ./insertr serve --dev-mode &
|
||||
SERVER_PID=$!
|
||||
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
|
||||
|
||||
# Check project status and validate setup
|
||||
@@ -208,7 +208,7 @@ help:
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
# === Content API Server Commands ===
|
||||
@@ -267,7 +267,7 @@ status:
|
||||
@echo "\n🔧 Unified binary:"
|
||||
@ls -la insertr main.go cmd/ internal/ 2>/dev/null || echo " Missing unified binary components"
|
||||
@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 "🚀 Development Commands:"
|
||||
@echo " just dev - Full-stack development (recommended)"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"scripts": {
|
||||
"build": "rollup -c && npm run copy:demo",
|
||||
"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",
|
||||
"dev": "rollup -c -w"
|
||||
},
|
||||
|
||||
@@ -8,10 +8,10 @@ function copyToDemo() {
|
||||
name: 'copy-to-demo',
|
||||
writeBundle() {
|
||||
try {
|
||||
execSync('cp dist/insertr.js ../demo-site/insertr.js');
|
||||
console.log('📄 Copied to demo-site/insertr.js');
|
||||
execSync('cp dist/insertr.js ../test-sites/demo-site/insertr.js');
|
||||
console.log('📄 Copied to test-sites/demo-site/insertr.js');
|
||||
} 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
|
||||
const requiredFiles = [
|
||||
'demo-site/index.html',
|
||||
'demo-site/about.html',
|
||||
'test-sites/demo-site/index.html',
|
||||
'test-sites/demo-site/about.html',
|
||||
'lib/dist/insertr.js',
|
||||
'lib/dist/insertr.min.js',
|
||||
'cmd/serve.go',
|
||||
@@ -77,8 +77,8 @@ const commands = {
|
||||
console.log('\n📊 Project stats:');
|
||||
|
||||
// Count editable elements
|
||||
const indexContent = fs.readFileSync('demo-site/index.html', 'utf8');
|
||||
const aboutContent = fs.readFileSync('demo-site/about.html', 'utf8');
|
||||
const indexContent = fs.readFileSync('test-sites/demo-site/index.html', 'utf8');
|
||||
const aboutContent = fs.readFileSync('test-sites/demo-site/about.html', 'utf8');
|
||||
const insertrMatches = (indexContent + aboutContent).match(/class="insertr"/g) || [];
|
||||
console.log(` 📝 Editable elements: ${insertrMatches.length}`);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ sql:
|
||||
# SQLite configuration for development
|
||||
- name: "sqlite"
|
||||
engine: "sqlite"
|
||||
queries: ["db/queries/", "db/sqlite/setup.sql"]
|
||||
schema: "db/sqlite/schema.sql"
|
||||
queries: ["internal/db/queries/", "internal/db/sqlite/setup.sql"]
|
||||
schema: "internal/db/sqlite/schema.sql"
|
||||
gen:
|
||||
go:
|
||||
package: "sqlite"
|
||||
@@ -18,8 +18,8 @@ sql:
|
||||
# PostgreSQL configuration for production
|
||||
- name: "postgresql"
|
||||
engine: "postgresql"
|
||||
queries: ["db/queries/", "db/postgresql/setup.sql"]
|
||||
schema: "db/postgresql/schema.sql"
|
||||
queries: ["internal/db/queries/", "internal/db/postgresql/setup.sql"]
|
||||
schema: "internal/db/postgresql/schema.sql"
|
||||
gen:
|
||||
go:
|
||||
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