Go to file
Simon 869c4f82c1 Merge pull request 'feat: Download picture on array keys' (#5) from picture_download into main
## Détails

- permet de télécharger les images depuis directus qui sont contenu dans un array

## Pourquoi

Pour faciliter l'import d'images

Reviewed-on: https://git.weko.io/resilien/directus-to-markdown/pulls/5
2022-04-29 12:18:05 +02:00
.gitignore feat: Create library 2022-01-27 12:41:28 +01:00
README.md feat: Add deleteFields field to delete keys on markdown front matter 2022-02-23 16:13:39 +01:00
index.js feat: Download picture on array keys 2022-04-29 12:15:43 +02:00
package-lock.json feat: Download picture on array keys 2022-04-29 12:15:43 +02:00
package.json feat: Download picture on array keys 2022-04-29 12:15:43 +02:00

README.md

Directus To Markdown

This library export Directus items collections to markdown files with assets.

I used it to export article from Directus to Hugo website.

Configuration

Directus

This library export data from an Directus so you should specify an url and token.

With environment variables:

export DIRECTUS_URL=https://your.directus.url
export DIRECTUS_TOKEN=your-token

or on configuration parameters:

const config = {
  url: 'https://your.directus.url',
  token: 'your-token',
  ...
}

Collection Name

The key of collections object should be the name of Directus Collection:

const config = {
  collections: {
    news: { ... },
    pages: { ... }
  }
}

Content key

default: content

You can modify the field of the content:

const config = {
  contentKey: 'body',
  ...
}

deleteFields

Delete keys on markdown front matter:

const config = {
  deleteFields: ['id', 'jobs'],
  ...
}

readByQueryOption

readByQueryOption match https://docs.directus.io/reference/sdk/#read-by-query

Export to specific path

For each collection you should an pathBuilder.

Example

import DirectusToMarkdown from '@resilien/directus-to-markdown'
import urlslug from 'url-slug'

const config = {
  url: 'https://your.directus.url',
  token: 'your-token',
  contentKey: 'body',
  collections: {
    news: {
      readByQueryOption: {
        fields: ['title', 'slug', 'date', 'image', 'image_credit', 'draft', 'body'],
        filter: { draft: { _eq: 'false' } },
        limit: -1
      },
      pathBuilder: (article) => {
        if (article.slug) {
          return `./content/news/${article.slug}`
        }
        return `./content/news/${article.date}-${urlslug(article.title, { remove: /\./g })}`;
      }
    }
  }
}

new DirectusToMarkdown(config).export();