Skip to content

Commit 79d460b

Browse files
authored
fix: more consistent sorting (#765)
1 parent 321fb1e commit 79d460b

14 files changed

+294
-284
lines changed

src/html/jsdoc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ impl ModuleDocCtx {
333333
render_ctx: &RenderContext,
334334
short_path: &ShortPath,
335335
render_symbols: bool,
336+
summary: bool,
336337
) -> Self {
337338
let module_doc_nodes = render_ctx.ctx.doc_nodes.get(short_path).unwrap();
338339

@@ -358,7 +359,7 @@ impl ModuleDocCtx {
358359
sections.push(examples);
359360
}
360361

361-
let html = jsdoc_body_to_html(render_ctx, &node.js_doc, false);
362+
let html = jsdoc_body_to_html(render_ctx, &node.js_doc, summary);
362363

363364
(deprecated, html)
364365
} else {

src/html/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl GenerateCtx {
311311
) -> Result<Self, anyhow::Error> {
312312
let mut main_entrypoint = None;
313313

314-
let doc_nodes = doc_nodes_by_url
314+
let mut doc_nodes = doc_nodes_by_url
315315
.into_iter()
316316
.map(|(specifier, nodes)| {
317317
let short_path = Rc::new(ShortPath::new(
@@ -420,6 +420,8 @@ impl GenerateCtx {
420420
})
421421
.collect::<IndexMap<_, _>>();
422422

423+
doc_nodes.sort_by_key(|a, _| !a.is_main);
424+
423425
let mut reference_index: std::collections::HashMap<
424426
crate::Location,
425427
Vec<(usize, DocNodeWithContext)>,

src/html/pages.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use super::util::AnchorCtx;
1212
use super::util::BreadcrumbsCtx;
1313
use super::util::SectionHeaderCtx;
1414
use std::borrow::Cow;
15-
use std::cmp::Ordering;
1615
use std::rc::Rc;
1716

1817
use super::DARKMODE_TOGGLE_FILENAME;
@@ -111,7 +110,7 @@ impl CategoriesPanelCtx {
111110
.filter(|(_name, node)| !node[0].is_internal(ctx.ctx))
112111
.count();
113112

114-
let mut categories = ctx
113+
let categories = ctx
115114
.ctx
116115
.doc_nodes
117116
.keys()
@@ -127,8 +126,6 @@ impl CategoriesPanelCtx {
127126
})
128127
.collect::<Vec<_>>();
129128

130-
categories.sort_by(|a, b| a.name.cmp(&b.name));
131-
132129
Some(CategoriesPanelCtx {
133130
categories,
134131
all_symbols_href: ctx.ctx.resolve_path(
@@ -241,6 +238,7 @@ impl IndexCtx {
241238
&render_ctx,
242239
short_path,
243240
!short_path.is_main,
241+
false,
244242
)
245243
});
246244

@@ -262,7 +260,7 @@ impl IndexCtx {
262260

263261
let overview = match ctx.file_mode {
264262
FileMode::Dts if short_path.is_none() => {
265-
let mut sections = ctx
263+
let sections = ctx
266264
.doc_nodes
267265
.iter()
268266
.map(|(short_path, nodes)| {
@@ -299,13 +297,6 @@ impl IndexCtx {
299297
})
300298
.collect::<Vec<_>>();
301299

302-
sections.sort_by(|a, b| match (&a.header, &b.header) {
303-
(Some(x), Some(y)) => x.title.cmp(&y.title),
304-
(None, Some(_)) => Ordering::Less,
305-
(Some(_), None) => Ordering::Greater,
306-
(None, None) => Ordering::Equal,
307-
});
308-
309300
Some(SymbolContentCtx {
310301
id: util::Id::empty(),
311302
sections,

src/html/render_context.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,16 @@ impl<'ctx> RenderContext<'ctx> {
188188
.resolve_path(self.current_resolve, UrlResolveKind::Root),
189189
};
190190
let mut current_entrypoint = None;
191-
let mut entrypoints =
192-
self.ctx.doc_nodes.keys().cloned().collect::<Vec<_>>();
193-
entrypoints.sort_unstable_by_key(|a| !a.is_main);
194191

195-
let mut entrypoints = entrypoints
196-
.into_iter()
192+
let mut entrypoints = self
193+
.ctx
194+
.doc_nodes
195+
.keys()
197196
.map(|short_path| BreadcrumbCtx {
198197
name: short_path.display_name().to_string(),
199198
href: self.ctx.resolve_path(
200199
self.current_resolve,
201-
UrlResolveKind::File { file: &short_path },
200+
UrlResolveKind::File { file: short_path },
202201
),
203202
})
204203
.collect::<Vec<_>>();

src/html/symbols/enum.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
use crate::r#enum::EnumMemberDef;
12
use crate::html::DocNodeWithContext;
23
use crate::html::render_context::RenderContext;
34
use crate::html::types::render_type_def;
45
use crate::html::util::*;
6+
use crate::js_doc::JsDocTag;
57

68
pub(crate) fn render_enum(
79
render_ctx: &RenderContext,
810
doc_node: &DocNodeWithContext,
911
) -> Vec<SectionCtx> {
1012
let mut members = doc_node.enum_def().unwrap().members.clone();
1113

12-
members.sort_by(|a, b| a.name.cmp(&b.name));
14+
members.sort_by(|a, b| {
15+
let is_deprecated = |m: &EnumMemberDef| {
16+
m.js_doc
17+
.tags
18+
.iter()
19+
.any(|t| matches!(t, JsDocTag::Deprecated { .. }))
20+
};
21+
22+
is_deprecated(a)
23+
.cmp(&is_deprecated(b))
24+
.then_with(|| a.name.cmp(&b.name))
25+
});
1326

1427
let items = members
1528
.into_iter()

src/html/symbols/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl AllSymbolsCtx {
436436
ctx.get_current_resolve(),
437437
UrlResolveKind::File { file: short_path },
438438
),
439-
module_doc: ModuleDocCtx::new(ctx, short_path, true),
439+
module_doc: ModuleDocCtx::new(ctx, short_path, true, true),
440440
})
441441
.collect();
442442

tests/html_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,12 @@ async fn module_doc() {
625625
doc_nodes,
626626
UrlResolveKind::File { file: short_path },
627627
);
628-
let module_doc =
629-
jsdoc::ModuleDocCtx::new(&render_ctx, short_path, !short_path.is_main);
628+
let module_doc = jsdoc::ModuleDocCtx::new(
629+
&render_ctx,
630+
short_path,
631+
!short_path.is_main,
632+
false,
633+
);
630634

631635
module_docs.push(module_doc);
632636
}

tests/snapshots/html_test__html_doc_files_multiple-2.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ expression: files.get(file_name).unwrap()
9595
<div><nav class="topSymbols">
9696
<h3>Symbols</h3>
9797
<ul><li>
98-
<a href=".&#x2F;d&#x2F;~&#x2F;externalFunction.html" title="externalFunction"><div class="docNodeKindIcon"><div class="text-Function bg-Function/15 dark:text-FunctionDark dark:bg-FunctionDark/15" title="Function">f</div></div>
99-
<span class="hover:bg-Function/15 hover:bg-FunctionDark/15">
100-
externalFunction
101-
</span>
102-
</a>
103-
</li><li>
10498
<a href=".&#x2F;.&#x2F;~&#x2F;AbstractClass.html" title="AbstractClass"><div class="docNodeKindIcon"><div class="text-Class bg-Class/15 dark:text-ClassDark dark:bg-ClassDark/15" title="Class">c</div></div>
10599
<span class="hover:bg-Class/15 hover:bg-ClassDark/15">
106100
AbstractClass
@@ -124,6 +118,12 @@ expression: files.get(file_name).unwrap()
124118
CompoundType
125119
</span>
126120
</a>
121+
</li><li>
122+
<a href=".&#x2F;.&#x2F;~&#x2F;EmptyInterface.html" title="EmptyInterface"><div class="docNodeKindIcon"><div class="text-Interface bg-Interface/15 dark:text-InterfaceDark dark:bg-InterfaceDark/15" title="Interface">I</div></div>
123+
<span class="hover:bg-Interface/15 hover:bg-InterfaceDark/15">
124+
EmptyInterface
125+
</span>
126+
</a>
127127
</li></ul><a class="flex items-center gap-0.5" href=".&#x2F;all_symbols.html">
128128
<span class="leading-none">view all 27 symbols</span><svg
129129
width="16"

tests/snapshots/html_test__html_doc_files_multiple-62.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ Functions</h2></div><div class="namespaceSection"><div id="namespace_x" class="n
172172
</div></div><nav class="topSymbols">
173173
<h3>Symbols</h3>
174174
<ul><li>
175-
<a href="..&#x2F;.&#x2F;d&#x2F;~&#x2F;externalFunction.html" title="externalFunction"><div class="docNodeKindIcon"><div class="text-Function bg-Function/15 dark:text-FunctionDark dark:bg-FunctionDark/15" title="Function">f</div></div>
176-
<span class="hover:bg-Function/15 hover:bg-FunctionDark/15">
177-
externalFunction
178-
</span>
179-
</a>
180-
</li><li>
181175
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;AbstractClass.html" title="AbstractClass"><div class="docNodeKindIcon"><div class="text-Class bg-Class/15 dark:text-ClassDark dark:bg-ClassDark/15" title="Class">c</div></div>
182176
<span class="hover:bg-Class/15 hover:bg-ClassDark/15">
183177
AbstractClass
@@ -201,6 +195,12 @@ Functions</h2></div><div class="namespaceSection"><div id="namespace_x" class="n
201195
CompoundType
202196
</span>
203197
</a>
198+
</li><li>
199+
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;EmptyInterface.html" title="EmptyInterface"><div class="docNodeKindIcon"><div class="text-Interface bg-Interface/15 dark:text-InterfaceDark dark:bg-InterfaceDark/15" title="Interface">I</div></div>
200+
<span class="hover:bg-Interface/15 hover:bg-InterfaceDark/15">
201+
EmptyInterface
202+
</span>
203+
</a>
204204
</li></ul><a class="flex items-center gap-0.5" href="..&#x2F;.&#x2F;all_symbols.html">
205205
<span class="leading-none">view all 27 symbols</span><svg
206206
width="16"

tests/snapshots/html_test__html_doc_files_multiple-64.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ Functions</h2></div><div class="namespaceSection"><div id="namespace_externalfun
172172
</div></div><nav class="topSymbols">
173173
<h3>Symbols</h3>
174174
<ul><li>
175-
<a href="..&#x2F;.&#x2F;d&#x2F;~&#x2F;externalFunction.html" title="externalFunction"><div class="docNodeKindIcon"><div class="text-Function bg-Function/15 dark:text-FunctionDark dark:bg-FunctionDark/15" title="Function">f</div></div>
176-
<span class="hover:bg-Function/15 hover:bg-FunctionDark/15">
177-
externalFunction
178-
</span>
179-
</a>
180-
</li><li>
181175
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;AbstractClass.html" title="AbstractClass"><div class="docNodeKindIcon"><div class="text-Class bg-Class/15 dark:text-ClassDark dark:bg-ClassDark/15" title="Class">c</div></div>
182176
<span class="hover:bg-Class/15 hover:bg-ClassDark/15">
183177
AbstractClass
@@ -201,6 +195,12 @@ Functions</h2></div><div class="namespaceSection"><div id="namespace_externalfun
201195
CompoundType
202196
</span>
203197
</a>
198+
</li><li>
199+
<a href="..&#x2F;.&#x2F;.&#x2F;~&#x2F;EmptyInterface.html" title="EmptyInterface"><div class="docNodeKindIcon"><div class="text-Interface bg-Interface/15 dark:text-InterfaceDark dark:bg-InterfaceDark/15" title="Interface">I</div></div>
200+
<span class="hover:bg-Interface/15 hover:bg-InterfaceDark/15">
201+
EmptyInterface
202+
</span>
203+
</a>
204204
</li></ul><a class="flex items-center gap-0.5" href="..&#x2F;.&#x2F;all_symbols.html">
205205
<span class="leading-none">view all 27 symbols</span><svg
206206
width="16"

0 commit comments

Comments
 (0)