davestewart / nuxt-content-assets

Enable locally-located assets in Nuxt Content
https://npmjs.com/package/nuxt-content-assets
108 stars 7 forks source link

Update related documents when images change #30

Closed davestewart closed 1 year ago

davestewart commented 1 year ago

Background

With the current watch system, images reload in the browser when they are changed.

However, any owning document is not updated, so if the image size changes, the document will still display the image at the old size, until the document itself is resaved.

Proposal

The only way for content documents to be successfully updated, would be to store a reverse lookup of which images are in which documents:

{
  'path/to/asset': {
    ...
    documents: [
      'source:path:to:doc_1',
      'source:path:to:doc_2',
    ]
  }
}

When documents are parsed:

When images are changed:

When assets are deleted or moved:

The thing to remember about moves is that they are reported by chokidar as a delete then an update, so does this change how paths should be rewritten, or is this only a concern for the user?

Also, it's possible that document moves would need to trigger this as well (should check if moves trigger the parsing hook).

Also, note that this only needs to happen if image size hints are on.

Otherwise, the image size should update automatically.

Notes

Consider if this would create problems if the related documents are open but not saved.

The target documents would need to be reloaded. Check live-reload section of #18 to see how this might be done.

davestewart commented 1 year ago

It looks like the refresh functionality is not going to work right now, as Nuxt Content is already refreshing saved content, even though it is ignored.