Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(html): expose raw document navigation for json output #689

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/html/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ pub enum SymbolPage {
Symbol {
breadcrumbs_ctx: BreadcrumbsCtx,
symbol_group_ctx: SymbolGroupCtx,
toc_ctx: util::ToCCtx,
toc_ctx: Box<util::ToCCtx>,
categories_panel: Option<CategoriesPanelCtx>,
},
Redirect {
Expand Down Expand Up @@ -538,7 +538,7 @@ pub fn generate_symbol_pages_for_module(
generated_pages.push(SymbolPage::Symbol {
breadcrumbs_ctx,
symbol_group_ctx,
toc_ctx,
toc_ctx: Box::new(toc_ctx),
categories_panel,
});

Expand Down Expand Up @@ -571,7 +571,7 @@ pub struct SymbolPageCtx {
pub html_head_ctx: HtmlHeadCtx,
pub symbol_group_ctx: SymbolGroupCtx,
pub breadcrumbs_ctx: BreadcrumbsCtx,
pub toc_ctx: util::ToCCtx,
pub toc_ctx: Box<util::ToCCtx>,
pub disable_search: bool,
pub categories_panel: Option<CategoriesPanelCtx>,
}
Expand Down
9 changes: 5 additions & 4 deletions src/html/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::html::GenerateCtx;
use crate::html::UrlResolveKind;
use crate::node::DocNodeDef;
use deno_graph::ModuleSpecifier;
use serde::Serialize;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::collections::HashSet;
Expand Down Expand Up @@ -309,7 +310,7 @@ impl<'ctx> RenderContext<'ctx> {
}
}

#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct ToCEntry {
pub level: u8,
pub content: String,
Expand Down Expand Up @@ -388,8 +389,8 @@ impl HeadingToCAdapter {
}
}

pub fn render(self) -> Option<String> {
let toc = Arc::into_inner(self.toc).unwrap().into_inner().unwrap();
pub fn render(&self) -> Option<String> {
let toc = self.toc.lock().unwrap();

if toc.is_empty() {
return None;
Expand All @@ -399,7 +400,7 @@ impl HeadingToCAdapter {
let mut current_level = toc.iter().map(|entry| entry.level).min().unwrap();

let mut level_diff = 0;
for entry in toc {
for entry in toc.iter() {
match current_level.cmp(&entry.level) {
Ordering::Equal => {}
Ordering::Less => {
Expand Down
6 changes: 3 additions & 3 deletions src/html/templates/toc.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{~#if (or usages (or top_symbols document_navigation))~}}
{{~#if (or usages (or top_symbols document_navigation_str))~}}
<div class="toc">
<div>
{{~#if usages~}}
Expand Down Expand Up @@ -27,10 +27,10 @@
</nav>
{{~/if~}}

{{~#if document_navigation~}}
{{~#if document_navigation_str~}}
<nav class="documentNavigation">
<h3>Document Navigation</h3>
{{{~document_navigation~}}} {{! table of contents }}
{{{~document_navigation_str~}}} {{! table of contents }}
</nav>
{{~/if~}}
</div>
Expand Down
13 changes: 10 additions & 3 deletions src/html/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::html::jsdoc::markdown_to_html;
use crate::html::jsdoc::MarkdownToHTMLOptions;
use crate::html::render_context::ToCEntry;
use crate::html::usage::UsagesCtx;
use crate::html::DocNodeKindWithDrilldown;
use crate::html::DocNodeWithContext;
Expand Down Expand Up @@ -740,7 +741,8 @@ impl TopSymbolsCtx {
pub struct ToCCtx {
pub usages: Option<UsagesCtx>,
pub top_symbols: Option<TopSymbolsCtx>,
pub document_navigation: Option<String>,
pub document_navigation_str: Option<String>,
pub document_navigation: Vec<ToCEntry>,
}

impl ToCCtx {
Expand All @@ -757,7 +759,8 @@ impl ToCCtx {
return Self {
usages: None,
top_symbols: None,
document_navigation: None,
document_navigation_str: None,
document_navigation: vec![],
};
}

Expand All @@ -775,7 +778,11 @@ impl ToCCtx {
} else {
None
},
document_navigation: ctx.toc.render(),
document_navigation_str: ctx.toc.render(),
document_navigation: std::sync::Arc::into_inner(ctx.toc.toc)
.unwrap()
.into_inner()
.unwrap(),
}
}
}
Expand Down
Loading
Loading