Skip to content

Commit f5a68f8

Browse files
michaelphamcfclaude
andcommitted
feat: expand search badges to classify plain, legacy, and shared results
Extends the search-tags plugin beyond legacy-only badges. Search results now show color-coded badges based on URL pattern classification: - green "plain" for plain client methods (recommended API) - gray "legacy" for chainable wrapper interfaces and create-*-api modules - blue "shared" for data type definitions (Props, Sys, etc.) Wrapper interfaces under entities/ are detected by converting the directory name to PascalCase and matching the filename. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent fc86fd1 commit f5a68f8

3 files changed

Lines changed: 83 additions & 13 deletions

File tree

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
.search-tag-legacy {
1+
.search-tag-legacy,
2+
.search-tag-plain,
3+
.search-tag-shared {
24
display: inline-block;
35
margin-left: 0.5em;
46
padding: 0.05em 0.4em;
@@ -7,21 +9,58 @@
79
line-height: 1.4;
810
border-radius: 3px;
911
vertical-align: middle;
12+
opacity: 0.8;
13+
pointer-events: none;
14+
}
15+
16+
.search-tag-legacy {
1017
color: var(--color-text-aside, #6e7781);
1118
background: var(--color-background-secondary, rgba(0, 0, 0, 0.06));
1219
border: 1px solid var(--color-accent, rgba(0, 0, 0, 0.08));
13-
opacity: 0.8;
14-
pointer-events: none;
20+
}
21+
22+
.search-tag-plain {
23+
color: #1a7f37;
24+
background: rgba(26, 127, 55, 0.08);
25+
border: 1px solid rgba(26, 127, 55, 0.2);
26+
}
27+
28+
.search-tag-shared {
29+
color: #0969da;
30+
background: rgba(9, 105, 218, 0.08);
31+
border: 1px solid rgba(9, 105, 218, 0.2);
1532
}
1633

1734
[data-theme='dark'] .search-tag-legacy {
1835
background: rgba(255, 255, 255, 0.08);
1936
border-color: rgba(255, 255, 255, 0.1);
2037
}
2138

39+
[data-theme='dark'] .search-tag-plain {
40+
color: #3fb950;
41+
background: rgba(63, 185, 80, 0.12);
42+
border-color: rgba(63, 185, 80, 0.25);
43+
}
44+
45+
[data-theme='dark'] .search-tag-shared {
46+
color: #58a6ff;
47+
background: rgba(88, 166, 255, 0.12);
48+
border-color: rgba(88, 166, 255, 0.25);
49+
}
50+
2251
@media (prefers-color-scheme: dark) {
2352
.search-tag-legacy:not([data-theme='light'] *) {
2453
background: rgba(255, 255, 255, 0.08);
2554
border-color: rgba(255, 255, 255, 0.1);
2655
}
56+
.search-tag-plain:not([data-theme='light'] *) {
57+
color: #3fb950;
58+
background: rgba(63, 185, 80, 0.12);
59+
border-color: rgba(63, 185, 80, 0.25);
60+
}
61+
.search-tag-shared:not([data-theme='light'] *) {
62+
color: #58a6ff;
63+
background: rgba(88, 166, 255, 0.12);
64+
border-color: rgba(88, 166, 255, 0.25);
65+
}
2766
}

docs/plugins/search-tags/search-tags.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,48 @@
11
/**
2-
* Search result tagger — adds visual badges to legacy client results so users
3-
* can distinguish plain client methods from legacy chainable methods at a glance.
2+
* Search result tagger — adds visual badges so users can distinguish plain
3+
* client, legacy client, and shared type results at a glance.
44
*
5-
* Detection uses the href on each result's <a> element:
6-
* - entities/<type>/<Wrapper>.html#<method> → legacy wrapper method (inherited)
7-
* - create-*-api → legacy module page
5+
* Classification uses the href on each result's <a> element:
6+
* - create-*-api → legacy
7+
* - *PlainClientAPI* → plain
8+
* - entities/{dir}/{WrapperInterface}.html → legacy
9+
* - entities/... (everything else) → shared
10+
* - plain/... → plain
11+
* - top-level {entity}.html → plain
812
*
913
* Injected inline by typedoc-search-tags.mjs via the head.end hook.
1014
*/
1115

1216
;(function () {
1317
'use strict'
1418

15-
var LEGACY_URL_PATTERN = /^(?:entities\/|create-)/
19+
var SKIP_TOP_LEVEL = /^(index|modules|common-types|getting-started|shared-types|hierarchy)(\.|$)/
20+
21+
function toPascalCase(kebab) {
22+
return kebab.replace(/(^|-)([a-z])/g, function (_, _sep, ch) {
23+
return ch.toUpperCase()
24+
})
25+
}
26+
27+
function classify(rel) {
28+
if (/^create-/.test(rel)) return 'legacy'
29+
if (rel.indexOf('PlainClientAPI') !== -1) return 'plain'
30+
31+
if (/^entities\//.test(rel)) {
32+
var parts = rel.replace(/#.*$/, '').split('/')
33+
if (parts.length >= 3) {
34+
var dir = parts[1]
35+
var file = parts[2].replace(/\.html$/, '')
36+
if (file === toPascalCase(dir)) return 'legacy'
37+
}
38+
return 'shared'
39+
}
40+
41+
if (/^plain\//.test(rel)) return 'plain'
42+
if (/^[a-z][a-z0-9-]*\.html/.test(rel) && !SKIP_TOP_LEVEL.test(rel)) return 'plain'
43+
44+
return null
45+
}
1646

1747
function tagResults(list) {
1848
var items = list.querySelectorAll('li')
@@ -24,18 +54,18 @@
2454
var anchor = li.querySelector('a')
2555
if (!anchor) continue
2656

27-
// Extract the relative path portion of the href
2857
var href = anchor.getAttribute('href') || ''
2958
var base = document.documentElement.dataset.base || './'
3059
var rel = href
3160
if (href.indexOf(base) === 0) {
3261
rel = href.slice(base.length)
3362
}
3463

35-
if (LEGACY_URL_PATTERN.test(rel)) {
64+
var tag = classify(rel)
65+
if (tag) {
3666
var badge = document.createElement('span')
37-
badge.className = 'search-tag-legacy'
38-
badge.textContent = 'legacy'
67+
badge.className = 'search-tag-' + tag
68+
badge.textContent = tag
3969
anchor.appendChild(badge)
4070
}
4171
}

typedoc.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default {
110110
'typedoc-plugin-missing-exports',
111111
'typedoc-github-theme',
112112
'./docs/plugins/version-selector/typedoc-version-selector.mjs',
113+
'./docs/plugins/search-tags/typedoc-search-tags.mjs',
113114
],
114115

115116
// Places internal types next to the module that owns them rather than

0 commit comments

Comments
 (0)