diff --git a/CHANGELOG.md b/CHANGELOG.md index b3095590..dc66df7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Support for defining a project's title (DOCSP-7988) + ## [v0.2.0] - 2020-01-23 ### Added diff --git a/snooty/parser.py b/snooty/parser.py index a2b8ed1d..e91fc82e 100644 --- a/snooty/parser.py +++ b/snooty/parser.py @@ -769,6 +769,9 @@ def get_page_ast(self, path: Path) -> SerializableType: def get_project_name(self) -> str: return self.config.name + def get_project_title(self) -> str: + return self.config.title + def update(self, path: Path, optional_text: Optional[str] = None) -> None: diagnostics: Dict[PurePath, List[Diagnostic]] = {path: []} prefix = get_giza_category(path) diff --git a/snooty/semanticparser.py b/snooty/semanticparser.py index 271877fe..85e088d4 100644 --- a/snooty/semanticparser.py +++ b/snooty/semanticparser.py @@ -48,6 +48,8 @@ def run( document: Dict[str, SerializableType] = {} + document.update({"title": self.project_config.title}) + self.run_event_parser( [ (OBJECT_START_EVENT, self.populate_include_nodes), @@ -226,7 +228,7 @@ def build_toctree(self) -> Dict[str, SerializableType]: # Build the toctree root: Dict[str, SerializableType] = { - "title": self.project_config.name, + "title": self.project_config.title, "slug": "/", "children": [], } diff --git a/snooty/test_semantic_parser.py b/snooty/test_semantic_parser.py index 8750edaa..9f384bdc 100644 --- a/snooty/test_semantic_parser.py +++ b/snooty/test_semantic_parser.py @@ -189,7 +189,7 @@ def test_toctree(backend: Backend) -> None: ], }, ], - "title": "test_data", + "title": "untitled", "slug": "/", } diff --git a/snooty/test_types.py b/snooty/test_types.py index 38bc09b1..956ba0f0 100644 --- a/snooty/test_types.py +++ b/snooty/test_types.py @@ -21,7 +21,8 @@ def test_project() -> None: # Test missing project behavior project_config, project_diagnostics = ProjectConfig.open(Path(".").resolve()) - assert project_config.name == "untitled" + assert project_config.name == "unnamed" + assert project_config.title == "untitled" assert len(project_diagnostics) == 0 diff --git a/snooty/types.py b/snooty/types.py index 57ab8ddd..aada8d53 100644 --- a/snooty/types.py +++ b/snooty/types.py @@ -365,6 +365,7 @@ def finish( class ProjectConfig: root: Path name: str + title: str = field(default="untitled") source: str = field(default="source") constants: Dict[str, object] = field(default_factory=dict) intersphinx: List[str] = field(default_factory=list) @@ -401,7 +402,7 @@ def open(cls, root: Path) -> Tuple["ProjectConfig", List[Diagnostic]]: path = path.parent - return cls(root, "untitled"), diagnostics + return cls(root, name="unnamed"), diagnostics def render_constants(self) -> Tuple["ProjectConfig", List[Diagnostic]]: if not self.constants: diff --git a/test_data/test_project/snooty.toml b/test_data/test_project/snooty.toml index 82db4268..491eaf0f 100644 --- a/test_data/test_project/snooty.toml +++ b/test_data/test_project/snooty.toml @@ -1,7 +1,8 @@ name = "test_data" [constants] -name = "MongoDB" +name = "MongoDB name" +title = "MongoDB title" [substitutions] guides = "MongoDB Guides" diff --git a/test_data/test_semantic_parser/snooty.toml b/test_data/test_semantic_parser/snooty.toml index 0dfdaec3..34c7e815 100644 --- a/test_data/test_semantic_parser/snooty.toml +++ b/test_data/test_semantic_parser/snooty.toml @@ -1,6 +1,7 @@ -name = "test_data" +name = "test_name" toc_landing_pages = ["/page2", "page3"] intersphinx = ["https://docs.mongodb.com/manual/objects.inv"] [constants] -name = "MongoDB" +name = "MongoDB name" +title = "MongoDB title"