Skip to content

Commit

Permalink
Fix: use existing File to retrieve navigation instead
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Nov 25, 2020
1 parent 71273cb commit e9c5760
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions classes/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const Bluebird = require('bluebird')
const _ = require('lodash')

const { Config } = require('./Config.js')
const { File, CollectionPageType } = require('./File.js')
const { File, CollectionPageType, DataType } = require('./File.js')
const { Navigation } = require('./Navigation.js')
const { deslugifyCollectionName } = require('../utils/utils.js')

const NAV_FILE_NAME = 'navigation.yml'

class Collection {
constructor(accessToken, siteName) {
this.accessToken = accessToken
Expand Down Expand Up @@ -41,8 +43,10 @@ class Collection {

await config.update(newContent, sha)

const nav = new Navigation(this.accessToken, this.siteName)
const { content:navContent, sha:navSha } = await nav.read()
const nav = new File(this.accessToken, this.siteName)
const dataType = new DataType()
nav.setFileType(dataType)
const { content:navContent, sha:navSha } = await nav.read(NAV_FILE_NAME)
const navContentObject = yaml.safeLoad(base64.decode(navContent))

navContentObject.links.push({
Expand All @@ -51,7 +55,7 @@ class Collection {
})
const newNavContent = base64.encode(yaml.safeDump(navContentObject))

await nav.update(newNavContent, navSha)
await nav.update(NAV_FILE_NAME, newNavContent, navSha)

} catch (err) {
throw err
Expand Down

0 comments on commit e9c5760

Please sign in to comment.