const yaml = require('js-yaml');
const fs   = require('fs');

const doc = yaml.loadAll(fs.readFileSync('../content/portfolioPage.md', 'utf8'));
// console.log(doc)
console.log(doc[0].portfolio)

portfolio=doc[0].portfolio


portfolioEN = portfolio.map(item => {
    return {
        logo:item.logo,
        logo2:item.logo2,
        sinceDate:item.sinceDate,
        nameEN:item.nameEN,
        type:item.type,
        website:item.website,
        descriptionEN:item.descriptionEN,
    }
})

// const portfolio = {
try {
    let str = yaml.dump(portfolioEN)
    str = `---
portfolioEN:
${str}
---`
  fs.writeFile('../content/portfolioEN.md', str, function (error) {
    if (error) {
      console.log('写入失败')
    } else {
      console.log('写入成功了')
    }
  })
} catch(e) {
    console.log(e)
}