@@ -5,35 +5,39 @@ import { processMarkdown } from '@velin-dev/core'
55import path from 'path-browserify-esm'
66import { createUnplugin } from 'unplugin'
77
8- export const unpluginFactory : UnpluginFactory < Options | undefined > = ( options ) => {
9- const { extension = 'velin.md' } = options || { }
10- const filter = new RegExp ( `\\.${ extension } $` )
11-
8+ export const unpluginFactory : UnpluginFactory < Options | undefined > = ( ) => {
129 return {
13- name : 'unplugin-custom-format ' ,
14- // Transform hook to process .custom files
15- async transform ( code , id ) {
16- if ( ! filter . test ( id ) )
17- return null // Early return for non-matching files
18-
19- try {
20- const pathname = path . dirname ( id )
21- // eslint-disable-next-line no-console
22- console . log ( `Processing file: ${ id } , ${ pathname } ` ) // Log file path
23- const parsed = await processMarkdown ( code , { } , pathname ) // Parse content
10+ name : 'unplugin-velin ' ,
11+ transform : {
12+ filter : {
13+ id : {
14+ include : [ / \. v e l i n \. m d $ / , '**/*.velin.md' ] ,
15+ } ,
16+ } ,
17+ handler : async ( code , id ) => {
18+ try {
19+ const pathname = path . dirname ( id )
20+ const parsed = await processMarkdown ( code , { } , pathname )
2421
25- // Return transformed module as ES module
26- return {
27- code : `export default function (args) {
22+ return {
23+ code : `export default function (args) {
2824 return \`${ parsed } \`
2925 }` ,
30- map : null , // Add source map support if needed
26+ map : null ,
27+ }
28+ }
29+ catch ( error ) {
30+ console . error ( `Failed to parse ${ id } : ${ ( error as Error ) . message } ` )
31+ return null
32+ }
33+ } ,
34+ } ,
35+ vite : {
36+ config ( ) {
37+ return {
38+ assetsInclude : [ '**/*.velin.md' ] ,
3139 }
32- }
33- catch ( error ) {
34- this . error ( `Failed to parse ${ id } : ${ ( error as Error ) . message } ` )
35- return null
36- }
40+ } ,
3741 } ,
3842 }
3943}
0 commit comments