diff --git a/src/post.ts b/src/post.ts index 11dea2c..26a7c79 100644 --- a/src/post.ts +++ b/src/post.ts @@ -90,17 +90,22 @@ export class ChatGptHelper implements GeneratorHelperInterface { return await this.getHeadingContent(postOutline.sections, headingLevel, '', '') } - private async getHeadingContent (sections : Section[], headingLevel : number, htmlContent : string, sectionDescription : string) : Promise { + private async getHeadingContent (sections: Section[], headingLevel: number, htmlContent: string, sectionDescription: string): Promise { return await sections.reduce(async (htmlContentPromise, section) => { let htmlContent = await htmlContentPromise htmlContent += `${section.title}\n` - if (section.sections) { - htmlContent += await this.getHeadingContent(section.sections, headingLevel + 1, htmlContent, sectionDescription + ' >> ' + section.title) - return Promise.resolve(htmlContent) - } else { - htmlContent += await this.getChapterContent(this.postPrompt.language, sectionDescription + ' >> ' + section.title, section.keywords) - return Promise.resolve(htmlContent) + + const generateHtmlContent = async (withSections: boolean, sectionTitle: string) => { + if (withSections) { + return await this.getHeadingContent(section.sections, headingLevel + 1, htmlContent, sectionDescription + ' >> ' + sectionTitle) + } else { + return await this.getChapterContent(this.postPrompt.language, sectionDescription + ' >> ' + sectionTitle, section.keywords) + } } + + htmlContent += await generateHtmlContent(!!section.sections, section.title) + + return Promise.resolve(htmlContent) }, Promise.resolve('')) }