Skip to content

Commit 7c6c42c

Browse files
committed
feat: add mutil component name on a line
1 parent c94b0b9 commit 7c6c42c

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed

demo/utils/ChangeLogButton.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export default defineComponent({
1616
HistoryIcon
1717
},
1818
props: {
19-
text: Boolean,
2019
quaternary: Boolean,
2120
size: {
2221
type: String as PropType<ButtonProps['size']>,
@@ -30,8 +29,8 @@ export default defineComponent({
3029
discrete: 'createDiscreteApi'
3130
}
3231
const isCN = route.path.startsWith('/zh-CN')
33-
const name = route.fullPath.split('/').pop()
34-
const componentName = miscMap[name as string] || `n-${name}`
32+
const text = route.fullPath.match(/\/([^\/#?]+)(?:#.*)?$/)?.[1]
33+
const componentName = miscMap[text as string] || `n-${text}`
3534
const logs = isCN ? zhCN[componentName] : enUS[componentName]
3635
const drawerRef = ref(false)
3736
const renderer = new marked.Renderer()

demo/utils/EditOnGithubHeader.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export default defineComponent({
2525
setup() {
2626
const route = useRoute()
2727
const components = zhComponentRoutes.map((route: any) => route.path)
28-
const isComponent = components.includes(route.fullPath.split('/').pop())
28+
const text = route.fullPath.match(/\/([^\/#?]+)(?:#.*)?$/)?.[1]
29+
const isComponent = components.includes(text)
2930
return {
3031
...i18n({
3132
'zh-CN': {

scripts/gen-component-changelog.js

+65-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
const fs = require('node:fs')
22
const path = require('node:path')
33

4+
const extraKeys = ['createDiscreteApi']
5+
const componentMapping = {
6+
'n-collapse-item': 'n-collapse',
7+
'n-float-button-group': 'n-float-button',
8+
'n-checkbox-group': 'n-checkbox',
9+
'n-form-item': 'n-form',
10+
'n-form-item-gi': 'n-form-item',
11+
'n-input-group': 'n-input',
12+
'n-upload-trigger': 'n-upload',
13+
'n-descriptions-item': 'n-descriptions',
14+
'n-image-group': 'n-image',
15+
'n-list-item': 'n-list',
16+
'n-timeline-item': 'n-timeline',
17+
'n-anchor-link': 'n-anchor',
18+
'n-breadcrumb-item': 'n-breadcrumb',
19+
'n-tab-pane': 'n-tabs',
20+
'n-drawer-content': 'n-drawer',
21+
'n-layout-sider': 'n-layout',
22+
'n-layout-header': 'n-layout',
23+
'n-layout-footer': 'n-layout',
24+
'n-layout-content': 'n-layout',
25+
'n-grid-item': 'n-grid'
26+
}
27+
428
function parseChangelog(content) {
529
const logs = {}
630
let version = ''
@@ -32,35 +56,53 @@ function parseChangelog(content) {
3256
return
3357
}
3458

35-
const componentMatch = line.match(/^- .*?`(n-[^`]*)`/)
36-
const apiMatch = line.match(/^- .*?`([^`]*Api)`/)
59+
const componentMatches = Array.from(line.matchAll(/`(n-[^`]*)`/g)).map(
60+
match => match[1]
61+
)
3762

38-
const name = componentMatch
39-
? componentMatch[1]
40-
: apiMatch
41-
? apiMatch[1]
42-
: ''
63+
const extraMatches = extraKeys.filter(key => line.includes(`\`${key}\``))
4364

44-
const content = isBreaking ? `${line.trim()} 🚨` : `${line.trim()}`
65+
const names = new Set()
4566

46-
if (!logs[name]) {
47-
logs[name] = []
48-
}
67+
componentMatches.forEach((name) => {
68+
if (componentMapping[name]) {
69+
names.add(componentMapping[name])
70+
}
71+
else {
72+
names.add(name)
73+
}
74+
})
4975

50-
const existingLog = logs[name].find(
51-
log => log.version === version && log.date === date
52-
)
76+
extraMatches.forEach((name) => {
77+
names.add(name)
78+
})
5379

54-
if (existingLog) {
55-
existingLog.changes.push(content)
56-
}
57-
else {
58-
logs[name].push({
59-
version,
60-
date,
61-
changes: [content]
62-
})
80+
if (names.size === 0) {
81+
names.add('')
6382
}
83+
84+
const content = isBreaking ? `${line.trim()} 🚨` : `${line.trim()}`
85+
86+
names.forEach((name) => {
87+
if (!logs[name]) {
88+
logs[name] = []
89+
}
90+
91+
const existingLog = logs[name].find(
92+
log => log.version === version && log.date === date
93+
)
94+
95+
if (existingLog) {
96+
existingLog.changes.push(content)
97+
}
98+
else {
99+
logs[name].push({
100+
version,
101+
date,
102+
changes: [content]
103+
})
104+
}
105+
})
64106
})
65107

66108
return logs

src/discrete/demos/zhCN/index.demo-entry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 脱离上下文的 API CreateDiscreteAPI
1+
# 脱离上下文的 API DiscreteAPI
22

33
如果你想在 `setup` 外使用 `useDialog``useMessage``useNotification``useLoadingBar``useModal`,可以通过 `createDiscreteApi` 来构建对应的 API。
44

0 commit comments

Comments
 (0)