Skip to content

Commit c4674f4

Browse files
juristrFrozenPandaz
authored andcommittedAug 1, 2024
fix(nx-dev): adjust scroll offset for headings on docs and blog container
(cherry picked from commit 90e29f0)
1 parent fd9f557 commit c4674f4

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed
 

‎nx-dev/feature-doc-viewer/src/lib/doc-viewer.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function DocViewer({
3737
document.content.toString(),
3838
{
3939
filePath: document.filePath,
40+
headingClass: 'scroll-mt-8',
4041
}
4142
);
4243

‎nx-dev/ui-blog/src/lib/blog-details.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function generateMetadata({ post }: BlogDetailsProps) {
3232
export function BlogDetails({ post }: BlogDetailsProps) {
3333
const { node } = renderMarkdown(post.content, {
3434
filePath: post.filePath ?? '',
35+
headingClass: 'scroll-mt-20',
3536
});
3637

3738
const formattedDate = new Date(post.date).toLocaleDateString('en-US', {

‎nx-dev/ui-markdoc/src/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { load as yamlLoad } from '@zkochan/js-yaml';
1010
import React, { ReactNode } from 'react';
1111
import { Heading } from './lib/nodes/heading.component';
12-
import { heading } from './lib/nodes/heading.schema';
12+
import { getHeadingSchema } from './lib/nodes/heading.schema';
1313
import { getImageSchema } from './lib/nodes/image.schema';
1414
import { CustomLink } from './lib/nodes/link.component';
1515
import { link } from './lib/nodes/link.schema';
@@ -63,12 +63,13 @@ import { VideoPlayer, videoPlayer } from './lib/tags/video-player.component';
6363
export { GithubRepository } from './lib/tags/github-repository.component';
6464

6565
export const getMarkdocCustomConfig = (
66-
documentFilePath: string
66+
documentFilePath: string,
67+
headingClass: string = ''
6768
): { config: any; components: any } => ({
6869
config: {
6970
nodes: {
7071
fence,
71-
heading,
72+
heading: getHeadingSchema(headingClass),
7273
image: getImageSchema(documentFilePath),
7374
link,
7475
},
@@ -156,14 +157,17 @@ export const extractFrontmatter = (
156157

157158
export const renderMarkdown: (
158159
documentContent: string,
159-
options: { filePath: string }
160+
options: { filePath: string; headingClass?: string }
160161
) => {
161162
metadata: Record<string, any>;
162163
node: ReactNode;
163164
treeNode: RenderableTreeNode;
164165
} = (documentContent, options = { filePath: '' }) => {
165166
const ast = parseMarkdown(documentContent);
166-
const configuration = getMarkdocCustomConfig(options.filePath);
167+
const configuration = getMarkdocCustomConfig(
168+
options.filePath,
169+
options.headingClass
170+
);
167171
const treeNode = transform(ast, configuration.config);
168172

169173
return {

‎nx-dev/ui-markdoc/src/lib/nodes/heading.schema.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function generateID(
4141
.replace(/\s+/g, '-');
4242
}
4343

44-
export const heading: Schema = {
44+
export const getHeadingSchema = (headingClass: string): Schema => ({
4545
render: 'Heading',
4646
children: ['inline'],
4747
attributes: {
@@ -58,8 +58,8 @@ export const heading: Schema = {
5858
return new Tag(
5959
this.render,
6060
// `h${node.attributes['level']}`,
61-
{ ...attributes, id },
61+
{ ...attributes, id, className: headingClass },
6262
children
6363
);
6464
},
65-
};
65+
});

0 commit comments

Comments
 (0)
Please sign in to comment.