Skip to content

Commit

Permalink
fix(html): post-sidepanel fixes (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored May 5, 2024
1 parent 0f0f513 commit ac747f9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ pub struct GenerateCtx<'ctx> {
pub href_resolver: Rc<dyn HrefResolver>,
pub usage_composer: Option<UsageComposer>,
pub rewrite_map: Option<IndexMap<ModuleSpecifier, String>>,
pub main_entrypoint: Option<Rc<ShortPath>>,
pub file_mode: FileMode,
pub sidebar_hide_all_symbols: bool,
}

impl<'ctx> GenerateCtx<'ctx> {
Expand All @@ -114,6 +114,8 @@ impl<'ctx> GenerateCtx<'ctx> {
file_mode: FileMode,
doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<DocNode>>,
) -> Result<Self, anyhow::Error> {
let mut main_entrypoint = None;

let doc_nodes = doc_nodes_by_url
.into_iter()
.map(|(specifier, nodes)| {
Expand All @@ -124,6 +126,10 @@ impl<'ctx> GenerateCtx<'ctx> {
common_ancestor.as_ref(),
));

if short_path.is_main {
main_entrypoint = Some(short_path.clone());
}

let nodes = nodes
.into_iter()
.map(|node| DocNodeWithContext {
Expand All @@ -150,7 +156,7 @@ impl<'ctx> GenerateCtx<'ctx> {
href_resolver: options.href_resolver,
usage_composer: options.usage_composer,
rewrite_map: options.rewrite_map,
sidebar_hide_all_symbols: file_mode == FileMode::SingleDts,
main_entrypoint,
file_mode,
})
}
Expand Down Expand Up @@ -568,21 +574,16 @@ pub fn generate(

// Index page
{
let main_entrypoint = ctx
.doc_nodes
.iter()
.find(|(short_path, _)| short_path.is_main);

let partitions_for_entrypoint_nodes =
if let Some((_, doc_nodes)) = main_entrypoint {
get_partitions_for_file(&ctx, doc_nodes)
if let Some(entrypoint) = ctx.main_entrypoint.as_ref() {
get_partitions_for_file(&ctx, ctx.doc_nodes.get(entrypoint).unwrap())
} else {
Default::default()
};

let index = pages::IndexCtx::new(
&ctx,
main_entrypoint.map(|(short_path, _)| short_path.clone()),
ctx.main_entrypoint.clone(),
partitions_for_entrypoint_nodes,
);

Expand Down
8 changes: 1 addition & 7 deletions src/html/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ impl<'ctx> RenderContext<'ctx> {
.get_file()
.cloned()
.unwrap_or_else(|| {
(**self
.ctx
.doc_nodes
.keys()
.find(|short_path| short_path.is_main)
.unwrap())
.clone()
(**self.ctx.main_entrypoint.as_ref().unwrap()).clone()
}),
symbol: target_symbol,
},
Expand Down
2 changes: 1 addition & 1 deletion src/html/templates/toc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</li>
{{~/each~}}
</ul>
{{~#if (gt (len top_symbols.symbols) 5)~}}
{{~#if (gt top_symbols.total_symbols 5)~}}
<a class="flex items-center gap-0.5" href="{{top_symbols.all_symbols_href}}">
<span class="leading-none">view all {{top_symbols.total_symbols}} symbols</span>
{{~> icons/arrow ~}}
Expand Down
10 changes: 8 additions & 2 deletions src/html/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl NamespacedGlobalSymbols {
}

/// Different current and target locations
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum UrlResolveKind<'a> {
Root,
AllSymbols,
Expand Down Expand Up @@ -649,7 +649,13 @@ impl ToCCtx {
usage_doc_nodes: &[DocNodeWithContext],
) -> Self {
Self {
usages: UsagesCtx::new(&ctx, usage_doc_nodes),
usages: if ctx.get_current_resolve() == UrlResolveKind::Root
&& ctx.ctx.main_entrypoint.is_none()
{
None
} else {
UsagesCtx::new(&ctx, usage_doc_nodes)
},
top_symbols: if include_top_symbols {
TopSymbolsCtx::new(&ctx)
} else {
Expand Down

0 comments on commit ac747f9

Please sign in to comment.