Skip to content

Commit 6351542

Browse files
authored
Fixed changelog issues (#595)
* Fixed changelog issues * update
1 parent 9b369c9 commit 6351542

File tree

14 files changed

+201
-3
lines changed

14 files changed

+201
-3
lines changed

scripts/docs-collator/templates/components/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ tags: [{{ tags|join(', ') }}]
88

99
{{ content }}
1010

11+
{% if change_log_content|trim != "" %}
1112
## CHANGELOG
1213

13-
{{ change_log_content }}
14+
{{ change_log_content }}
15+
{% endif %}

src/plugins/changelog/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function extractCommitters(content) {
2929
let committers = "";
3030

3131
if (matches.length > 0) {
32-
committers += "## Commiters: \n";
32+
committers += "## Commiters \n";
3333
for (let i = 0; i < matches.length; i++) {
3434
const author = matches[i].replace('@', '');
3535

@@ -58,7 +58,7 @@ function extractPullRequests(content) {
5858
let prs = "";
5959

6060
if (matches.length > 0) {
61-
prs += "## Pull Requests: \n";
61+
prs += "## Pull Requests \n";
6262
for (let i = 0; i < matches.length; i++) {
6363
const pr = matches[i];
6464

@@ -72,6 +72,12 @@ function extractPullRequests(content) {
7272
};
7373
}
7474

75+
function capitalizeHeaders(str) {
76+
return str.replace(/(##+)(\s[a-z])/g, function(match, p1, p2) {
77+
return p1 + p2.toUpperCase();
78+
});
79+
}
80+
7581
/**
7682
* @param {string} section
7783
*/
@@ -98,6 +104,8 @@ function processSection(section) {
98104
content = result.updatedContent;
99105
const prs = result.prs;
100106

107+
content = capitalizeHeaders(content);
108+
101109
const date = title.match(/ \((?<date>.*)\)/)?.groups.date;
102110

103111
return {

src/plugins/changelog/theme/ChangelogList/Header/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export default function ChangelogListHeader({
5151
'Subscribe through {rssLink} to stay up-to-date with new releases!'
5252
}
5353
</Translate>
54+
<br/>
55+
<br/>
56+
<Link href="https://github.com/cloudposse/terraform-aws-components/blob/main/CHANGELOG.md">View on GitHub</Link>
5457
</p>
5558
</header>
5659
);

src/theme/MDXComponents/A.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import Link from '@docusaurus/Link';
3+
export default function MDXA(props) {
4+
return <Link {...props} />;
5+
}

src/theme/MDXComponents/Code.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, {isValidElement} from 'react';
2+
import CodeBlock from '@theme/CodeBlock';
3+
export default function MDXCode(props) {
4+
const inlineElements = [
5+
'a',
6+
'abbr',
7+
'b',
8+
'br',
9+
'button',
10+
'cite',
11+
'code',
12+
'del',
13+
'dfn',
14+
'em',
15+
'i',
16+
'img',
17+
'input',
18+
'ins',
19+
'kbd',
20+
'label',
21+
'object',
22+
'output',
23+
'q',
24+
'ruby',
25+
's',
26+
'small',
27+
'span',
28+
'strong',
29+
'sub',
30+
'sup',
31+
'time',
32+
'u',
33+
'var',
34+
'wbr',
35+
];
36+
const shouldBeInline = React.Children.toArray(props.children).every(
37+
(el) =>
38+
(typeof el === 'string' && !el.includes('\n')) ||
39+
(isValidElement(el) && inlineElements.includes(el.props?.mdxType)),
40+
);
41+
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
42+
}

src/theme/MDXComponents/Details.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import Details from '@theme/Details';
3+
import {useLocation} from '@docusaurus/router';
4+
5+
export default function MDXDetails(props) {
6+
const items = React.Children.toArray(props.children);
7+
// Split summary item from the rest to pass it as a separate prop to the
8+
// Details theme component
9+
const summary = items.find(
10+
(item) => React.isValidElement(item) && item.props?.mdxType === 'summary',
11+
);
12+
const children = <>{items.filter((item) => item !== summary)}</>;
13+
14+
// ugly hack starts
15+
// MDXComponents has been swizzled like this
16+
// npm run swizzle @docusaurus/theme-classic MDXComponents -- --eject
17+
//
18+
// we want ot open <details> tag for changelog pages but not for list changelogs page
19+
const location = useLocation();
20+
const endpointPattern = /components\/changelog\/\d+\.\d+\.\d+\/?$/;
21+
const open=endpointPattern.test(location.pathname);
22+
// ugly hack ends
23+
24+
return open ? (
25+
<Details {...props} summary={summary} open>
26+
{children}
27+
</Details>
28+
) : (
29+
<Details {...props} summary={summary}>
30+
{children}
31+
</Details>
32+
);
33+
}

src/theme/MDXComponents/Head.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import Head from '@docusaurus/Head';
3+
// MDX elements are wrapped through the MDX pragma. In some cases (notably usage
4+
// with Head/Helmet) we need to unwrap those elements.
5+
function unwrapMDXElement(element) {
6+
if (element.props?.mdxType && element.props.originalType) {
7+
const {mdxType, originalType, ...newProps} = element.props;
8+
return React.createElement(element.props.originalType, newProps);
9+
}
10+
return element;
11+
}
12+
export default function MDXHead(props) {
13+
const unwrappedChildren = React.Children.map(props.children, (child) =>
14+
React.isValidElement(child) ? unwrapMDXElement(child) : child,
15+
);
16+
return <Head {...props}>{unwrappedChildren}</Head>;
17+
}

src/theme/MDXComponents/Heading.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
import Heading from '@theme/Heading';
3+
export default function MDXHeading(props) {
4+
return <Heading {...props} />;
5+
}

src/theme/MDXComponents/Img/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import styles from './styles.module.css';
4+
function transformImgClassName(className) {
5+
return clsx(className, styles.img);
6+
}
7+
export default function MDXImg(props) {
8+
return (
9+
// eslint-disable-next-line jsx-a11y/alt-text
10+
<img
11+
loading="lazy"
12+
{...props}
13+
className={transformImgClassName(props.className)}
14+
/>
15+
);
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.img {
2+
height: auto;
3+
}

src/theme/MDXComponents/Pre.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, {isValidElement} from 'react';
2+
import CodeBlock from '@theme/CodeBlock';
3+
export default function MDXPre(props) {
4+
return (
5+
<CodeBlock
6+
// If this pre is created by a ``` fenced codeblock, unwrap the children
7+
{...(isValidElement(props.children) &&
8+
props.children.props?.originalType === 'code'
9+
? props.children.props
10+
: {...props})}
11+
/>
12+
);
13+
}

src/theme/MDXComponents/Ul/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import styles from './styles.module.css';
4+
function transformUlClassName(className) {
5+
return clsx(
6+
className,
7+
// This class is set globally by GitHub/MDX. We keep the global class, and
8+
// add another class to get a task list without the default ul styling
9+
// See https://github.com/syntax-tree/mdast-util-to-hast/issues/28
10+
className?.includes('contains-task-list') && styles.containsTaskList,
11+
);
12+
}
13+
export default function MDXUl(props) {
14+
return <ul {...props} className={transformUlClassName(props.className)} />;
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.containsTaskList {
2+
list-style: none;
3+
}
4+
5+
:not(.containsTaskList > li) > .containsTaskList {
6+
padding-left: 0;
7+
}

src/theme/MDXComponents/index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import MDXHead from '@theme/MDXComponents/Head';
3+
import MDXCode from '@theme/MDXComponents/Code';
4+
import MDXA from '@theme/MDXComponents/A';
5+
import MDXPre from '@theme/MDXComponents/Pre';
6+
import MDXDetails from '@theme/MDXComponents/Details';
7+
import MDXHeading from '@theme/MDXComponents/Heading';
8+
import MDXUl from '@theme/MDXComponents/Ul';
9+
import MDXImg from '@theme/MDXComponents/Img';
10+
import Admonition from '@theme/Admonition';
11+
import Mermaid from '@theme/Mermaid';
12+
const MDXComponents = {
13+
head: MDXHead,
14+
code: MDXCode,
15+
a: MDXA,
16+
pre: MDXPre,
17+
details: MDXDetails,
18+
ul: MDXUl,
19+
img: MDXImg,
20+
h1: (props) => <MDXHeading as="h1" {...props} />,
21+
h2: (props) => <MDXHeading as="h2" {...props} />,
22+
h3: (props) => <MDXHeading as="h3" {...props} />,
23+
h4: (props) => <MDXHeading as="h4" {...props} />,
24+
h5: (props) => <MDXHeading as="h5" {...props} />,
25+
h6: (props) => <MDXHeading as="h6" {...props} />,
26+
admonition: Admonition,
27+
mermaid: Mermaid,
28+
};
29+
export default MDXComponents;

0 commit comments

Comments
 (0)