Skip to content

Commit

Permalink
feat: only ignore modified sources in preview (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz authored Mar 1, 2023
1 parent a56c01c commit d94a3cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/runtime/components/ContentPreviewMode.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<script setup lang="ts">
import type { Socket } from 'socket.io-client'
import { onMounted, ref, onUnmounted, nextTick, Transition } from 'vue'
import { refreshNuxtData, useCookie, useRoute, navigateTo, useNuxtApp } from '#app'
import type { PreviewResponse } from '../../../types'
// @ts-ignore
import { refreshNuxtData, useCookie, useRoute, navigateTo, useNuxtApp } from '#imports'
const props = defineProps({
previewToken: {
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/composables/useStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export const useStudio = () => {
await Promise.all(keys.map(key => contentStorage.removeItem(key)))

// Set preview meta
await contentStorage.setItem(`${previewToken.value}$`, JSON.stringify({ ignoreBuiltContents }))
const sources = new Set<string>(files.map(file => file.parsed!._id.split(':').shift()!))
await contentStorage.setItem(`${previewToken.value}$`, JSON.stringify({ ignoreSources: Array.from(sources) }))

// Handle content files
await Promise.all(
files.map(item => contentStorage.setItem(`${previewToken.value}:${item.parsed?._id}`, JSON.stringify(item.parsed)))
files.map(item => contentStorage.setItem(`${previewToken.value}:${item.parsed!._id}`, JSON.stringify(item.parsed)))
)
}

Expand Down Expand Up @@ -144,7 +145,10 @@ export const useStudio = () => {
path = path.replace(/\/$/, '')
let content = await storage.value?.getItem(`${previewToken.value}:${path}`)
if (!content) {
content = await storage.value?.getItem(path)
content = await storage.value?.getItem(`cached:${path}`)
}
if (!content) {
content = content = await storage.value?.getItem(path)
}
return content as ParsedContent
}
Expand Down

0 comments on commit d94a3cb

Please sign in to comment.