feat: implement unified content engine to eliminate ID generation inconsistencies

- Create internal/engine module as single source of truth for content processing
- Consolidate 4 separate ID generation systems into one unified engine
- Update API handlers to use engine for consistent server-side ID generation
- Remove frontend client-side ID generation, delegate to server engine
- Ensure identical HTML markup + file path produces identical content IDs
- Resolve content persistence failures caused by ID fragmentation between manual editing and enhancement processes
This commit is contained in:
2025-09-16 15:04:27 +02:00
parent c1bc28d107
commit 84c90f428d
12 changed files with 1426 additions and 267 deletions

View File

@@ -29,21 +29,22 @@ export class ApiClient {
}
async createContent(contentId, content, type, elementContext = null) {
async createContent(contentId, content, type, htmlMarkup = null) {
try {
const payload = {
value: content,
type: type
type: type,
file_path: this.getCurrentFilePath() // Always include file path for consistent ID generation
};
if (contentId) {
// Enhanced site - provide existing ID
payload.id = contentId;
} else if (elementContext) {
// Non-enhanced site - provide context for backend ID generation
payload.element_context = elementContext;
} else if (htmlMarkup) {
// Non-enhanced site - provide HTML markup for unified engine ID generation
payload.html_markup = htmlMarkup;
} else {
throw new Error('Either contentId or elementContext must be provided');
throw new Error('Either contentId or htmlMarkup must be provided');
}
const response = await fetch(`${this.baseUrl}?site_id=${this.siteId}`, {
@@ -283,4 +284,17 @@ export class ApiClient {
return false;
}
/**
* Get current file path from URL for consistent ID generation
* @returns {string} File path like "index.html", "about.html"
*/
getCurrentFilePath() {
const path = window.location.pathname;
if (path === '/' || path === '') {
return 'index.html';
}
// Remove leading slash: "/about.html" → "about.html"
return path.replace(/^\//, '');
}
}