This will add all .svg
icons to a Single-line string
field using the Accept only specified values
required validator. The script will read all SVG files from with a directory and then update the correspondind model field with the values, you can then use them to select inline icons within model content.
Created
April 28, 2019 08:05
-
-
Save panoply/3ec057644891f8ef45fb9d915e5c8a73 to your computer and use it in GitHub Desktop.
DatoCMS Icons SVG Select values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() // read the `.env` file for API token | |
const fs = require('fs') | |
const path = require('path') | |
const { SiteClient } = require('datocms-client') | |
const field = '296844' | |
const client = new SiteClient(process.env.DATO_API_TOKEN) | |
const icons = fs | |
.readdirSync('./source/icons') | |
.map(i => path.extname(i) === '.svg' && i.substring(0, i.length - 4)) | |
client.fields | |
.update(field, { | |
validators: { | |
enum: { | |
values: icons | |
} | |
} | |
}) | |
.then(field => { | |
console.log(field) | |
}) | |
.catch(error => { | |
console.log(error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment