亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何根據來自多個降價文件的數據編寫 JSON 文件

如何根據來自多個降價文件的數據編寫 JSON 文件

海綿寶寶撒 2021-06-28 12:42:27
我需要使用 Markdown 文件中的數據構建 API。我有大約 100 個 Markdown 文件,文件頂部有這樣的數據:---title: Lorem ipsumcategory: componentprimaryKeywords: curved horizonsecondaryKeywords: css block content seperator---所需的輸出是單個 .json 文件,其中包含來自我的 .md 文件的所有數據作為數組中的對象。例子:[  {    "title": "Lorem ipsum",    "category": "component",    "primaryKeywords": "curved horizon",    "secondaryKeywords": "css block content seperator"  },  {    "title": "Lorem ipsum",    "category": "component",    "primaryKeywords": "curved horizon",    "secondaryKeywords": "css block content seperator"  },  {    "title": "Lorem ipsum",    "category": "component",    "primaryKeywords": "curved horizon",    "secondaryKeywords": "css block content seperator"  }]JSON 文件應該作為我的前端構建的一部分生成。我正在使用吞咽。我試過做這樣的事情:gulp.task('search-api', function (cb) {  const fs = require('fs');  const matter = require('gray-matter');  const str = fs.readFileSync('./src/docs/01-Components/02-Layout/03-bow.md', 'utf8');  console.log(matter(str));});我可以在控制臺中顯示來自 1 個文件的數據。但我需要幫助來顯示所有文件中的數據./src/docs/,然后將其合并為 1 個結果并將其解析為 1 個 JSON 文件。我怎樣才能做到這一點?感謝所有幫助和建議。
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號