scripts/lib/generators/post.js
/**
   * Transform post data into API formats.
   * @returns void
   */
Transform post data into API formats.
@returns void
Transform post data into API formats . @returns void
transform() {
    if (this.count <= 0) return
    let prevPost = {}
    let dummyList = []
    let featureIndexes = []
    const dummyFeaturesIndexes = []
    const featureLimit = 3
    this.sortByDate()
    this.data.forEach((post, index) => {
      let current = postMapper(post, this.configs)
      current.prev_post = prevPost
      current.next_post = {}
      prevPost = postListMapper(current, this.configs)
      if ((index !== 0) & (index !== this.data.length - 1)) {
        dummyList[index - 1].next_post = postListMapper(current, this.configs)
      }
      dummyList.push(current)
      if (dummyFeaturesIndexes.length < featureLimit)
        dummyFeaturesIndexes.push(index)
      if (
        Boolean(current.feature) === true &&
        featureIndexes.length < featureLimit
      )
        featureIndexes.push(index)
    })
    if (featureIndexes.length === 0) {
      featureIndexes = dummyFeaturesIndexes
    } else if (featureIndexes.length < featureLimit) {
      dummyFeaturesIndexes.forEach(function (postIndex) {
        if (featureIndexes.length < featureLimit && !featureIndexes[postIndex])
          featureIndexes.push(postIndex)
      })
    }
    this.features = featureIndexes.map(function (postIndex) {
      return dummyList[postIndex]
    })
    this.data = dummyList
  }
transform ( ) { if ( this . count <= 0 ) return let prevPost = { } let dummyList = [ ] let featureIndexes = [ ] const dummyFeaturesIndexes = [ ] const featureLimit = 3 this . sortByDate ( ) this . data . forEach ( ( post , index ) => { let current = postMapper ( post , this . configs ) current . prev_post = prevPost current . next_post = { } prevPost = postListMapper ( current , this . configs ) if ( ( index !== 0 ) & ( index !== this . data . length - 1 ) ) { dummyList [ index - 1 ] . next_post = postListMapper ( current , this . configs ) } dummyList . push ( current ) if ( dummyFeaturesIndexes . length < featureLimit ) dummyFeaturesIndexes . push ( index ) if ( Boolean ( current . feature ) === true && featureIndexes . length < featureLimit ) featureIndexes . push ( index ) } ) if ( featureIndexes . length === 0 ) { featureIndexes = dummyFeaturesIndexes } else if ( featureIndexes . length < featureLimit ) { dummyFeaturesIndexes . forEach ( function ( postIndex ) { if ( featureIndexes . length < featureLimit && ! featureIndexes [ postIndex ] ) featureIndexes . push ( postIndex ) } ) } this . features = featureIndexes . map ( function ( postIndex ) { return dummyList [ postIndex ] } ) this . data = dummyList }
Transform post data into API formats.
Transform post data into API formats .
// Used when feature posts is not enough // Save the feature post data. // If feature pots are not enough. // Fill in posts until reaches featureLimit.