mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
Add prefetching to sidebar links
This commit is contained in:
parent
bfc00a4b94
commit
bdd98e0276
2 changed files with 43 additions and 25 deletions
|
@ -58,36 +58,53 @@ pub fn generate_docs_html(filenames: Vec<PathBuf>) {
|
|||
)
|
||||
.expect("TODO gracefully handle failing to make the favicon");
|
||||
|
||||
let module_pairs = package.modules.iter().flat_map(|loaded_module| {
|
||||
loaded_module
|
||||
.documentation
|
||||
.iter()
|
||||
.filter_map(move |(module_id, module)| {
|
||||
// TODO it seems this `documentation` dictionary has entries for
|
||||
// every module, but only the current module has any info in it.
|
||||
// We disregard the others, but probably this shouldn't bother
|
||||
// being a hash map in the first place if only one of its entries
|
||||
// actually has interesting information in it?
|
||||
if *module_id == loaded_module.module_id {
|
||||
let exposed_values = loaded_module
|
||||
.exposed_values
|
||||
.iter()
|
||||
.map(|symbol| symbol.as_str(&loaded_module.interns).to_string())
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
Some((module, exposed_values))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let template_html = include_str!("./static/index.html")
|
||||
.replace("<!-- search.js -->", "/search.js")
|
||||
.replace("<!-- styles.css -->", "/styles.css")
|
||||
.replace("<!-- favicon.svg -->", "/favicon.svg")
|
||||
.replace(
|
||||
"<!-- Module links -->",
|
||||
render_sidebar(package.modules.iter().flat_map(|loaded_module| {
|
||||
loaded_module
|
||||
.documentation
|
||||
.iter()
|
||||
.filter_map(move |(module_id, module)| {
|
||||
// TODO it seems this `documentation` dictionary has entries for
|
||||
// every module, but only the current module has any info in it.
|
||||
// We disregard the others, but probably this shouldn't bother
|
||||
// being a hash map in the first place if only one of its entries
|
||||
// actually has interesting information in it?
|
||||
if *module_id == loaded_module.module_id {
|
||||
let exposed_values = loaded_module
|
||||
.exposed_values
|
||||
.iter()
|
||||
.map(|symbol| symbol.as_str(&loaded_module.interns).to_string())
|
||||
.collect::<Vec<String>>();
|
||||
"<!-- Prefetch links -->",
|
||||
&module_pairs
|
||||
.clone()
|
||||
.map(|(module, _)| {
|
||||
let href = {
|
||||
let mut href_buf = base_url();
|
||||
href_buf.push_str(module.name.as_str());
|
||||
href_buf
|
||||
};
|
||||
|
||||
Some((module, exposed_values))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}))
|
||||
.as_str(),
|
||||
format!(r#"<link rel="prefetch" href="{href}"/>"#)
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n "),
|
||||
)
|
||||
.replace(
|
||||
"<!-- Module links -->",
|
||||
render_sidebar(module_pairs).as_str(),
|
||||
);
|
||||
|
||||
// Write each package's module docs html file
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
<!-- <title>TODO populate this based on the module's name, e.g. "Parser - roc/parser"</title> -->
|
||||
<!-- <meta name="description" content="TODO populate this based on the module's description"> -->
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<link rel="icon" href="<!-- favicon.svg -->">
|
||||
<script type="text/javascript" src="<!-- search.js -->" defer></script>
|
||||
<link rel="icon" href="<!-- favicon.svg -->">
|
||||
<link rel="stylesheet" href="<!-- styles.css -->">
|
||||
<!-- Prefetch links -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue