Skip to content

Commit

Permalink
refactor: split mod.ts into more modules
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Dec 6, 2023
1 parent 3ab1155 commit 456284f
Show file tree
Hide file tree
Showing 5 changed files with 583 additions and 537 deletions.
41 changes: 41 additions & 0 deletions src/html/jsdoc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use super::util::*;
use crate::html::GenerateCtx;
use crate::js_doc::JsDoc;
use crate::js_doc::JsDocTag;
use crate::DocNode;
use crate::DocNodeKind;
use deno_ast::ModuleSpecifier;
use indexmap::IndexMap;
use serde::Serialize;
use serde_json::json;

Expand Down Expand Up @@ -254,3 +259,39 @@ pub(crate) fn render_doc_entry(
}),
)
}

#[derive(Debug, Serialize, Clone)]
pub struct ModuleDocCtx {
url: String,
docs: String,
}

impl ModuleDocCtx {
pub fn new(
ctx: &GenerateCtx,
render_ctx: &RenderContext,
specifier: Option<&ModuleSpecifier>,
doc_nodes_by_url: &IndexMap<ModuleSpecifier, Vec<DocNode>>,
) -> Option<Self> {
if let Some(main_entrypoint) = specifier {
let module_doc_nodes = doc_nodes_by_url.get(main_entrypoint).unwrap();

let docs = module_doc_nodes
.iter()
.find(|n| n.kind == DocNodeKind::ModuleDoc);

docs
.and_then(|node| node.js_doc.doc.as_ref())
.map(|docs_md| {
let rendered_docs = render_markdown(docs_md, render_ctx);

Self {
url: ctx.url_to_short_path(main_entrypoint),
docs: rendered_docs,
}
})
} else {
None
}
}
}
Loading

0 comments on commit 456284f

Please sign in to comment.