import parseStructureFile from "./parseStructureFile" ; import Summary from "../models/summary" ; import modifiers from "../modifiers" ; const SummaryModifier = modifiers . Summary ; param { Book } book return { Promise < Book > } function parseSummary ( book ) { const readme = book . getReadme ( ) ; const logger = book . getLogger ( ) ; const readmeFile = readme . getFile ( ) ; return parseStructureFile ( book , "summary" ) . spread ( ( file , result ) => { let summary ; if ( ! file ) { logger . warn . ln ( "no summary file in this book" ) ; summary = new Summary ( ) ; } else { logger . debug . ln ( "summary file found at" , file . getPath ( ) ) ; summary = Summary . createFromParts ( file , result . parts ) ; } const readmeArticle = summary . getByPath ( readmeFile . getPath ( ) ) ; if ( readmeFile . exists ( ) && ! readmeArticle ) { summary = SummaryModifier . unshiftArticle ( summary , { title : "Introduction" , ref : readmeFile . getPath ( ) , } ) ; } return book . setSummary ( summary ) ; } ) ; } export default parseSummary ;