Skip to content

Commit 087ef73

Browse files
committed
Filter out comments from h1s
1 parent 5b4c557 commit 087ef73

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

make_release/release-note/notes.nu

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ const toc = '[[toc](#table-of-contents)]'
4848

4949
# Generate and write the table of contents to a release notes file
5050
export def write-toc [file: path] {
51+
let known_h1s = [
52+
"# Highlights and themes of this release",
53+
"# Changes",
54+
"# Notes for plugin developers",
55+
"# Hall of fame",
56+
"# Full changelog",
57+
]
58+
5159
let lines = open $file | lines | each { str trim -r }
5260

5361
let content_start = 2 + (
@@ -65,11 +73,32 @@ export def write-toc [file: path] {
6573
| insert level {
6674
get line | split chars | take while { $in == '#' } | length
6775
}
76+
| insert nocomment {
77+
if ($in.level == 1) {
78+
let line = $in.line
79+
80+
# Try to use the whitelist first
81+
if ($known_h1s | any {|| $line =~ $in}) {
82+
return true
83+
}
84+
let user = ([Ignore Accept] |
85+
input list $"Is this a code comment or a markdown h1 heading:(char nl)(ansi blue)($line)(ansi reset)(char nl)Choose if we include it in the TOC!")
86+
match $user {
87+
"Accept" => {true}
88+
"Ignore" => {false}
89+
}
90+
91+
} else {
92+
return true
93+
}
94+
}
6895
)
6996

97+
print $data
98+
7099
let table_of_contents = (
71100
$data
72-
| where level in 1..=3
101+
| where level in 1..=3 and nocomment == true
73102
| each {|header|
74103
let indent = '- ' | fill -w ($header.level * 2) -a right
75104

@@ -91,7 +120,7 @@ export def write-toc [file: path] {
91120
)
92121

93122
let content = $data | each {
94-
if $in.level in 1..=3 and not ($in.line ends-with $toc) {
123+
if $in.level in 1..=3 and not ($in.line ends-with $toc) and $in.nocomment {
95124
$'($in.line) ($toc)'
96125
} else {
97126
$in.line

0 commit comments

Comments
 (0)