Skip to content

Commit 93982ba

Browse files
Add Introduction entry to table of contents (#223)
* Add Introduction entry to table of contents * Update local visual-regression snapshots * Update Playwright baseline screenshots (Linux) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent f23e33c commit 93982ba

17 files changed

Lines changed: 22 additions & 13 deletions

File tree

src/components/markdown-renderer/styles.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Paragraph } from 'components/paragraph/Paragraph';
22
import styled, { DefaultTheme } from 'styled-components';
33
import breakpoint from 'styled-components-breakpoint';
4-
import { mb, mt, ml, pb } from 'styled-components-spacing';
4+
import { mb, mt, ml, pb, my } from 'styled-components-spacing';
55
import { Heading } from '../heading/Heading';
66
import { Link } from '../link/Link';
77

@@ -51,8 +51,8 @@ export const OrderedList = styled.ol`
5151

5252
// Fixes for gatsby span wrapper
5353
export const Span = styled.span`
54-
&.gatsby-resp-image-wrapper {
55-
margin: 0 !important;
54+
& > .gatsby-resp-image-wrapper {
55+
${my(5)};
5656
}
5757
`;
5858

src/components/table-of-contents/TableOfContents.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ const TocItems = ({
2626
onClick={(e) => {
2727
e.preventDefault();
2828
onClickItem?.();
29-
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
29+
if (id === 'introduction') {
30+
window.scrollTo({ top: 0, behavior: 'smooth' });
31+
} else {
32+
document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' });
33+
}
3034
}}
3135
>
3236
{text}

src/hooks/useTableOfContents.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ const useTableOfContents = () => {
99

1010
useEffect(() => {
1111
const els = Array.from(
12-
document.querySelectorAll<HTMLElement>('h2[id], h3[id]')
12+
document.querySelectorAll<HTMLElement>('[id="introduction"], h2[id], h3[id]')
1313
);
1414

1515
setHeadings(
16-
els.map((el) => ({
17-
id: el.id,
18-
text: el.textContent ?? '',
19-
level: el.tagName === 'H2' ? 2 : 3,
20-
}))
16+
els.map((el) => {
17+
if (el.id === 'introduction') {
18+
return { id: 'introduction', text: 'Introduction', level: 2 as const };
19+
}
20+
return {
21+
id: el.id,
22+
text: el.textContent ?? '',
23+
level: el.tagName === 'H2' ? 2 : (3 as const),
24+
};
25+
})
2126
);
2227

2328
const INITIAL_TOP = 320; // 20rem
@@ -31,7 +36,7 @@ const useTableOfContents = () => {
3136
// headings, making the captured `els` reference stale detached nodes
3237
// whose getBoundingClientRect() returns all zeros.
3338
const liveEls = Array.from(
34-
document.querySelectorAll<HTMLElement>('h2[id], h3[id]')
39+
document.querySelectorAll<HTMLElement>('[id="introduction"], h2[id], h3[id]')
3540
);
3641
let currentId = liveEls[0]?.id ?? '';
3742
for (const el of liveEls) {

src/posts/nestjs-aws-lambda-cdk-deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ By the end of this guide, you’ll have:
2929
- Infrastructure defined as code: a Lambda function, HTTP API Gateway, provisioned with AWS CDK
3030
- A GitHub Actions workflow that builds and deploys your stack automatically on every push to `main`
3131

32-
### ![Simple artchitecture diagram of NestJS deployment in AWS Lambda](../images/nestjs-aws-serverless/nestjs-serverless-lambda-simple-diagram.png)
32+
![Simple artchitecture diagram of NestJS deployment in AWS Lambda](../images/nestjs-aws-serverless/nestjs-serverless-lambda-simple-diagram.png)
3333

3434
The complete source code is available on [GitHub](https://github.com/ajeetchaulagain/nestjs-serverless-aws-lambda-cdk).
3535

src/templates/BlogPage/BlogPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const BlogTemplate: React.FC<PageProps<DataProps, PageContextProps>> = (
9494
/>
9595
<HeroBlank />
9696
<ContentRenderer>
97-
<PostHeaderContainer>
97+
<PostHeaderContainer id="introduction">
9898
<PostHeaderLeftColumn>
9999
<Heading size="xlarge">{title}</Heading>
100100

4.24 KB
Loading
4.09 KB
Loading
792 Bytes
Loading
1.21 KB
Loading
-435 Bytes
Loading

0 commit comments

Comments
 (0)