Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added headings option to control optional headings, changed all headings to h1, #2729 #2733

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Unreleased

### Features

- Added `headings` option to control optional headings, #2729.

### Bug Fixes

- `externalSymbolLinkMappings` now uses the TypeScript reported link target if available, #2725.
- TypeDoc will no longer omit the modules page if a project contains only modules/documents, #2730.
- Fixed missing breadcrumbs on project page, #2728.
- TypeDoc will no longer render an empty readme page if no readme was found.

### Thanks!

- @lriggle-strib
- @mrfigg

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

Expand Down
1 change: 1 addition & 0 deletions src/lib/internationalization/translatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export const translatable = {
help_navigationLeaves:
"Branches of the navigation tree which should not be expanded",
help_navigation: "Determines how the navigation sidebar is organized",
help_headings: "Determines which optional headings are rendered",
help_visibilityFilters:
"Specify the default visibility for builtin filters and additional filters according to modifier tags",
help_searchCategoryBoosts:
Expand Down
6 changes: 1 addition & 5 deletions src/lib/output/themes/default/DefaultTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class DefaultTheme extends Theme {
const urls: UrlMapping[] = [];
this.sluggers.set(project, new Slugger());

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

function hasReadme(readme: string) {
return !readme.endsWith("none");
}

function getReflectionClasses(
reflection: DeclarationReflection | DocumentReflection,
filters: Record<string, boolean>,
Expand Down
40 changes: 30 additions & 10 deletions src/lib/output/themes/default/partials/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,39 @@ import { classNames, getDisplayName, hasTypeParameters, join } from "../../lib";
import { JSX } from "../../../../utils";
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
import type { PageEvent } from "../../../events";
import { type Reflection, ReflectionKind } from "../../../../models";
import type { Reflection } from "../../../../models";

export const header = (context: DefaultThemeRenderContext, props: PageEvent<Reflection>) => {
const HeadingLevel = props.model.isProject() ? "h2" : "h1";
const opts = context.options.getValue("headings");

// Don't render on the index page or the class hierarchy page
// We should probably someday render on the class hierarchy page, but currently breadcrumbs
// are entirely dependent on the reflection hierarchy, so it doesn't make sense today.
const renderBreadcrumbs = props.url !== "index.html" && props.url !== "hierarchy.html";

// Titles are always rendered on DeclarationReflection pages and the modules page for the project.
// They are also rendered on the readme + document pages if configured to do so by the user.
let renderTitle: boolean;
let titleKindString = "";
if (props.model.isProject()) {
if (props.url === "index.html" && props.model.readme?.length) {
renderTitle = opts.readme;
} else {
renderTitle = true;
}
} else if (props.model.isDocument()) {
renderTitle = opts.document;
} else {
renderTitle = true;
titleKindString = " " + context.internationalization.kindSingularString(props.model.kind);
}

return (
<div class="tsd-page-title">
{props.url !== "index.html" && props.url !== "hierarchy.html" && (
<ul class="tsd-breadcrumb">{context.breadcrumb(props.model)}</ul>
)}
{!props.model.isDocument() && (
<HeadingLevel class={classNames({ deprecated: props.model.isDeprecated() })}>
{props.model.kind !== ReflectionKind.Project &&
`${context.internationalization.kindSingularString(props.model.kind)} `}
{renderBreadcrumbs && <ul class="tsd-breadcrumb">{context.breadcrumb(props.model)}</ul>}
{renderTitle && (
<h1 class={classNames({ deprecated: props.model.isDeprecated() })}>
Gerrit0 marked this conversation as resolved.
Show resolved Hide resolved
{titleKindString}
{getDisplayName(props.model)}
{hasTypeParameters(props.model) && (
<>
Expand All @@ -24,7 +44,7 @@ export const header = (context: DefaultThemeRenderContext, props: PageEvent<Refl
</>
)}
{context.reflectionFlags(props.model)}
</HeadingLevel>
</h1>
)}
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/utils/options/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export interface TypeDocOptionMap {
compactFolders: boolean;
excludeReferences: boolean;
};
headings: {
readme: boolean;
document: boolean;
};
visibilityFilters: ManuallyValidatedOption<{
protected?: boolean;
private?: boolean;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/utils/options/sources/typedoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,16 @@ export function addTypeDocOptions(options: Pick<Options, "addDeclaration">) {
},
});

options.addDeclaration({
name: "headings",
help: (i18n) => i18n.help_headings(),
type: ParameterType.Flags,
defaults: {
readme: true,
document: false,
},
});

options.addDeclaration({
name: "visibilityFilters",
help: (i18n) => i18n.help_visibilityFilters(),
Expand Down