Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified HTML for Algolia Crawler #5441

Merged
merged 1 commit into from
May 16, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactNode } from 'react';
import styled from '@emotion/styled';

import { Theme } from '@/app/_components/ui/theme/theme';
import { wrapHeadingsWithAnchor } from '@/shared-utils/wrapHeadingsWithAnchor';

const StyledContent = styled.div`
flex: 1;
Expand All @@ -27,6 +28,10 @@ const StyledContent = styled.div`
font-family: var(--font-gabarito);
color: ${Theme.text.color.primary};
font-weight: 700;
a {
text-decoration: none;
color: ${Theme.text.color.primary};
}
}

h1 {
Expand Down Expand Up @@ -89,5 +94,5 @@ const StyledContent = styled.div`
`;

export const ArticleContent = ({ children }: { children: ReactNode }) => {
return <StyledContent>{children}</StyledContent>;
return <StyledContent>{wrapHeadingsWithAnchor(children)}</StyledContent>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ const StyledHeader = styled.div`
}
`;

const StyledHeading = styled.div`
const StyledHeading = styled.h1`
font-size: 40px;
font-weight: 700;
font-family: var(--font-gabarito);
margin: 0px;
@media (max-width: 800px) {
font-size: 28px;
}
Expand All @@ -77,12 +78,13 @@ const StyledHeaderInfoSectionTitle = styled.div`
font-family: var(--font-gabarito);
`;

const StyledHeaderInfoSectionSub = styled.div`
const StyledHeaderInfoSectionSub = styled.p`
display: flex;
flex-direction: column;
gap: ${Theme.spacing(4)};
color: ${Theme.text.color.tertiary};
line-height: 1.8;
margin: 0px;
`;

const StyledRectangle = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const StyledTitle = styled.div`
font-weight: 600;
`;

const StyledSubTopicItem = styled.div<{ isselected: boolean }>`
const StyledSubTopicItem = styled.a<{ isselected: boolean }>`
cursor: pointer;
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -135,6 +135,7 @@ const UserGuideSidebarSection = ({
<StyledSubTopicItem
key={card.title}
isselected={isselected}
href={`/user-guide/${card.fileName}`}
onClick={() => router.push(`/user-guide/${card.fileName}`)}
onMouseEnter={() => setHoveredItem(card.title)}
onMouseLeave={() => setHoveredItem(null)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {
Children,
cloneElement,
isValidElement,
ReactElement,
ReactNode,
} from 'react';

export const wrapHeadingsWithAnchor = (children: ReactNode): ReactNode => {
const hasChildren = (
element: ReactElement,
): element is ReactElement<{ children: ReactNode }> => {
return element.props.children !== undefined;
};

return Children.map(children, (child) => {
if (
isValidElement(child) &&
typeof child.type === 'string' &&
['h1', 'h2', 'h3', 'h4'].includes(child.type)
) {
const id = child.props.children
.toString()
.replace(/\s+/g, '-')
.toLowerCase();
return cloneElement(child as ReactElement<any>, {
id: id,
children: <a href={`#${id}`}>{child.props.children}</a>,
});
}

if (isValidElement(child) && hasChildren(child)) {
return cloneElement(child, {
children: wrapHeadingsWithAnchor(child.props.children),
});
}

return child;
});
};
Loading