From a5008a3646a31bbea0f76fae7edc5d12eeb01b33 Mon Sep 17 00:00:00 2001 From: echo Date: Sat, 28 Feb 2026 18:02:33 +0100 Subject: [PATCH] fix: add slug auto-generation fallback for articles without slugs - Add generateSlug() helper to create URL-friendly slugs from titles - Apply slug fallback in syncArticles() and syncSingleArticle() - Handles articles created before slug field was added to schema - Prevents 'slug cannot be null' database constraint errors --- backend/src/modules/strapi.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/src/modules/strapi.service.ts b/backend/src/modules/strapi.service.ts index b6285da..fe411e0 100644 --- a/backend/src/modules/strapi.service.ts +++ b/backend/src/modules/strapi.service.ts @@ -111,6 +111,17 @@ export class StrapiService { return {}; } + private generateSlug(title: string): string { + // Generate slug from title if missing + return title + .toLowerCase() + .trim() + .replace(/[^\w\s-]/g, '') // Remove special characters + .replace(/\s+/g, '-') // Replace spaces with hyphens + .replace(/-+/g, '-') // Replace multiple hyphens with single hyphen + .substring(0, 100); // Limit length + } + private async findOrCreateCategory( categorySlug: string, ): Promise { @@ -241,7 +252,7 @@ export class StrapiService { title: strapiArticle.title, excerpt: strapiArticle.description, content: strapiArticle.content, - slug: strapiArticle.slug, + slug: strapiArticle.slug || this.generateSlug(strapiArticle.title), status: strapiArticle.publishedAt ? ArticleStatus.PUBLISHED : ArticleStatus.DRAFT, @@ -328,7 +339,7 @@ export class StrapiService { title: strapiArticle.title, excerpt: strapiArticle.description, content: strapiArticle.content, - slug: strapiArticle.slug, + slug: strapiArticle.slug || this.generateSlug(strapiArticle.title), status, tags: [], featuredImage: imageUrl,