import Immutable from "immutable" ; import timing from "../utils/timing" ; import Page from "../models/page" ; import walkSummary from "./walkSummary" ; import parsePage from "./parsePage" ; param { Book } book param { string } filePath return { Page ? } function parseFilePage ( book , filePath ) { const fs = book . getContentFS ( ) ; return fs . statFile ( filePath ) . then ( ( file ) => { const page = Page . createForFile ( file ) ; return parsePage ( book , page ) ; } , ( err ) => { return null ; } ) . fail ( ( err ) => { const logger = book . getLogger ( ) ; logger . error . ln ( `error while parsing page "${ filePath }":` ) ; throw err ; } ) ; } param { Book } book return { Promise < OrderedMap < Page > > } function parsePagesList ( book ) { const summary = book . getSummary ( ) ; const glossary = book . getGlossary ( ) ; let map = Immutable . OrderedMap ( ) ; return ( timing . measure ( "parse.listPages" , walkSummary ( summary , ( article ) => { if ( ! article . isPage ( ) ) return ; const filepath = article . getPath ( ) ; if ( book . isContentFileIgnored ( filepath ) ) return ; return parseFilePage ( book , filepath ) . then ( ( page ) => { if ( ! page ) { return ; } map = map . set ( filepath , page ) ; } ) ; } ) ) . then ( ( ) => { const file = glossary . getFile ( ) ; if ( ! file . exists ( ) ) { return ; } return parseFilePage ( book , file . getPath ( ) ) . then ( ( page ) => { if ( ! page ) { return ; } map = map . set ( file . getPath ( ) , page ) ; } ) ; } ) . then ( ( ) => { return map ; } ) ) ; } export default parsePagesList ;