feat: Update filename with path field
This commit is contained in:
parent
3af1ef11f7
commit
ab796326f1
13
index.js
13
index.js
|
@ -2,6 +2,7 @@ import { Directus } from '@directus/sdk'
|
||||||
import yaml from 'js-yaml'
|
import yaml from 'js-yaml'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import Axios from 'axios'
|
import Axios from 'axios'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
export default class DirectusToMarkdown {
|
export default class DirectusToMarkdown {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
|
@ -25,12 +26,16 @@ export default class DirectusToMarkdown {
|
||||||
const frontMatter = this._formatFrontMatter(item, deleteFields)
|
const frontMatter = this._formatFrontMatter(item, deleteFields)
|
||||||
const content = item[this.contentKey] ? item[this.contentKey].toString() : ''
|
const content = item[this.contentKey] ? item[this.contentKey].toString() : ''
|
||||||
const itemContent = `${frontMatter}${content}\r\n`
|
const itemContent = `${frontMatter}${content}\r\n`
|
||||||
const indexName = 'index' // TODO: index or _index ?
|
const filePath = `${itemPath}/${item.path ? item.path : 'index.md'}`
|
||||||
fs.writeFileSync(`${itemPath}/${indexName}.md`, itemContent)
|
const fileDirname = path.dirname(filePath)
|
||||||
|
if (!fs.existsSync(fileDirname)) {
|
||||||
|
fs.mkdirSync(fileDirname, { recursive: true });
|
||||||
|
}
|
||||||
|
fs.writeFileSync(filePath, itemContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
async _writeFile(response, path) {
|
async _writeFile(response, filePath) {
|
||||||
const writer = fs.createWriteStream(path)
|
const writer = fs.createWriteStream(filePath)
|
||||||
|
|
||||||
response.data.pipe(writer)
|
response.data.pipe(writer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue