Converting markdown to structured content i DatoCMS

Hi,
Our team is looking into using DatoCMS for our new website project. Currently, all our website content is generated and structured in Airtable. Therefore, we are looking for a setup where we can integrate Airtable content into our CMS.

When we generate new content in Airtable, we want to create a new record in DatoCMS. I saw that Dato has recently launched a feature for converting Markdown to structured content, but what about the other way around?

Our marketing setup is currently Airtable and Make. Does anybody have experience with a similar setup approach, since we would not actively be managing content in Dato, but as much as possible externally through the systems that we already use. Is it possible without a serverless function to convert Markdown to structured text when we create new records?

Hello @alfred.steensen and welcome to the community!

TL;DR: What you are looking for is this: Markdown to Structured Text migration

Yes, this setup is totally doable. A lot of teams keep Airtable as the source of truth and use Make to push content into DatoCMS via the Content Management API. In Make, this is usually just an Airtable trigger followed by an HTTP request to the CMA (overview: https://www.datocms.com/docs/content-management-api). Creating a record is documented here: https://www.datocms.com/docs/content-management-api/resources/item/create and, if your model uses the draft/published system, you can publish right after creation with https://www.datocms.com/docs/content-management-api/resources/item/publish (otherwise the record will stay in Draft).

On the Markdown and Structured Text part: Structured Text is not stored as Markdown on the API, it’s stored as a DAST JSON document (spec here: https://www.datocms.com/docs/structured-text/dast). So if you create records via API and the target field is Structured Text, you need to send valid DAST JSON, not a Markdown string.

If your team is already authoring Markdown in Airtable and you do not need Structured Text features like embedded blocks and record links, the simplest approach is to use a multi paragraph text field configured to use Markdown. That way you can send the Markdown straight through from Airtable with no conversion step at all (see “Multi paragraph Text” here: https://www.datocms.com/user-guides/content-modeling/intro-to-string-text-fields).

If you do want to keep Markdown in Airtable but store it in a Structured Text field in DatoCMS, the conversion has to run somewhere before you call the CMA. We provide conversion utilities as libraries (the “Migrating Markdown content” section shows the typical approach: https://www.datocms.com/docs/structured-text/migrating-content-to-structured-text and the underlying package is https://www.npmjs.com/package/datocms-html-to-structured-text), but the CMA itself does not automatically convert Markdown into Structured Text for you. So unless you can run that conversion code inside Make (which is often tricky if you need npm dependencies), you’d normally add a small code step somewhere (a lightweight serverless function or any tiny service) to do Markdown to DAST and then POST the result to Dato.

For the other direction, Structured Text back into Markdown, we did release an official renderer recently: https://www.datocms.com/product-updates/introducing-datocms-structured-text-to-markdown and the npm package is https://www.npmjs.com/package/datocms-structured-text-to-markdown.

2 Likes

Hi,

Thanks for your quick reply. That makes sense, and we would really like to avoid setting up edge/serverless functions to minimize technical overhead for the marketing team.

We are currently trying to build our own script in Airtable to convert Markdown into the JSON structure required for the DAST format. We also plan to maintain a mirrored table for the media library in both Airtable and DatoCMS, so we can store the correct corresponding DatoCMS IDs for media assets when our rich content is created.

I hope this approach will work well. Otherwise, as you mentioned, the way forward would probably be to set up a small serverless function :slight_smile:

1 Like

You might be able to do that with the Airtable Scripting app https://airtable.com/marketplace/blkQyAKhJoGKqnR0T/scripting and maybe a guide like this one: https://simplescraper.io/blog/complete-guide-airtable-scripting

You should also be able to add JS snippets into your Make.com workflow to do something similar, if that’s better

I have a bit of experience with both those systems (though it’s been a couple years), so let me know if you need help with getting that working!

But also, I suppose I should ask what your intended architecture here is, at a higher level. If Airtable is your source of truth, what is the reason for wanting to clone it into Dato too? (Like, why sync it at all, either one-way or both ways?)

They can both act as content repositories, so in a way they’re both doing the same thing. Another option you can consider is, for example, having your frontend fetch from both systems separately and then combining them (it’s all headless, after all). In Dato, if you want your editors to be able to see your Airtable stuff, that could be a simple plugin or even an iframe of the published Airtable data.

It just depends on how you envision these two systems working together, both for the machines (your API and frontend) and the humans (your editors)… happy to discuss more if helpful, but if you already know what you’re doing, don’t let me stop you :slight_smile:

Oh… and… one last thing, sorry! When you say:

If you’re not going to be doing edits in Dato, why even convert to Structured Text? We do natively support Markdown fields, so you can directly sync the Markdown into your Dato records if that’s easier…?