davestewart / nuxt-content-assets

Enable locally-located assets in Nuxt Content

Home Page:https://npmjs.com/package/nuxt-content-assets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update related documents when images change

davestewart opened this issue · comments

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:

  • for any found assets, the document id is inserted into the asset's metadata

When images are changed:

  • the image asset index is updated with the new metadata
  • related documents should be are re-parsed, updating image sizes in matching paths

When assets are deleted or moved:

  • the document list for each individual asset should be modified
  • related documents should be re-parsed, replacing old asset paths with the new asset paths

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.

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.