Skip to content

Commit 540e779

Browse files
Copilothotlong
andcommitted
refactor: extract description line checker into reusable function
Improves readability of migrate command's description extraction logic Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 6873c11 commit 540e779

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/cli/src/commands/migrate.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ function extractTitle(content, filename) {
4343
.replace(/\b\w/g, c => c.toUpperCase());
4444
}
4545

46+
/**
47+
* Check if a line is suitable as a description (plain text, not markup)
48+
* @param {string} line - The trimmed line to check
49+
* @returns {boolean} - True if the line is plain descriptive text
50+
*/
51+
function isDescriptionLine(line) {
52+
const nonDescriptionPrefixes = ['#', '!', '```', '-', '|', '<', '[!', '*', '>'];
53+
return line.length > 0 && !nonDescriptionPrefixes.some(prefix => line.startsWith(prefix));
54+
}
55+
4656
/**
4757
* Extract description from markdown content
4858
* Uses the first paragraph after the H1 heading
@@ -56,7 +66,7 @@ function extractDescription(content) {
5666
const lines = withoutH1.split('\n');
5767
for (const line of lines) {
5868
const trimmed = line.trim();
59-
if (trimmed && !trimmed.startsWith('#') && !trimmed.startsWith('!') && !trimmed.startsWith('```') && !trimmed.startsWith('-') && !trimmed.startsWith('|') && !trimmed.startsWith('<') && !trimmed.startsWith('[!')) {
69+
if (isDescriptionLine(trimmed)) {
6070
// Truncate long descriptions
6171
return trimmed.length > 160 ? trimmed.substring(0, 157) + '...' : trimmed;
6272
}

0 commit comments

Comments
 (0)