Skip to content

Commit c8fa0d6

Browse files
add logic to add pagefind weight for pages and tags (heading, paragraph, connectorDetailsHeader)
1 parent e50086e commit c8fa0d6

File tree

14 files changed

+118
-13
lines changed

14 files changed

+118
-13
lines changed

components/ConnectorDetailsHeader/ConnectorDetailsHeader.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface ConnectorDetailsHeaderProps {
44
platform: string;
55
availableFeatures: Array<string>;
66
unavailableFeatures: Array<string>;
7+
searchWeight: string;
78
}

components/ConnectorDetailsHeader/ConnectorDetailsHeader.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,29 @@ function ConnectorDetailsHeader({
1717
platform,
1818
availableFeatures,
1919
unavailableFeatures,
20+
searchWeight,
2021
}: Readonly<ConnectorDetailsHeaderProps>) {
2122
const showSubHeading = useMemo(
2223
() => !isEmpty(availableFeatures) || !isEmpty(unavailableFeatures),
2324
[availableFeatures, unavailableFeatures]
2425
);
2526

27+
let otherProps = {};
28+
29+
if (searchWeight) {
30+
otherProps = {
31+
["data-pagefind-weight"]: searchWeight,
32+
};
33+
}
34+
2635
return (
2736
<div className={styles.Container}>
2837
<div className={styles.Heading}>
2938
<div className="flex items-center gap-3">
3039
<div className={styles.ImageContainer}>{getConnectorImage(name)}</div>
31-
<div className={styles.ConnectorName}>{name}</div>
40+
<div className={styles.ConnectorName} {...otherProps}>
41+
{name}
42+
</div>
3243
{getStageBadge(stage)}
3344
</div>
3445
<div className={styles.PlatformDetails}>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ReactNode } from "react";
2+
3+
export interface HeadingProps {
4+
children: ReactNode;
5+
id?: string;
6+
level?: number;
7+
className?: string;
8+
searchWeight?: string;
9+
}

components/Heading/Heading.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import classNames from "classnames";
22
import { useState } from "react";
3+
import { HeadingProps } from "./Heading.interface";
34
import styles from "./Heading.module.css";
45
import HeadingElement from "./HeadingElement";
56

6-
export function Heading({ id = "", level = 1, children, className }) {
7+
export function Heading({
8+
id = "",
9+
level = 1,
10+
children,
11+
className = "",
12+
searchWeight,
13+
}: Readonly<HeadingProps>) {
714
const [copied, setCopied] = useState(false);
815

916
const copyLinkUnbound = async () => {
@@ -14,14 +21,26 @@ export function Heading({ id = "", level = 1, children, className }) {
1421
window.setTimeout(() => setCopied(false), 2000);
1522
};
1623

24+
let otherProps = {};
25+
26+
if (searchWeight) {
27+
otherProps = {
28+
["data-pagefind-weight"]: searchWeight,
29+
};
30+
}
31+
1732
return (
1833
<div
1934
className={classNames(className, styles.HeaderLink, {
2035
[styles.H1Element]: level === 1,
2136
})}
2237
>
2338
<a id={id} className={styles.HashLink} />
24-
<HeadingElement className={styles.HeaderElement} level={level}>
39+
<HeadingElement
40+
className={styles.HeaderElement}
41+
level={level}
42+
{...otherProps}
43+
>
2544
{children}
2645
</HeadingElement>
2746
{copied ? (

components/Heading/HeadingElement.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,50 @@ export default function HeadingElement({
88
level,
99
className = "",
1010
children,
11-
}: Props) {
11+
...otherProps
12+
}: Readonly<Props>) {
1213
switch (level) {
1314
case 1:
14-
return <h1 className={className}>{children}</h1>;
15+
return (
16+
<h1 className={className} {...otherProps}>
17+
{children}
18+
</h1>
19+
);
1520
case 2:
16-
return <h2 className={className}>{children}</h2>;
21+
return (
22+
<h2 className={className} {...otherProps}>
23+
{children}
24+
</h2>
25+
);
1726
case 3:
18-
return <h3 className={className}>{children}</h3>;
27+
return (
28+
<h3 className={className} {...otherProps}>
29+
{children}
30+
</h3>
31+
);
1932
case 4:
20-
return <h4 className={className}>{children}</h4>;
33+
return (
34+
<h4 className={className} {...otherProps}>
35+
{children}
36+
</h4>
37+
);
2138
case 5:
22-
return <h5 className={className}>{children}</h5>;
39+
return (
40+
<h5 className={className} {...otherProps}>
41+
{children}
42+
</h5>
43+
);
2344
case 6:
24-
return <h6 className={className}>{children}</h6>;
45+
return (
46+
<h6 className={className} {...otherProps}>
47+
{children}
48+
</h6>
49+
);
2550
default:
26-
return <h6 className={className}>{children}</h6>;
51+
return (
52+
<h6 className={className} {...otherProps}>
53+
{children}
54+
</h6>
55+
);
2756
}
2857
}

components/Search/Search.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ export default function Search({
149149
setIsLoading(true);
150150
if (window[`pageFind${docVersion}`]) {
151151
const search = await window[`pageFind${docVersion}`].search(
152-
isEmpty(searchValue) ? "releases" : searchValue
152+
// To show results for "releases" as a default suggestions when no search text is present
153+
isEmpty(searchValue) ? "releases" : searchValue,
154+
{ sort: { weight: "desc" } }
153155
);
154156

155157
// Select only top 20 results
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { ReactNode } from "react";
2+
3+
export interface ParagraphProps {
4+
children: ReactNode;
5+
searchWeight?: string;
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ParagraphProps } from "./Paragraph.interface";
2+
3+
function Paragraph({ searchWeight, children }: ParagraphProps) {
4+
let otherProps = {};
5+
6+
if (searchWeight) {
7+
otherProps = {
8+
["data-pagefind-weight"]: searchWeight,
9+
};
10+
}
11+
return <p {...otherProps}>{children}</p>;
12+
}
13+
14+
export default Paragraph;

lib/markdoc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Image from "../components/common/Image/Image";
2626
import InlineCallout from "../components/common/InlineCallout/InlineCallout";
2727
import InlineCalloutContainer from "../components/common/InlineCallout/InlineCalloutContainer";
2828
import Note from "../components/common/Note/Note";
29+
import Paragraph from "../components/common/Paragraph/Paragraph";
2930
import MultiTablesWrapper from "../components/common/Table/MultiTablesWrapper";
3031
import Table from "../components/common/Table/Table";
3132
import Tile from "../components/common/Tiles/Tile/Tile";
@@ -51,6 +52,7 @@ export const components = {
5152
CodePreview,
5253
Code,
5354
Heading,
55+
Paragraph,
5456
Image,
5557
Step,
5658
StepsContainer,

markdoc/nodes/heading.markdoc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const heading = {
3838
level: { type: Number, required: true, default: 1 },
3939
className: { type: String },
4040
children: { type: String },
41+
searchWeight: { type: String },
4142
},
4243
transform(node, config) {
4344
const attributes = node.transformAttributes(config);

0 commit comments

Comments
 (0)