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,