Skip to content

Commit 5880139

Browse files
authored
[jsdoc] Add per-release GitHub release-notes link to sidebar (#1551)
Add a "Release notes" link to the sidebar of each generated jsdoc release so developers browsing a version's API reference can jump straight to that release's notes for a quick overview of what changed. - tmpl/layout.tmpl: derive the release-notes URL from the package.json `repository.url` (strip the `git+` prefix and `.git` suffix) and render a `brand-release-notes` link under the version badge, pointing at `<repo>/releases/tag/<version>`. Gated on the URL being resolvable, so the link is omitted when no repository is configured. Because the version is the release being documented, the link is always correct without extra logic, and reading the slug from package.json keeps forks/renames working. - static/styles/jsdoc-default.css: add a `.brand-release-notes` style matching the sidebar accent color with an underline on hover. Fix: #1550
1 parent 8aeafae commit 5880139

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tools/jsdoc/static/styles/jsdoc-default.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ samp,
211211
color: var(--text-soft);
212212
}
213213

214+
.brand-release-notes {
215+
width: fit-content;
216+
color: var(--accent-strong);
217+
font-size: 0.82rem;
218+
font-weight: 700;
219+
}
220+
221+
.brand-release-notes:hover {
222+
text-decoration: underline;
223+
}
224+
214225
.nav-toggle {
215226
display: none;
216227
border: 0;

tools/jsdoc/tmpl/layout.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
var packageName = packageInfo.name || 'rclnodejs';
2020
var packageVersion = packageInfo.version || '';
2121
var packageDescription = packageInfo.description || 'ROS 2 client library for Node.js and TypeScript';
22+
var repository = packageInfo.repository;
23+
var repositoryUrl = '';
24+
if (repository) {
25+
var repositoryString = (typeof repository === 'string' ? repository : (repository.url || '')).trim();
26+
repositoryString = repositoryString
27+
.replace(/^git\+/, '')
28+
.replace(/#.*$/, '')
29+
.replace(/^ssh:\/\//, '')
30+
.replace(/^git:\/\//, 'https://')
31+
.replace(/^git@([^:/]+)[:/]/, 'https://$1/')
32+
.replace(/\.git$/, '')
33+
.replace(/\/$/, '');
34+
if (/^https?:\/\//.test(repositoryString)) {
35+
repositoryUrl = repositoryString;
36+
}
37+
}
38+
var releaseNotesUrl = (repositoryUrl && packageVersion) ? repositoryUrl + '/releases/tag/' + encodeURIComponent(packageVersion) : '';
2239
?>
2340
<body>
2441
<div class="site-backdrop"></div>
@@ -34,6 +51,9 @@
3451
<?js } ?>
3552
</a>
3653
<p class="brand-description"><?js= packageDescription ?></p>
54+
<?js if (releaseNotesUrl) { ?>
55+
<a class="brand-release-notes" href="<?js= releaseNotesUrl ?>" target="_blank" rel="noopener noreferrer">Release notes &#8599;</a>
56+
<?js } ?>
3757
</div>
3858

3959
<button class="nav-toggle" type="button" aria-expanded="false" aria-controls="site-nav">

0 commit comments

Comments
 (0)