contentful / jekyll-contentful-data-import

Contentful Plugin for the Jekyll Static Site Generator
MIT License
101 stars 32 forks source link

Rich Text: Node Target Is Not An Asset #77

Open stevebenjamins opened 5 years ago

stevebenjamins commented 5 years ago

Hi,

I'm on Jekyll 3.8.6 (and 1.8.1 of jekyll-contentful-data-import) and I'm having trouble with rich_text fields. The rich_text fields work fine if there is no images in them. But if I add an image to the rich_text I start getting this error:

Liquid Exception: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"3AUkX9yyLz689tJQeshs0u", "created_at"=>2019-10-22 20:49:39 +0000, "updated_at"=>2019-10-22 20:49:39 +0000}, "title"=>"This is the Squarespace editor.", "description"=>nil, "url"=>"//images.ctfassets.net/fm8sawzb3em9/3AUkX9yyLz689tJQeshs0u/1c441b2d98d65b3b7797c165f2f44a6e/website-editor.jpeg"}}, "content"=>[], "nodeType"=>"embedded-asset-block"} in index.html

jekyll 3.8.6 | Error: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"3AUkX9yyLz689tJQeshs0u", "created_at"=>2019-10-22 20:49:39 +0000, "updated_at"=>2019-10-22 20:49:39 +0000}, "title"=>"This is the Squarespace editor.", "description"=>nil, "url"=>"//images.ctfassets.net/fm8sawzb3em9/3AUkX9yyLz689tJQeshs0u/1c441b2d98d65b3b7797c165f2f44a6e/website-editor.jpeg"}}, "content"=>[], "nodeType"=>"embedded-asset-block"}

Am I doing something wrong? I have the rich_text_renderer gem installed too. 🤔

norahine commented 4 years ago

Hi, I ran into the same problem.

Liquid Exception: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"27ULLhtn6c2FUdHSOH1nLP", "created_at"=>2020-01-12 19:44:36 +0000, "updated_at"=>2020-01-12 19:44:36 +0000}, "title"=>"cold-email-example", "description"=>nil, "url"=>"//images.ctfassets.net/plii0v5gbc4s/27ULLhtn6c2FUdHSOH1nLP/e2828b61dc4ed6abc1298866ca53817a/cold-email-example.png"}}, "content"=>[], "nodeType"=>"embedded-asset-block"} in ./cold-email-templates-b2b.html

jekyll 3.3.1 | Error: Node target is not an asset - Node: {"data"=>{"target"=>{"sys"=>{"id"=>"27ULLhtn6c2FUdHSOH1nLP", "created_at"=>2020-01-12 19:44:36 +0000, "updated_at"=>2020-01-12 19:44:36 +0000}, "title"=>"cold-email-example", "description"=>nil, "url"=>"//images.ctfassets.net/plii0v5gbc4s/27ULLhtn6c2FUdHSOH1nLP/e2828b61dc4ed6abc1298866ca53817a/cold-email-example.png"}}, "content"=>[], "nodeType"=>"embedded-asset-block"}

Any fix?

sstrudeau commented 4 years ago

I am running into this same problem on Rails (5.2) with the rich_text_renderer gem. It occurred after I added an Asset to a Rich Text field and attempted to render. It looks like maybe that gem is not able to handle this?

airtwo commented 3 years ago

Having this same exact issue. Rich text is rendered fine, until I add a link or asset to a rich text field. Using Jekyll 3.9.0, ruby 2.7.0. Node target is not an asset - Node: {"nodeType"=>"embedded-asset-block", "content"=>[], "data"=>{"target"=>{"sys"

pbt-shirokuma commented 3 years ago

I got the same error with rich_text_renderer. For rich_text_renderer, replacing the content['data']['target'] with Asset worked fine.

def replace_asset(content)
  if content['nodeType'] == 'embedded-asset-block'
    asset = cda_client.asset(content.dig('data', 'target', 'sys', 'id'))
    content['data']['target'] = asset
  end

  content['content'].each { |cnt| replace_asset(cnt) } if content.key('content') && content['content'].present?
end