Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/nice-ravens-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"gitbook-docs": minor
"nextjs-website": minor
---

Fix chat message parsing and update markdown parsing
43 changes: 36 additions & 7 deletions apps/nextjs-website/src/helpers/chatMessageParser.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import ChatLink from '@/components/atoms/ChatLink/ChatLink';
import Markdoc, { Config, ConfigType, Node } from '@markdoc/markdoc';
import Markdoc, { Config, ConfigType, Node, Tag } from '@markdoc/markdoc';
import React, { ReactNode } from 'react';

import { PageTitlePath } from '@/helpers/parseS3Doc.helpers';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { PageTitlePath } from '@/helpers/parseS3Doc.helpers';
import { PageTitlePath } from '@/helpers/parseS3Doc.helpers';

const capitalizeFirstLetter = (text: string): string =>
text.charAt(0).toUpperCase() + text.slice(1);
const chatMarkdocConfig: ConfigType = {
nodes: {
link: {
Expand All @@ -12,12 +14,39 @@ const chatMarkdocConfig: ConfigType = {
title: { type: String },
},
transform(node: Node, config: Config) {
const attributes = node.transformAttributes(config);
return new Markdoc.Tag(
'Link',
attributes,
node.transformChildren(config)
const attrs = node.transformAttributes(config);
const gitBookPagesWithTitle: ReadonlyArray<PageTitlePath> =
config.variables ? [...config.variables.gitBookPagesWithTitle] : [];
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spread operator creates a new array unnecessarily. Since you're only reading from the array, you can use it directly: config.variables?.gitBookPagesWithTitle || []

Suggested change
config.variables ? [...config.variables.gitBookPagesWithTitle] : [];
config.variables?.gitBookPagesWithTitle || [];

Copilot uses AI. Check for mistakes.

const page = gitBookPagesWithTitle.find(
({ path }) => path === attrs.href
);

const childrenTreeNode = node.transformChildren(config);

const titleFromPage =
childrenTreeNode &&
typeof childrenTreeNode[0] === 'string' &&
childrenTreeNode[0].endsWith('.md') &&
page
? page.title
: undefined;
Comment on lines +26 to +32
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This complex conditional logic should be extracted into a helper function for better readability and testability. Consider creating a getTitleFromPage function.

Copilot uses AI. Check for mistakes.


const titleFromAnchor =
childrenTreeNode &&
typeof childrenTreeNode[0] === 'string' &&
childrenTreeNode[0].startsWith('#')
? capitalizeFirstLetter(
childrenTreeNode[0].replace('#', '').replaceAll('-', ' ')
)
: undefined;
Comment on lines +34 to +41
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Similar to the previous comment, this conditional logic should also be extracted into a helper function like getTitleFromAnchor for consistency and maintainability.

Copilot uses AI. Check for mistakes.


const children = titleFromPage
? [titleFromPage]
: titleFromAnchor
? [titleFromAnchor]
: childrenTreeNode;

return new Tag('Link', attrs, children);
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function recursiveParseMarkdownFiles(
guideMetadata,
metadata,
fullPath
);
).replaceAll('\\', '');
try {
fs.writeFileSync(fullPath, urlParsedFileContent, 'utf8');
} catch (error) {
Expand Down