Skip to content

Commit 0c29e66

Browse files
committed
build: strip YAML fontmatter from breaking changes in changelog
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent f29381d commit 0c29e66

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/**
32
* @license Apache-2.0
43
*
@@ -33,10 +32,44 @@ var heading = require( './heading.js' );
3332
// VARIABLES //
3433

3534
var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit';
35+
var RE_YAML_DELIMITER = /^\s*---\s*$/;
3636

3737

3838
// FUNCTIONS //
3939

40+
/**
41+
* Strips YAML frontmatter blocks from text.
42+
*
43+
* @private
44+
* @param {string} text - text to process
45+
* @returns {string} text without YAML blocks
46+
*/
47+
function stripYamlBlocks( text ) {
48+
var result;
49+
var inYaml;
50+
var lines;
51+
var i;
52+
53+
lines = text.split( '\n' );
54+
result = [];
55+
inYaml = false;
56+
57+
for ( i = 0; i < lines.length; i++ ) {
58+
// Check for YAML delimiter (---) with optional whitespace:
59+
if ( RE_YAML_DELIMITER.test( lines[i] ) ) {
60+
inYaml = !inYaml; // Toggle YAML block state
61+
continue;
62+
}
63+
64+
// Only include lines that are not part of YAML blocks:
65+
if ( !inYaml ) {
66+
result.push( lines[i] );
67+
}
68+
}
69+
70+
return trim( result.join( '\n' ) );
71+
}
72+
4073
/**
4174
* Formats a breaking change.
4275
*
@@ -54,9 +87,13 @@ var STDLIB_GITHUB_URL = 'https://github.com/stdlib-js/stdlib/commit';
5487
* // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep'
5588
*/
5689
function formatBreakingChange( note ) {
57-
var parts = note.text.split( '\n' );
58-
var hash = trim( note.hash );
59-
var out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
90+
var parts;
91+
var hash;
92+
var out;
93+
94+
parts = stripYamlBlocks( note.text ).split( '\n' );
95+
hash = trim( note.hash );
96+
out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
6097
if ( parts.length > 1 ) {
6198
out +='\n\n';
6299
out += ' - ';

0 commit comments

Comments
 (0)