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

Cover image remains after being deleted #15233

Open
alvaromontoro opened this issue Oct 31, 2021 · 4 comments
Open

Cover image remains after being deleted #15233

alvaromontoro opened this issue Oct 31, 2021 · 4 comments
Assignees
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution external contributors welcome contribution is welcome!

Comments

@alvaromontoro
Copy link

Describe the bug

If a blog post has a cover image, but then the Jekyll Front Matter information for the cover image is removed, the image remains for that blog post. Example of a post with this behavior (it shows a cover image, but the Jekyll Front Matter tag for cover image was deleted)

To Reproduce

These are the steps using the classic Markdown editor, not the WYSIWYG editor (I haven't tried on that one).

  1. Go to https://dev.to
  2. Click on the "Create Post" button
  3. Fill in the Jekyll Front Matter (JFM) information for the post (title, published: true, some description, some tag)
  4. Click on the "Upload image" button and upload an image
  5. Add the uploaded image as a cover_image in JFM
  6. Save the post (it will be published because JFM published is true)
  7. You'll be taken to the published article, now click on the "Edit" button
  8. Remove the cover_image line from JFM
  9. Save the post (it will be automatically republished because published: true)
  10. The post still has the cover image

Expected behavior

If the Jekyll Front Matter value for cover_image is removed, the cover image should not be displayed.

Screenshots/Code

Original JFM code when creating a blank post:

---
title: 
published: false
description: 
tags: 
//cover_image: https://direct_url_to_image.jpg
---

After filling in all the information and uploading an image:

---
title: This is a test
published: true
description: This is a test
tags: test
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7mrugnfkt09dzh0i6hy.png
---

We published, so now we edit and remove the cover_image for the last step:

---
title: This is a test
published: true
description: This is a test
tags: test
---

After that last change, the image will still remain in the post.

Desktop (please complete the following information):

  • OS, version: Mac 11.6
  • Browser, version: Chrome 95
@github-actions
Copy link
Contributor

Thanks for the issue, we will take it into consideration! Our team of engineers is busy working on many types of features, please give us time to get back to you.

Feature requests that require more discussion may be closed. Read more about our feature request process on forem.dev.

To our amazing contributors: issues labeled type: bug are always up for grabs, but for feature requests, please wait until we add a ready for dev before starting to work on it.

To claim an issue to work on, please leave a comment. If you've claimed the issue and need help, please ping @forem/oss. The OSS Community Manager or the engineers on OSS rotation will follow up.

For full info on how to contribute, please check out our contributors guide.

@citizen428 citizen428 added area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution external contributors welcome contribution is welcome! labels Nov 1, 2021
@djuber
Copy link
Contributor

djuber commented Nov 1, 2021

I can confirm this is happening as you described.

It looks like leaving the cover_image: property blank in the front matter (removing the linked image) updates the post to have no cover image, and removing the cover_image property completely (as you described) leaves the existing cover image intact.

It looks like this might be an issue with a special case around absent cover_image values in the front matter - https://github.com/forem/forem/blob/main/app/models/article.rb#L613-L624 - if the article main image was set previously (by the same method), we only set/update the cover image when it's a present key for update.

As a work-around, setting the front matter to include cover_image: with nothing will update the post.

There was an earlier context around this behavior in #5687

However, I had some trouble getting the logic correct here because we can't just rely on the presence of cover_image in the front_matter; we need to be able to distinguish the scenario of when the user is trying to clear out a previous image (the main_image on the article), and when they just haven't set a cover_image at all. Because we allow users to add cover_image to the markdown as well as remove it, it's hard to know exactly which action they're trying to take.

It seems like the complication here is that articles could have had the main image/cover image set via the api, without adding a cover image to the front matter, and editing the body markdown (including the frontmatter, which never had a cover_image property present) would otherwise clear the image.

One fix for this could be to save some flag indicating whether the cover image was set via frontmatter or not, and clearing the image if it had been in the frontmatter but that key is now absent.

@vishaldeepak
Copy link
Contributor

would like to help out here. Please assign it to me if possible

@citizen428
Copy link
Contributor

I assigned you this issue @vishaldeepak, thanks for volunteering!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: publishing experience issues related to an authors experience publishing. Tags, series, etc. bug always open for contribution external contributors welcome contribution is welcome!
Projects
None yet
Development

No branches or pull requests

4 participants