Jekyll-contentful-data-import

Hi,

I am using the jekyll contentful data import plugin to collect data from Contentful. Everything seems to be working as expected, but the content types are displayed using their IDs rather than labels in the yaml file. Is there a way to force the exported data to use the labels rather than the IDs?

The yaml file has:

fS8J0UehVuo8YuO2AswYS:
- sys:

And I would expect it to have:

county:
- sys:

I am using jekyll 3.5.2 and jekyll-contentful-data-import 1.6.0, with ruby 2.4.2 on macOs High Sierra.

Any suggestions?

Thank you,
Miguel

Hey @jmvieira,

I’m David, the creator of the Jekyll plugin, would you mind sharing the contentful block in your _config.yaml file? Please remove all credentials.

Cheers

Hi @david.litvak,

Here is my current contentful config:
contentful:
spaces:
- ara:
space: ENV_CONTENTFUL_SPACE_ID
access_token: ENV_CONTENTFUL_ACCESS_TOKEN

Thank you

Hey @jmvieira,

Sadly there’s currently no way of doing that, as the tool was created after we changed the content type IDs to default to human readable IDs, and it doesn’t handle ID mapping.

That said, I’ll add it to the backlog of continuous improvements for the tool.

There are a few things you can do to workaround the issue.

  1. Rake task to re-map the IDs:
require 'yaml'

desc "Re-map labels"
task :remap_labels do
  labels = {
    'original_id' => 'mapped_id',
    'other_weird_id' => 'other_mapped_id'
  }

  yaml_path = File.join(Dir.pwd, '... path to your yaml file ...')
  yaml = YAML::load_file(yaml_path)

  new_yaml = {}
  yaml.each do |key, value|
    key = labels[key] if labels.key?(key)
    new_yaml[key] = value
  end

  File.open(yaml_path, 'w') do |f|
    f.write(YAML.dump(new_yaml))
  end
end

Then after you run jekyll contentful, you can run rake remap_labels in order to remap your labels to match your desired pattern.

  1. Re-create the content type through the WebApp:

The new content type will have a human readable ID.

Hope this helps,

Cheers

Thank you for your help.

I went with option 1 because I don’t have control over the WebApp.

Glad that worked for you.

Cheers