I’m loving DatoCMS and mostly been cruising along developing with it, but I’ve been pulling my hair out trying to solve a recent problem and I think I finally diagnosed it as maybe a bug?
I’m using Hugo with DatoCMS and have my config file set up to output .md files in yaml format. One example:
root.directory("content/exhibitions", (dir) => {
dato.exhibitions.forEach((exhibition) => {
dir.createPost(`${exhibition.slug}.md`, "yaml", {
frontmatter: {
title: exhibition.title,
slug: exhibition.slug,
exhibition_type: exhibition.exhibitionType,
exhibition_space: exhibition.exhibitionSpace,
opening_date: exhibition.openingDate,
closing_date: exhibition.closingDate,
gallery_artists: exhibition.galleryArtists.toMap(),
other_artists: exhibition.otherArtists.toMap(),
exhibition_images: exhibition.exhibitionImages.toMap(),
main_image: exhibition.image.toMap()
},
});
})
});
Which outputs the .md file as expected and I have no trouble working with the data:
title: Exhibition 1
slug: exhibition-1
exhibition_type: Solo
exhibition_space: Downstairs
opening_date: 2021-10-05T00:00:00.000Z
closing_date: 2021-12-24T00:00:00.000Z
gallery_artists:
- id: '54674262'
itemType: artist
updatedAt: '2021-08-31T14:14:06.952Z'
createdAt: '2021-08-30T16:36:01.502Z'
groupExhibitions:
- id: '54674258'
itemType: group_exhibition
updatedAt: '2021-08-31T02:53:16.562Z'
createdAt: '2021-08-30T16:36:01.467Z'
exhibition: My Frontyard
year: '2021'
[...]
Then later in the config, I have the following block:
root.directory("content/news", (dir) => {
dir.createPost(`news.md`, "yaml", {
frontmatter: {
article: dato.news.article.toMap()
},
});
});
But when that outputs the data related to “article” in a map, it formats it as follows:
article:
- id: '55007998'
itemType: article
updatedAt: '2021-09-01T14:33:38.886Z'
createdAt: '2021-09-01T14:33:38.882Z'
slug: highlights-from-nada-new-york
artists:
id: '54674262'
itemType: artist
updatedAt: '2021-08-31T14:14:06.952Z'
createdAt: '2021-08-30T16:36:01.502Z'
[...]
Note that in the second map, the data below “artists” does not lead with the dash. This makes that information inaccessible via Hugo. It throws the error: can't evaluate field lastName in type interface {}
If I manually reformat the markdown file to the following, adding the dash and an extra tab:
article:
- id: '55007998'
itemType: article
updatedAt: '2021-09-01T14:33:38.886Z'
createdAt: '2021-09-01T14:33:38.882Z'
slug: highlights-from-nada-new-york
artists:
- id: '54674262'
itemType: artist
updatedAt: '2021-08-31T14:14:06.952Z'
createdAt: '2021-08-30T16:36:01.502Z'
[...]
Then I can access the data perfectly fine.
My question: why is the DatoCMS .toMap() function formatting the two sets of data differently? They are mapping the exact same data, as they are both pulling from the same linked reference.