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

Feature: Watch assets

davestewart opened this issue · comments

Background

Right now, the user has to restart the server when there is any change in assets.

Having the server monitor for asset updates and reload the page would be great.

Proposal

So it looks like this is super-simple using unstorage!

  const storage = createStorage()
  storage.mount('<key>', fsDriver({
    base: 'path/to/folder',
        ignore: ['.md'], // add other doc types here
  }))
  storage.watch(async function (op, id) {
    console.log({ op, id })
  })

May even be able to replace the current globbing system and just use unstorage.

Could also potentially move the copy process to the build hook, and align file and github copy operations.

Notes

Prior art

Content does its watching here:

Also, look to see if markdown files would need to be refreshed at the same time – for example, an image might be added to match a path in an existing document, and that document would need its relative/* links updated to /public/*.

Optimisations

Content currently uses an index file: .nuxt/content-cache/index.json to keep track of all documents.

Should there be something similar for all absolute image paths, and which documents reference them?

Can we even rebuild individual markdown files on demand?