💄 (fonts) add fonts

This commit is contained in:
Julien Calixte
2023-07-18 21:41:09 +02:00
parent 2a8e9c8b63
commit de0f592c46
4 changed files with 31 additions and 26 deletions

View File

@@ -12,33 +12,39 @@ export const useImages = (sha: string) => {
() => store.files.find((file) => file.sha === sha)?.path
)
watch(currentFilePath, (filePath) => {
if (!filePath) {
return
}
const images = document.querySelectorAll(`.note-${sha} img`)
images.forEach(async (image) => {
const src = image.getAttribute('src')
if (!src || src.startsWith(SRC_PREFIX)) {
watch(
currentFilePath,
(filePath) => {
if (!filePath) {
return
}
const imageFilePath = resolvePath(
filePath,
image.getAttribute('src') ?? ''
)
const images = document.querySelectorAll(`.note-${sha} img`)
const imageFile = store.files.find((file) => file.path === imageFilePath)
images.forEach(async (image) => {
const src = image.getAttribute('src')
if (!src || src.startsWith(SRC_PREFIX)) {
return
}
if (!imageFile?.sha) {
return
}
const { getCachedFileContent } = useFile(imageFile.sha, false)
const imageFilePath = resolvePath(
filePath,
image.getAttribute('src') ?? ''
)
const fileContent = await getCachedFileContent()
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
})
})
const imageFile = store.files.find(
(file) => file.path === imageFilePath
)
if (!imageFile?.sha) {
return
}
const { getCachedFileContent } = useFile(imageFile.sha, false)
const fileContent = await getCachedFileContent()
image.setAttribute('src', `${SRC_PREFIX} ${fileContent}`)
})
},
{ immediate: true }
)
}