Skip to content

Commit ac747f9

Browse files
authored
fix(html): post-sidepanel fixes (#570)
1 parent 0f0f513 commit ac747f9

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/html/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ pub struct GenerateCtx<'ctx> {
103103
pub href_resolver: Rc<dyn HrefResolver>,
104104
pub usage_composer: Option<UsageComposer>,
105105
pub rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
106+
pub main_entrypoint: Option<Rc<ShortPath>>,
106107
pub file_mode: FileMode,
107-
pub sidebar_hide_all_symbols: bool,
108108
}
109109

110110
impl<'ctx> GenerateCtx<'ctx> {
@@ -114,6 +114,8 @@ impl<'ctx> GenerateCtx<'ctx> {
114114
file_mode: FileMode,
115115
doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<DocNode>>,
116116
) -> Result<Self, anyhow::Error> {
117+
let mut main_entrypoint = None;
118+
117119
let doc_nodes = doc_nodes_by_url
118120
.into_iter()
119121
.map(|(specifier, nodes)| {
@@ -124,6 +126,10 @@ impl<'ctx> GenerateCtx<'ctx> {
124126
common_ancestor.as_ref(),
125127
));
126128

129+
if short_path.is_main {
130+
main_entrypoint = Some(short_path.clone());
131+
}
132+
127133
let nodes = nodes
128134
.into_iter()
129135
.map(|node| DocNodeWithContext {
@@ -150,7 +156,7 @@ impl<'ctx> GenerateCtx<'ctx> {
150156
href_resolver: options.href_resolver,
151157
usage_composer: options.usage_composer,
152158
rewrite_map: options.rewrite_map,
153-
sidebar_hide_all_symbols: file_mode == FileMode::SingleDts,
159+
main_entrypoint,
154160
file_mode,
155161
})
156162
}
@@ -568,21 +574,16 @@ pub fn generate(
568574

569575
// Index page
570576
{
571-
let main_entrypoint = ctx
572-
.doc_nodes
573-
.iter()
574-
.find(|(short_path, _)| short_path.is_main);
575-
576577
let partitions_for_entrypoint_nodes =
577-
if let Some((_, doc_nodes)) = main_entrypoint {
578-
get_partitions_for_file(&ctx, doc_nodes)
578+
if let Some(entrypoint) = ctx.main_entrypoint.as_ref() {
579+
get_partitions_for_file(&ctx, ctx.doc_nodes.get(entrypoint).unwrap())
579580
} else {
580581
Default::default()
581582
};
582583

583584
let index = pages::IndexCtx::new(
584585
&ctx,
585-
main_entrypoint.map(|(short_path, _)| short_path.clone()),
586+
ctx.main_entrypoint.clone(),
586587
partitions_for_entrypoint_nodes,
587588
);
588589

src/html/render_context.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,7 @@ impl<'ctx> RenderContext<'ctx> {
111111
.get_file()
112112
.cloned()
113113
.unwrap_or_else(|| {
114-
(**self
115-
.ctx
116-
.doc_nodes
117-
.keys()
118-
.find(|short_path| short_path.is_main)
119-
.unwrap())
120-
.clone()
114+
(**self.ctx.main_entrypoint.as_ref().unwrap()).clone()
121115
}),
122116
symbol: target_symbol,
123117
},

src/html/templates/toc.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</li>
1818
{{~/each~}}
1919
</ul>
20-
{{~#if (gt (len top_symbols.symbols) 5)~}}
20+
{{~#if (gt top_symbols.total_symbols 5)~}}
2121
<a class="flex items-center gap-0.5" href="{{top_symbols.all_symbols_href}}">
2222
<span class="leading-none">view all {{top_symbols.total_symbols}} symbols</span>
2323
{{~> icons/arrow ~}}

src/html/util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl NamespacedGlobalSymbols {
227227
}
228228

229229
/// Different current and target locations
230-
#[derive(Debug, Clone, Copy)]
230+
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
231231
pub enum UrlResolveKind<'a> {
232232
Root,
233233
AllSymbols,
@@ -649,7 +649,13 @@ impl ToCCtx {
649649
usage_doc_nodes: &[DocNodeWithContext],
650650
) -> Self {
651651
Self {
652-
usages: UsagesCtx::new(&ctx, usage_doc_nodes),
652+
usages: if ctx.get_current_resolve() == UrlResolveKind::Root
653+
&& ctx.ctx.main_entrypoint.is_none()
654+
{
655+
None
656+
} else {
657+
UsagesCtx::new(&ctx, usage_doc_nodes)
658+
},
653659
top_symbols: if include_top_symbols {
654660
TopSymbolsCtx::new(&ctx)
655661
} else {

0 commit comments

Comments
 (0)