mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Restyle docs search results
This commit is contained in:
parent
b456ee9592
commit
aabef9dd48
3 changed files with 49 additions and 49 deletions
|
@ -357,7 +357,8 @@ fn render_module_documentation(
|
|||
}
|
||||
|
||||
fn push_html<'a, 'b, I>(buf: &mut String, tag_name: &str, attrs: I, content: impl AsRef<str>)
|
||||
where I: IntoIterator<Item=(&'a str, &'b str)>
|
||||
where
|
||||
I: IntoIterator<Item = (&'a str, &'b str)>,
|
||||
{
|
||||
buf.push('<');
|
||||
buf.push_str(tag_name);
|
||||
|
@ -418,12 +419,7 @@ fn render_name_link(name: &str) -> String {
|
|||
let mut link_buf = String::new();
|
||||
|
||||
// link to root (= docs overview page)
|
||||
push_html(
|
||||
&mut link_buf,
|
||||
"a",
|
||||
[("href", base_url().as_str())],
|
||||
name,
|
||||
);
|
||||
push_html(&mut link_buf, "a", [("href", base_url().as_str())], name);
|
||||
|
||||
link_buf
|
||||
});
|
||||
|
@ -496,40 +492,45 @@ fn render_search_type_ahead<'a, I: Iterator<Item = &'a ModuleDocumentation>>(mod
|
|||
if let DocEntry::DocDef(doc_def) = entry {
|
||||
if module.exposed_symbols.contains(&doc_def.symbol) {
|
||||
let mut entry_contents_buf = String::new();
|
||||
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"p",
|
||||
"span",
|
||||
[("class", "type-ahead-module-name")],
|
||||
module_name,
|
||||
);
|
||||
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"span",
|
||||
[("class", "type-ahead-module-dot")],
|
||||
".",
|
||||
);
|
||||
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"span",
|
||||
[("class", "type-ahead-def-name")],
|
||||
doc_def.name.as_str(),
|
||||
&doc_def.name,
|
||||
);
|
||||
|
||||
let mut entry_signature_buf = String::new();
|
||||
type_annotation_to_html(
|
||||
0,
|
||||
&mut entry_signature_buf,
|
||||
&doc_def.type_annotation,
|
||||
false,
|
||||
);
|
||||
let mut type_ann_buf = String::new();
|
||||
type_annotation_to_html(0, &mut type_ann_buf, &doc_def.type_annotation, false);
|
||||
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"p",
|
||||
[("class", "type-ahead-signature")],
|
||||
entry_signature_buf.as_str(),
|
||||
);
|
||||
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"p",
|
||||
[("class", "type-ahead-doc-path")],
|
||||
format!("{} > {}", module_name, doc_def.name),
|
||||
);
|
||||
if !type_ann_buf.is_empty() {
|
||||
push_html(
|
||||
&mut entry_contents_buf,
|
||||
"span",
|
||||
[("class", "type-ahead-signature")],
|
||||
format!(" : {type_ann_buf}"),
|
||||
);
|
||||
}
|
||||
|
||||
let mut entry_href = String::new();
|
||||
|
||||
entry_href.push_str(module_name);
|
||||
entry_href.push('#');
|
||||
entry_href.push_str(doc_def.name.as_str());
|
||||
entry_href.push_str(&doc_def.name);
|
||||
|
||||
let mut anchor_buf = String::new();
|
||||
|
||||
|
@ -537,15 +538,10 @@ fn render_search_type_ahead<'a, I: Iterator<Item = &'a ModuleDocumentation>>(mod
|
|||
&mut anchor_buf,
|
||||
"a",
|
||||
[("href", entry_href.as_str()), ("class", "type-ahead-link")],
|
||||
entry_contents_buf.as_str(),
|
||||
&entry_contents_buf,
|
||||
);
|
||||
|
||||
push_html(
|
||||
&mut buf,
|
||||
"li",
|
||||
[("role", "option")],
|
||||
anchor_buf.as_str(),
|
||||
);
|
||||
push_html(&mut buf, "li", [("role", "option")], &anchor_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@
|
|||
.textContent.toLowerCase();
|
||||
const entrySignature = entry
|
||||
.querySelector(".type-ahead-signature")
|
||||
.textContent.toLowerCase()
|
||||
.replace(/\s+/g, "");
|
||||
?.textContent?.toLowerCase()
|
||||
?.replace(/\s+/g, "");
|
||||
|
||||
if (
|
||||
totalResults < 5 &&
|
||||
(entryName.includes(text) ||
|
||||
entrySignature.includes(text.replace(/\s+/g, "")))
|
||||
entrySignature?.includes(text.replace(/\s+/g, "")))
|
||||
) {
|
||||
totalResults++;
|
||||
entry.classList.remove("hidden");
|
||||
|
|
|
@ -482,8 +482,9 @@ pre>samp {
|
|||
}
|
||||
|
||||
#search-type-ahead {
|
||||
font-family: var(--font-mono);
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
gap: 0px;
|
||||
flex-direction: column;
|
||||
position: absolute;
|
||||
top: calc(var(--module-search-padding-height) + var(--module-search-height));
|
||||
|
@ -501,20 +502,23 @@ pre>samp {
|
|||
}
|
||||
|
||||
#search-type-ahead .type-ahead-link {
|
||||
font-size: 0.875rem;
|
||||
font-size: 1rem;
|
||||
color: var(--text-color);
|
||||
p {
|
||||
line-height: 2em;
|
||||
display: inline-block;
|
||||
|
||||
/* if it wraps, indent after the first line */
|
||||
padding-left: 2em;
|
||||
text-indent: -2em;
|
||||
|
||||
span {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
p.type-ahead-def-name {
|
||||
.type-ahead-module-name, .type-ahead-def-name {
|
||||
color: var(--violet);
|
||||
font-size: 1rem;
|
||||
}
|
||||
p.type-ahead-doc-path {
|
||||
font-size: 0.75rem;
|
||||
color: var(--faded-color);
|
||||
}
|
||||
}
|
||||
#search-type-ahead li {
|
||||
box-sizing: border-box;
|
||||
|
@ -545,7 +549,7 @@ pre>samp {
|
|||
}
|
||||
|
||||
#search-shortcut-key {
|
||||
font-family: monospace;
|
||||
font-family: var(--font-mono);
|
||||
border: 1px solid #666;
|
||||
border-radius: 5px;
|
||||
padding: 1px 3px 3px;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue