friends-of-hugo / contentful-export

Extract Contentful to Hugo
MIT License
23 stars 8 forks source link

Reference fields, including content type folder with filename.md #29

Closed bzerangue closed 6 years ago

bzerangue commented 6 years ago

On reference fields, it only lists the filename.md in the front matter.

Example...

lessons:
- 3op5VIqGZiwoe06c8IQIMO.md
- 5p9qNpTOJaCE6ykC4a8Wqg.md
- 1zwAjpe38UC8iqKMM6gu0Q.md
- 3KinTi83FecuMeiUo0qGU4.md

And that causes a problem if you are refererring to multiple content types. Would it be possible to add the folder of the content type along with the filename in the the reference field, like so???

lessons:
- programming/3op5VIqGZiwoe06c8IQIMO.md
- administration/5p9qNpTOJaCE6ykC4a8Wqg.md
- programming/1zwAjpe38UC8iqKMM6gu0Q.md
- accounting/3KinTi83FecuMeiUo0qGU4.md

As a guy who is very Golang illiterate, this looks like the place you are defining this frontmatter? https://github.com/adriaandejonge/contentful-hugo/blob/7ab0c690f2a5a78beba76d6c2d798bbb0120c04a/translate/translate.go#L103

Could you point in the direction to adding the directory of the content types?

gawin commented 6 years ago

@bzerangue currently implementing Hugo and I came across the same issue. I was already wonder how others would render a partial if you don't know the contenttype directory. Anyways, since we needed this I decided to fix this.

Besides me spending some time figuring out how Go works.... the main challenge is that Contentful does not expose the ContentType in the sys reference fields in their API:

 "sys": {
  "type": "Link",
  "linkType": "Entry",
  "id": "3hzaoKf49QakqgccMkyWbi"
}

Since it does not exist in the API response, it is not (automatically) included in the generated markdown files.

To solve this, I first go over all Entries to link all Entry IDs to their ContentType, after that, I provide that information to the function that writes the reference so it can include the lower case content type and create references like programming/3op5VIqGZiwoe06c8IQIMO.md

@adriaandejonge would be great if you can review and merge this, see pull request #33