File tree Expand file tree Collapse file tree 1 file changed +26
-24
lines changed
Expand file tree Collapse file tree 1 file changed +26
-24
lines changed Original file line number Diff line number Diff line change 1- import { createContentLoader } from 'vitepress'
1+ import { createContentLoader , type ContentData } from 'vitepress'
22import { ExampleLangs } from '../src/catalog/data'
33
44interface Rule {
@@ -23,28 +23,30 @@ export default createContentLoader('catalog/**/*.md', {
2323 . filter ( ( { url } ) => {
2424 return url . endsWith ( '.html' ) && ! url . includes ( 'rule-template' )
2525 } )
26- . map ( ( { url, src } ) => {
27- const source = src !
28- const id = url . split ( '/' ) . pop ( ) ?. replace ( / \. m d $ / , '' ) || ''
29- const type = source . includes ( '```yml' ) || source . includes ( '```yaml' )
30- ? 'YAML' : 'Pattern'
31- const playgroundLink = / \[ P l a y g r o u n d L i n k \] \( ( .+ ) \) / . exec ( source ) ?. [ 1 ] || ''
32- const hasFix = source . includes ( '<Badge' ) && source . includes ( 'Has Fix' )
33- const language = url . split ( '/' ) [ 2 ] as ExampleLangs
34- const name = source . match ( / # # \s * ( [ ^ < \n ] + ) / ) ?. [ 1 ] || ''
35-
36- return {
37- id,
38- name,
39- type,
40- link : url ,
41- playgroundLink,
42- language,
43- hasFix,
44- rules : [ ] ,
45- features : [ ] ,
46- }
47- } )
26+ . map ( extractRuleInfo )
4827 . sort ( ( a , b ) => a . id . localeCompare ( b . id ) )
4928 } ,
50- } )
29+ } )
30+
31+ function extractRuleInfo ( { url, src } : ContentData ) : Rule {
32+ const source = src !
33+ const id = url . split ( '/' ) . pop ( ) ?. replace ( / \. m d $ / , '' ) || ''
34+ const type = source . includes ( '```yml' ) || source . includes ( '```yaml' )
35+ ? 'YAML' : 'Pattern'
36+ const playgroundLink = / \[ P l a y g r o u n d L i n k \] \( ( .+ ) \) / . exec ( source ) ?. [ 1 ] || ''
37+ const hasFix = source . includes ( '<Badge' ) && source . includes ( 'Has Fix' )
38+ const language = url . split ( '/' ) [ 2 ] as ExampleLangs
39+ const name = source . match ( / # # \s * ( [ ^ < \n ] + ) / ) ?. [ 1 ] || ''
40+
41+ return {
42+ id,
43+ name,
44+ type,
45+ link : url ,
46+ playgroundLink,
47+ language,
48+ hasFix,
49+ rules : [ ] ,
50+ features : [ ] ,
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments