-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generate:releaseNotes): Add inline links to headings (#22415)
GitHub does not create heading IDs in the Releases UI, so our release note TOC links don't work. This change adds a remarkjs/unist plugin that inserts HTML anchors into the headings. Also updates the intro message on the release notes issue to include a command that can be used to generate the release notes locally. [AB#14174](https://dev.azure.com/fluidframework/235294da-091d-4c29-84fc-cdfc3d90890b/_workitems/edit/14174) --------- Co-authored-by: Alex Villarreal <716334+alexvy86@users.noreply.github.com>
- Loading branch information
1 parent
1cc829d
commit 1a4b95f
Showing
8 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
This issue is automatically updated with a preview of the release notes for the upcoming Fluid Framework release. | ||
|
||
**To generate release notes locally to commit to the `RELEASE_NOTES` folder in the repo,** run the following command: | ||
|
||
```shell | ||
pnpm flub generate releaseNotes -g client -t minor --outFile RELEASE_NOTES/{{ version }}.md | ||
``` | ||
|
||
**To generate the release notes to paste into the GitHub Release,** run the following command: | ||
|
||
```shell | ||
pnpm flub generate releaseNotes -g client -t minor --headingLinks --excludeH1 --outFile temporary-file.md | ||
``` | ||
|
||
You can then copy and paste the contents of the `temporary-file.md` into the GitHub Release. | ||
|
||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import GithubSlugger from "github-slugger"; | ||
import type { Heading, Html } from "mdast"; | ||
import type { Node } from "unist"; | ||
import { visit } from "unist-util-visit"; | ||
|
||
/** | ||
* Using the same instance for all slug generation ensures that no duplicate IDs are generated. | ||
*/ | ||
const slugger = new GithubSlugger(); | ||
|
||
/** | ||
* A remarkjs/unist plugin that inserts HTML anchor nodes before heading text. This is a workaround for GitHub's lack of | ||
* automatic heading links in GitHub Releases. GitHub's markdown rendering is inconsistent, and in this case it does not | ||
* add automatic links. | ||
* | ||
* For more details, see: https://github.com/orgs/community/discussions/48311#discussioncomment-10436184 | ||
*/ | ||
export function remarkHeadingLinks(): (tree: Node) => void { | ||
return (tree: Node): void => { | ||
visit(tree, "heading", (node: Heading) => { | ||
if (node.children?.length > 0) { | ||
const firstChild = node.children[0]; | ||
if (firstChild.type === "text") { | ||
const headingValue = firstChild.value; | ||
const slug = slugger.slug(headingValue); | ||
// We need to insert an Html node instead of a string, because raw | ||
// strings will get markdown-escaped when rendered | ||
const htmlNode: Html = { | ||
type: "html", | ||
value: `<a id="${slug}"></a>`, | ||
}; | ||
// Insert the HTML node before the text node of the heading | ||
node.children.unshift(htmlNode); | ||
} | ||
} | ||
}); | ||
}; | ||
} |
Oops, something went wrong.