Skip to content

Commit 1bcbd53

Browse files
refactor: move extractRuleInfo out
1 parent 813c1f5 commit 1bcbd53

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

website/_data/catalog.data.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContentLoader } from 'vitepress'
1+
import { createContentLoader, type ContentData } from 'vitepress'
22
import { ExampleLangs } from '../src/catalog/data'
33

44
interface 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(/\.md$/, '') || ''
29-
const type = source.includes('```yml') || source.includes('```yaml')
30-
? 'YAML' : 'Pattern'
31-
const playgroundLink = /\[Playground Link\]\((.+)\)/.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(/\.md$/, '') || ''
34+
const type = source.includes('```yml') || source.includes('```yaml')
35+
? 'YAML' : 'Pattern'
36+
const playgroundLink = /\[Playground Link\]\((.+)\)/.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+
}

0 commit comments

Comments
 (0)