Skip to content

Commit 79f30b8

Browse files
authored
feat(tools): add renderTitleInOverview option to cem 11ty plugin (#2444)
1 parent 9fd329e commit 79f30b8

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

.changeset/cem-11ty-title.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
"@patternfly/pfe-tools": minor
3+
---
4+
5+
`11ty/plugins/custom-elements-manifest.cjs`: added `renderTitleInOverview`
6+
option, a boolean flag which defaults to `true`.
7+
8+
When true, this option renders an `<h1>` in the element's docs page's "Overview"
9+
section.
10+
11+
Note: the next major release will switch this option to `false` by default, so
12+
to prepare your docs pages, add your own headings:
13+
14+
BEFORE:
15+
```md
16+
{% renderOverview %}
17+
<pf-jazz-hands></pf-jazz-hands>
18+
{% endrenderOverview %}
19+
```
20+
21+
AFTER:
22+
```md
23+
<section class="band">
24+
<h1 id="jazz-hands">Jazz Hands</h1>
25+
</section>
26+
27+
{% renderOverview %}
28+
<pf-jazz-hands></pf-jazz-hands>
29+
{% endrenderOverview %}
30+
```

tools/create-element/templates/element/docs/element.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
{% renderCssCustomProperties %}{% endrenderCssCustomProperties %}
1616

17-
{% renderCssParts %}{% endrenderCssParts %}
17+
{% renderCssParts %}{% endrenderCssParts %}

tools/pfe-tools/11ty/DocsPage.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface DocsPageOptions extends PfeConfig {
1313
docsTemplatePath?: string;
1414
tagName?: string;
1515
title?: string;
16+
/** When true, renders an <h1> with the element's title in the element docs overview */
17+
renderTitleInOverview?: boolean;
1618
}
1719

1820
export interface RenderKwargs {
@@ -69,7 +71,7 @@ export class DocsPage implements DocsPageRenderer {
6971

7072
constructor(
7173
public manifest: Manifest,
72-
options?: DocsPageOptions) {
74+
private options?: DocsPageOptions) {
7375
this.tagName = options?.tagName ?? '';
7476
this.title = options?.title ?? Manifest.prettyTag(this.tagName);
7577
this.slug = slugify(options?.aliases?.[this.tagName] ?? this.tagName.replace(/^\w+-/, '')).toLowerCase();
@@ -103,7 +105,13 @@ export class DocsPage implements DocsPageRenderer {
103105
/** Render the overview of a component page */
104106
renderOverview(content: string, kwargs: RenderKwargs = {}) {
105107
const description = this.manifest.getDescription(this.#packageTagName(kwargs));
106-
return this.templates.render('overview.njk', { description, content, ...kwargs });
108+
const header = kwargs.title ?? this.title;
109+
// TODO: switch to false in next major
110+
const { renderTitleInOverview = true } = this.options ?? {};
111+
const renderedTitle =
112+
!renderTitleInOverview ? ''
113+
: this.renderBand('', { level: 1, header });
114+
return `${renderedTitle}\n${this.templates.render('overview.njk', { description, content, ...kwargs })}`;
107115
}
108116

109117
/** Render the list of element attributes */

tools/pfe-tools/11ty/templates/overview.njk

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
<header class="band">
2-
<h1>{{ title }}</h1>
3-
</header>
4-
51
<section class="band overview">
62
<h2>Overview</h2>
73

0 commit comments

Comments
 (0)