Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 'image by URL' editor component #1293

Closed
tomsabin opened this issue Apr 20, 2018 · 2 comments · Fixed by #4700
Closed

Feature: 'image by URL' editor component #1293

tomsabin opened this issue Apr 20, 2018 · 2 comments · Fixed by #4700

Comments

@tomsabin
Copy link

- Do you want to request a feature or report a bug?

Feature

- What is the current behavior?

screen shot 2018-04-20 at 14 04 04

- What is the proposed behavior?

screen shot 2018-04-20 at 14 05 46

  • an alternative to uploading an image to Netlify CMS, by referencing an external image instead.

This is partially possible by registering another editor component (see below), but this new editor component gets in conflict with the existing image editor component (as it's using the same pattern match). However, this component calls the toBlock function correctly when first added into the rich editor block, but after changing context, the text is matched to the existing image component.

CMS.registerEditorComponent({
  id: 'image_by_url',
  label: 'Image by URL',
  fields: [
    {name: 'url', label: 'Image URL', widget: 'string'},
    {name: 'alt', label: 'Alternative text', widget: 'string'}
  ],
  pattern: /^!\[(.*)\]\((.*)\)$/,
  fromBlock: function(match) {
    // Netlify CMS doesn't seem to execute this function
    return {
      image: match[2],
      alt: match[1]
    };
  },
  toBlock: function(obj) {
    var url = obj.url || '';
    var alt = obj.alt || '';
    return '![' + alt + '](' + url + ')';
  },
  toPreview: function(obj) {
    // Netlify CMS doesn't seem to execute this function
    var url = obj.url || '';
    var alt = obj.alt || '';
    return '<img src="' + obj.url + '" alt="' + obj.alt + '" />';
  }
});
@erquhart
Copy link
Contributor

I think we'd take a PR to update the current image widget with this.

@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants