@@ -5,7 +5,7 @@ import { withLeadingSlash } from 'ufo'
55import StudioPreviewMode from '../../components/StudioPreviewMode.vue'
66import { loadDatabaseAdapter } from '../database.client'
77import { v2ToV3ParsedFile } from './compatibility'
8- import { getCollectionByPath , generateCollectionInsert , generateRecordDeletion , generateRecordSelectByColumn , generateRecordUpdate } from './collection'
8+ import { getCollectionByFilePath , generateCollectionInsert , generateRecordDeletion , generateRecordSelectByColumn , generateRecordUpdate , getCollectionByRoutePath } from './collection'
99import { createSingleton , deepAssign , deepDelete , defu , generateStemFromPath , mergeDraft , StudioConfigFiles , withoutRoot } from './utils'
1010import { callWithNuxt , refreshNuxtData } from '#app'
1111import { useAppConfig , useNuxtApp , useRuntimeConfig , useRoute , useRouter , ref } from '#imports'
@@ -43,15 +43,15 @@ const initializePreview = async (data: DraftSyncData) => {
4343
4444const syncDraftFile = async ( collections : Record < string , CollectionInfo > , file : DraftSyncFile ) => {
4545 // Fetch corresponding collection
46- const collection = getCollectionByPath ( file . path , collections )
46+ const { collection, matchedSource } = getCollectionByFilePath ( file . path , collections )
4747 if ( ! collection ) {
4848 console . warn ( `Studio Preview: collection not found for file: ${ file . path } , skipping insertion.` )
4949 return
5050 }
5151
5252 const db = loadDatabaseAdapter ( collection . name )
5353
54- const v3File = v2ToV3ParsedFile ( file , collection )
54+ const v3File = v2ToV3ParsedFile ( file , collection , matchedSource )
5555
5656 const query = generateCollectionInsert ( collection , v3File )
5757
@@ -167,7 +167,7 @@ export function initIframeCommunication() {
167167 return
168168 }
169169
170- const collection = getCollectionByPath ( withoutRoot ( path ) , collections )
170+ const { collection } = getCollectionByFilePath ( withoutRoot ( path ) , collections )
171171 if ( ! collection ) {
172172 console . warn ( `Studio Preview: collection not found for file: ${ path } , skipping navigation.` )
173173 return
@@ -205,15 +205,15 @@ export function initIframeCommunication() {
205205 }
206206
207207 async function handleFileUpdate ( file : PreviewFile , navigate : boolean ) {
208- const collection = getCollectionByPath ( file . path , collections )
208+ const { collection, matchedSource } = getCollectionByFilePath ( file . path , collections )
209209 if ( ! collection ) {
210210 console . warn ( `Studio Preview: collection not found for file: ${ file . path } , skipping update.` )
211211 return
212212 }
213213
214214 const stem = generateStemFromPath ( file . path )
215215
216- const v3File = v2ToV3ParsedFile ( { path : file . path , parsed : file . parsed } , collection )
216+ const v3File = v2ToV3ParsedFile ( { path : file . path , parsed : file . parsed } , collection , matchedSource )
217217
218218 const query = generateRecordUpdate ( collection , stem , v3File )
219219
@@ -240,7 +240,7 @@ export function initIframeCommunication() {
240240 }
241241
242242 async function handleFileDeletion ( path : string ) {
243- const collection = getCollectionByPath ( withoutRoot ( path ) , collections )
243+ const { collection } = getCollectionByFilePath ( withoutRoot ( path ) , collections )
244244 if ( ! collection ) {
245245 console . warn ( `Studio Preview: collection not found for file: ${ path } , skipping deletion.` )
246246 return
@@ -261,23 +261,23 @@ export function initIframeCommunication() {
261261 return
262262 }
263263
264- const currentPath = route . path
264+ const routePath = route . path
265265
266- const collection = getCollectionByPath ( currentPath , collections )
266+ const { collection } = getCollectionByRoutePath ( routePath , collections )
267267 if ( ! collection || collection . type !== 'page' ) {
268268 return
269269 }
270270
271271 const db = loadDatabaseAdapter ( collection . name )
272272
273- const query = generateRecordSelectByColumn ( collection , 'path' , currentPath )
273+ const query = generateRecordSelectByColumn ( collection , 'path' , routePath )
274274
275275 const file = await db . first ( query ) as { path : string }
276276 if ( ! file || ! file . path ) {
277277 return
278278 }
279279
280- window . openFileInStudio ( currentPath )
280+ window . openFileInStudio ( routePath )
281281 }
282282
283283 nuxtApp . hook ( 'page:finish' , ( ) => {
0 commit comments