1- import { comarkContent , defineContentPlugin , type ComarkContent , type CacheOptions } from 'comark-content'
1+ import { type ContentOptions , defineContentPlugin , type ComarkContent , type CacheOptions , comarkContent } from 'comark-content' ;
22import fs from 'comark-content/sources/fs'
33import github from 'comark-content/sources/github'
44import rangi from 'comark/plugins/rangi'
@@ -23,6 +23,7 @@ const comarkPlugins = [
2323 } ) ,
2424]
2525
26+ // Bound to THIS instance so a preview content instance serves its own version's sections, not production's.
2627const searchSectionsPlugin = defineContentPlugin ( ( ) => ( {
2728 name : 'search-sections' ,
2829 setup ( ctx ) {
@@ -38,7 +39,8 @@ export async function createSourceContent(
3839 ref : string ,
3940 opts : { remote ?: boolean ; cache ?: CacheOptions ; basePath ?: string ; watch ?: boolean } = { }
4041) {
41- const instance = comarkContent ( {
42+
43+ const options : any = {
4244 markdown : {
4345 plugins : comarkPlugins ,
4446 html : false ,
@@ -49,13 +51,18 @@ export async function createSourceContent(
4951 plugins : [ searchSectionsPlugin ] ,
5052 cache : opts . cache ,
5153 basePath : opts . basePath ,
52- } )
54+ }
55+
56+ // A no-op unless the consumer shadows it from their own `server/utils/`. Re-typed as the layer's own
57+ // options: a consumer's hook is declared against the wide `ContentOptions`, and letting that widen the
58+ // argument would erase the source and plugin types `comarkContent` infers from the literal.
59+ const instance = comarkContent ( extendContent ( options ) as ContentOptions )
5360
5461 // Only the default instance watches: others read a fixed ref that can't change, and retaining
5562 // `watch()`'s stop function to release the watcher would leak once the preview entry is evicted.
5663 if ( import . meta. dev && opts . watch ) {
5764 await instance . watch ( )
58- instance . hooks . hook ( 'watch:file:update' , ( _source , key ) => {
65+ instance . hooks . hook ( 'watch:file:update' , ( _source : string , key : string ) => {
5966 invalidateSearchSections ( instance )
6067 console . log ( `${ key } updated` )
6168 } )
0 commit comments