Skip to content

Commit 98a7795

Browse files
authored
Merge pull request #2733 from mrfigg/headings
Added headings option to control optional headings, changed all headings to h1, #2729
2 parents 97d0620 + b0648a1 commit 98a7795

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Unreleased
22

3+
### Features
4+
5+
- Added `headings` option to control optional headings, #2729.
6+
37
### Bug Fixes
48

59
- `externalSymbolLinkMappings` now uses the TypeScript reported link target if available, #2725.
610
- TypeDoc will no longer omit the modules page if a project contains only modules/documents, #2730.
711
- Fixed missing breadcrumbs on project page, #2728.
12+
- TypeDoc will no longer render an empty readme page if no readme was found.
13+
14+
### Thanks!
15+
16+
- @lriggle-strib
17+
- @mrfigg
818

919
## v0.26.8 (2024-10-04)
1020

src/lib/internationalization/translatable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export const translatable = {
300300
help_navigationLeaves:
301301
"Branches of the navigation tree which should not be expanded",
302302
help_navigation: "Determines how the navigation sidebar is organized",
303+
help_headings: "Determines which optional headings are rendered",
303304
help_visibilityFilters:
304305
"Specify the default visibility for builtin filters and additional filters according to modifier tags",
305306
help_searchCategoryBoosts:

src/lib/output/themes/default/DefaultTheme.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class DefaultTheme extends Theme {
205205
const urls: UrlMapping[] = [];
206206
this.sluggers.set(project, new Slugger());
207207

208-
if (!hasReadme(this.application.options.getValue("readme"))) {
208+
if (!project.readme?.length) {
209209
project.url = "index.html";
210210
urls.push(new UrlMapping<ContainerReflection>("index.html", project, this.reflectionTemplate));
211211
} else {
@@ -507,10 +507,6 @@ export class DefaultTheme extends Theme {
507507
}
508508
}
509509

510-
function hasReadme(readme: string) {
511-
return !readme.endsWith("none");
512-
}
513-
514510
function getReflectionClasses(
515511
reflection: DeclarationReflection | DocumentReflection,
516512
filters: Record<string, boolean>,

src/lib/output/themes/default/partials/header.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@ import { classNames, getDisplayName, hasTypeParameters, join } from "../../lib";
22
import { JSX } from "../../../../utils";
33
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
44
import type { PageEvent } from "../../../events";
5-
import { type Reflection, ReflectionKind } from "../../../../models";
5+
import type { Reflection } from "../../../../models";
66

77
export const header = (context: DefaultThemeRenderContext, props: PageEvent<Reflection>) => {
8-
const HeadingLevel = props.model.isProject() ? "h2" : "h1";
8+
const opts = context.options.getValue("headings");
9+
10+
// Don't render on the index page or the class hierarchy page
11+
// We should probably someday render on the class hierarchy page, but currently breadcrumbs
12+
// are entirely dependent on the reflection hierarchy, so it doesn't make sense today.
13+
const renderBreadcrumbs = props.url !== "index.html" && props.url !== "hierarchy.html";
14+
15+
// Titles are always rendered on DeclarationReflection pages and the modules page for the project.
16+
// They are also rendered on the readme + document pages if configured to do so by the user.
17+
let renderTitle: boolean;
18+
let titleKindString = "";
19+
if (props.model.isProject()) {
20+
if (props.url === "index.html" && props.model.readme?.length) {
21+
renderTitle = opts.readme;
22+
} else {
23+
renderTitle = true;
24+
}
25+
} else if (props.model.isDocument()) {
26+
renderTitle = opts.document;
27+
} else {
28+
renderTitle = true;
29+
titleKindString = " " + context.internationalization.kindSingularString(props.model.kind);
30+
}
31+
932
return (
1033
<div class="tsd-page-title">
11-
{props.url !== "index.html" && props.url !== "hierarchy.html" && (
12-
<ul class="tsd-breadcrumb">{context.breadcrumb(props.model)}</ul>
13-
)}
14-
{!props.model.isDocument() && (
15-
<HeadingLevel class={classNames({ deprecated: props.model.isDeprecated() })}>
16-
{props.model.kind !== ReflectionKind.Project &&
17-
`${context.internationalization.kindSingularString(props.model.kind)} `}
34+
{renderBreadcrumbs && <ul class="tsd-breadcrumb">{context.breadcrumb(props.model)}</ul>}
35+
{renderTitle && (
36+
<h1 class={classNames({ deprecated: props.model.isDeprecated() })}>
37+
{titleKindString}
1838
{getDisplayName(props.model)}
1939
{hasTypeParameters(props.model) && (
2040
<>
@@ -24,7 +44,7 @@ export const header = (context: DefaultThemeRenderContext, props: PageEvent<Refl
2444
</>
2545
)}
2646
{context.reflectionFlags(props.model)}
27-
</HeadingLevel>
47+
</h1>
2848
)}
2949
</div>
3050
);

src/lib/utils/options/declaration.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export interface TypeDocOptionMap {
185185
compactFolders: boolean;
186186
excludeReferences: boolean;
187187
};
188+
headings: {
189+
readme: boolean;
190+
document: boolean;
191+
};
188192
visibilityFilters: ManuallyValidatedOption<{
189193
protected?: boolean;
190194
private?: boolean;

src/lib/utils/options/sources/typedoc.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,16 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
564564
},
565565
});
566566

567+
options.addDeclaration({
568+
name: "headings",
569+
help: (i18n) => i18n.help_headings(),
570+
type: ParameterType.Flags,
571+
defaults: {
572+
readme: true,
573+
document: false,
574+
},
575+
});
576+
567577
options.addDeclaration({
568578
name: "visibilityFilters",
569579
help: (i18n) => i18n.help_visibilityFilters(),

0 commit comments

Comments
 (0)