Dynamically generate the documentation title

This commit is contained in:
Christopher Duncan 2022-10-15 19:45:31 -04:00
parent d6885bde23
commit 7131432e7c
No known key found for this signature in database
GPG key ID: CCC42F03843A4CA8
2 changed files with 15 additions and 4 deletions

View file

@ -9,7 +9,7 @@ use roc_code_markup::slow_pool::SlowPool;
use roc_highlight::highlight_parser::{highlight_defs, highlight_expr};
use roc_load::docs::DocEntry::DocDef;
use roc_load::docs::{DocEntry, TypeAnnotation};
use roc_load::docs::{ModuleDocumentation, RecordField};
use roc_load::docs::{Documentation, ModuleDocumentation, RecordField};
use roc_load::{ExecutionMode, LoadConfig, LoadedModule, LoadingProblem, Threading};
use roc_module::symbol::{IdentIdsByModule, Interns, ModuleId};
use roc_parse::ident::{parse_ident, Ident};
@ -28,7 +28,7 @@ pub fn generate_docs_html(filenames: Vec<PathBuf>) {
let loaded_modules = load_modules_for_files(filenames);
// TODO: get info from a package module; this is all hardcoded for now.
let mut package = roc_load::docs::Documentation {
let package = Documentation {
name: "documentation".to_string(),
version: "".to_string(),
docs: "Package introduction or README.".to_string(),
@ -104,7 +104,7 @@ pub fn generate_docs_html(filenames: Vec<PathBuf>) {
);
// Write each package's module docs html file
for loaded_module in package.modules.iter_mut() {
for loaded_module in package.modules.iter() {
for (module_id, module_docs) in loaded_module.documentation.iter() {
if *module_id == loaded_module.module_id {
let module_dir = build_dir.join(module_docs.name.replace('.', "/").as_str());
@ -113,6 +113,10 @@ pub fn generate_docs_html(filenames: Vec<PathBuf>) {
.expect("TODO gracefully handle not being able to create the module dir");
let rendered_module = template_html
.replace(
"<!-- Page title -->",
page_title(&package, module_docs).as_str(),
)
.replace(
"<!-- Package Name and Version -->",
render_name_and_version(package.name.as_str(), package.version.as_str())
@ -138,6 +142,13 @@ fn sidebar_link_url(module: &ModuleDocumentation) -> String {
url
}
fn page_title(package: &Documentation, module: &ModuleDocumentation) -> String {
let package_name = &package.name;
let module_name = &module.name;
let title = format!("<title>{module_name} - {package_name}</title>");
title
}
// converts plain-text code to highlighted html
pub fn syntax_highlight_expr(code_str: &str) -> DocsResult<String> {
let trimmed_code_str = code_str.trim_end().trim();

View file

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<!-- <title>TODO populate this based on the module's name, e.g. "Parser - roc/parser"</title> -->
<!-- Page title -->
<!-- <meta name="description" content="TODO populate this based on the module's description"> -->
<meta name="viewport" content="width=device-width">
<script type="text/javascript" src="<!-- search.js -->" defer></script>