Merge pull request #12 from rfc1437/copilot/fix-two-open-issues

This commit is contained in:
Georg Bauer
2026-02-17 19:56:54 +01:00
committed by GitHub
4 changed files with 52 additions and 24 deletions

View File

@@ -255,7 +255,8 @@ export class MetaEngine extends EventEmitter {
try {
await this.ensureMetaDirExists();
const filePath = this.getProjectMetadataFilePath();
const content = JSON.stringify(this.projectMetadata, null, 2);
const { dataPath: _dataPath, ...persistedMetadata } = this.projectMetadata || {};
const content = JSON.stringify(persistedMetadata, null, 2);
await fs.writeFile(filePath, content, 'utf-8');
} catch (error) {
console.error('[MetaEngine] Failed to save project metadata:', error);
@@ -439,22 +440,11 @@ export class MetaEngine extends EventEmitter {
// Handle project metadata
if (projectMetadataFileExists) {
await this.loadProjectMetadata();
// Keep dataPath authoritative in database (selected folder path on create/open).
// If project.json has a stale dataPath, update project.json from database.
const projectData = await this.fetchProjectFromDatabase();
if (!projectData) {
throw new Error(`Project not found in database: ${this.currentProjectId}`);
}
const databaseDataPath = projectData.dataPath || undefined;
if (this.projectMetadata && this.projectMetadata.dataPath !== databaseDataPath) {
this.projectMetadata = {
...this.projectMetadata,
dataPath: databaseDataPath,
};
if (this.projectMetadata?.dataPath !== undefined) {
const { dataPath: _dataPath, ...metadataWithoutDataPath } = this.projectMetadata;
this.projectMetadata = metadataWithoutDataPath;
await this.saveProjectMetadata();
console.log(`[MetaEngine] Synced dataPath from database to project.json: ${databaseDataPath || '(default)'}`);
console.log('[MetaEngine] Removed deprecated dataPath from project.json');
}
} else {
// No file exists, fetch project data from database and create file
@@ -465,7 +455,6 @@ export class MetaEngine extends EventEmitter {
this.projectMetadata = {
name: projectData.name,
description: projectData.description || undefined,
dataPath: projectData.dataPath || undefined,
maxPostsPerPage: DEFAULT_MAX_POSTS_PER_PAGE,
};
await this.saveProjectMetadata();

View File

@@ -284,9 +284,9 @@ function buildCanonicalPostPath(post: PostData): string {
return `/${year}/${month}/${day}/${post.slug}`;
}
function getPageHtml(content: string, title: string): string {
function getPageHtml(content: string, title: string, language: string): string {
return `<!doctype html>
<html lang="en">
<html lang="${escapeHtml(language)}">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -452,7 +452,8 @@ export class PreviewServer {
return;
}
this.respond(res, 200, getPageHtml(result, resolvePageTitle(metadata, context.projectName, context.projectDescription)));
const language = metadata?.mainLanguage?.trim() || 'en';
this.respond(res, 200, getPageHtml(result, resolvePageTitle(metadata, context.projectName, context.projectDescription), language));
} catch (error) {
console.error('[PreviewServer] Request failed:', error);
this.respond(res, 500, 'Internal Server Error');