Skip to content

Commit

Permalink
Simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
christophebe committed Mar 18, 2023
1 parent 378d601 commit 47ee5c8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
private async getHeadingContent (sections: Section[], headingLevel: number, htmlContent: string, sectionDescription: string): Promise<string> {
return await sections.reduce(async (htmlContentPromise, section) => {
let htmlContent = await htmlContentPromise
htmlContent += `<h${headingLevel}>${section.title}</h${headingLevel}>\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(''))
}

Expand Down

0 comments on commit 47ee5c8

Please sign in to comment.