Map content to new structure
Define how to map your exported content to your new content model. To make the mapping easier, use the Kontent.ai Migration toolkit to ensure your content items and assets are correctly structured and referenced in your new project.
Mapping on paper
Before you start writing the mapping logic in code, we recommend you first define the mapping visually. You can do this on digital or analog paper. Visual mapping lets you and other stakeholders see how your existing content fits within the new content model. You’ll see which parts fit and which don’t. If a part doesn’t fit, you can adjust the content model or discard that part if it’s not needed. This lets you find possible gaps in your content model early on.Example mapping
Check the following diagram to see how an existing structure used for blog posts in one system can be mapped to a content model in Kontent.ai. The Kontent.ai content model in the example is based on the Article content modeling accelerator. Notice that the Blog post’s fields don’t always map one-to-one to the Article’s elements; sometimes, you need to transform the existing content to another format. Text fields can usually be mapped 1:1. For anything more complex, there is often a transformation involved.Mapping on paper can reveal gaps in your model. In this case, the Article’s Subtitle and Tags elements don’t match any of the original Blog post’s fields. In your case, it might be the other way around—some of the original fields might not match elements in the new model. For example, you might have fields that define visual information that you no longer need.If this happens, you might want to remove these extra elements unless you plan to use them for mapping from other types of content as well.
Mapping in code
Once you’ve verified everything on paper, you can move to the real thing. To simplify the mapping in code, use the Kontent.ai Migration toolkitInstall the Migration toolkit
To get started, create a Node.js app and install the Migration toolkit by running the following command in the terminal.Migration toolkit 101
To migrate your exported content to a Kontent.ai project with the Migration toolkit, you need to:- Map your textual and structured content to the
MigrationItem
objects. - Map your binary files to the
MigrationAsset
objects. - Import the mapped content from the
MigrationItem
andMigrationAsset
objects to your Kontent.ai project.
Let’s now see how to map content items and assets.
Map exported content to content items
Kontent.ai stores content in content items. Depending on the number of languages in your project, each content item has one or more content item variants. The Migration toolkit’sMigrationItem
represents a single localized variant of a content item. This includes the variant’s metadata and elements. The specific elements depend on the content item’s content type. With each MigrationItem
, you can choose to specify content for the content item variant’s latest version, published version, or both.
The following example shows how you can map content to a
MigrationItem
. We recommend using strongly typed models for the MigrationItem
objects.
Parse rich text content
Plan for any necessary parsing of your existing rich text content to map it to the HTML5 rich text format supported by Kontent.ai’s Management API. Remember that the rich text editor in Kontent.ai doesn’t support custom visual formatting, such as setting text color or font size, for a reasonMap binary files to assets
The Migration toolkit’sMigrationAsset
represents a single asset. You can reference assets by codenames in multiple MigrationItem
objects. Every asset can specify localized asset descriptions for use as alt text.
Putting it together
Now that you know how to map your content and binary files to the migration objects, create mapping logic for your existing types of content.Once you have all the content mapped, you can start importing it to your project.