-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add search #8
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a079ae
feat: add breadcumbs
rsbh 5cd178a
feat: add search api
rsbh bf2048f
feat: add search component
rsbh 26414fd
fix: breadcrumb folder link
rsbh 7937c07
fix: pr comments
rsbh aad8ab4
fix: pr comments
rsbh c9b49a3
fix: pr comments
rsbh af48505
fix: hydration warning
rsbh d984f35
feat: add footer component
rsbh 5760f9e
fix: use current working dir for config
rsbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { source } from '../../../lib/source' | ||
| import { createSearchAPI, type AdvancedIndex } from 'fumadocs-core/search/server' | ||
| import type { StructuredData } from 'fumadocs-core/mdx-plugins' | ||
|
|
||
| interface PageData { | ||
| title?: string | ||
| description?: string | ||
| structuredData?: StructuredData | ||
| load?: () => Promise<{ structuredData?: StructuredData }> | ||
| } | ||
|
|
||
| export const { GET } = createSearchAPI('advanced', { | ||
| indexes: async (): Promise<AdvancedIndex[]> => { | ||
| const pages = source.getPages() | ||
| const indexes = await Promise.all( | ||
| pages.map(async (page): Promise<AdvancedIndex> => { | ||
| const data = page.data as PageData | ||
| let structuredData: StructuredData | undefined = data.structuredData | ||
|
|
||
| if (!structuredData && data.load) { | ||
| try { | ||
| const loaded = await data.load() | ||
| structuredData = loaded.structuredData | ||
| } catch (error) { | ||
| console.error(`Failed to load structured data for ${page.url}:`, error) | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| id: page.url, | ||
| url: page.url, | ||
| title: data.title ?? '', | ||
| description: data.description ?? '', | ||
| structuredData: structuredData ?? { headings: [], contents: [] }, | ||
| } | ||
| }) | ||
| ) | ||
| return indexes | ||
| }, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| 'use client' | ||
|
|
||
| import { Breadcrumb } from '@raystack/apsara' | ||
| import type { PageTree, PageTreeItem } from '../../types' | ||
|
|
||
| interface BreadcrumbsProps { | ||
| slug: string[] | ||
| tree: PageTree | ||
| } | ||
|
|
||
| function findInTree(items: PageTreeItem[], targetPath: string): PageTreeItem | undefined { | ||
| for (const item of items) { | ||
| const itemUrl = item.url || `/${item.name.toLowerCase().replace(/\s+/g, '-')}` | ||
| if (itemUrl === targetPath || itemUrl === `/${targetPath}`) { | ||
| return item | ||
| } | ||
| if (item.children) { | ||
| const found = findInTree(item.children, targetPath) | ||
| if (found) return found | ||
| } | ||
| } | ||
| return undefined | ||
| } | ||
|
|
||
| function getFirstPageUrl(item: PageTreeItem): string | undefined { | ||
| if (item.type === 'page' && item.url) { | ||
| return item.url | ||
| } | ||
| if (item.children) { | ||
| for (const child of item.children) { | ||
| const url = getFirstPageUrl(child) | ||
| if (url) return url | ||
| } | ||
| } | ||
| return undefined | ||
| } | ||
|
|
||
| export function Breadcrumbs({ slug, tree }: BreadcrumbsProps) { | ||
| const items: { label: string; href: string }[] = [] | ||
|
|
||
| for (let i = 0; i < slug.length; i++) { | ||
| const currentPath = `/${slug.slice(0, i + 1).join('/')}` | ||
| const node = findInTree(tree.children, currentPath) | ||
| const href = node?.url || (node && getFirstPageUrl(node)) || currentPath | ||
| const label = node?.name ?? slug[i] | ||
| items.push({ | ||
| label: label.charAt(0).toUpperCase() + label.slice(1), | ||
| href, | ||
| }) | ||
| } | ||
|
|
||
| return ( | ||
| <Breadcrumb size="small"> | ||
| {items.flatMap((item, index) => { | ||
| const breadcrumbItem = ( | ||
| <Breadcrumb.Item | ||
| key={`item-${index}`} | ||
| href={item.href} | ||
| current={index === items.length - 1} | ||
| > | ||
| {item.label} | ||
| </Breadcrumb.Item> | ||
| ) | ||
| if (index === 0) return [breadcrumbItem] | ||
| return [ | ||
| <Breadcrumb.Separator key={`sep-${index}`} style={{ display: 'flex' }} />, | ||
| breadcrumbItem, | ||
| ] | ||
| })} | ||
| </Breadcrumb> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| .footer { | ||
| border-top: 1px solid var(--rs-color-border-base-primary); | ||
| padding: var(--rs-space-5) var(--rs-space-7); | ||
| } | ||
|
|
||
| .container { | ||
| max-width: 1200px; | ||
| margin: 0 auto; | ||
| width: 100%; | ||
| } | ||
|
|
||
| .copyright { | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| } | ||
|
|
||
| .links { | ||
| flex-wrap: wrap; | ||
| } | ||
|
|
||
| .link { | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .link:hover { | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { Flex, Link, Text } from "@raystack/apsara"; | ||
| import type { FooterConfig } from "../../types"; | ||
| import styles from "./footer.module.css"; | ||
|
|
||
| interface FooterProps { | ||
| config?: FooterConfig; | ||
| } | ||
|
|
||
| export function Footer({ config }: FooterProps) { | ||
| return ( | ||
| <footer className={styles.footer}> | ||
| <Flex align="center" justify="between" className={styles.container}> | ||
| {config?.copyright && ( | ||
| <Text size={2} className={styles.copyright}> | ||
| {config.copyright} | ||
| </Text> | ||
| )} | ||
| {config?.links && config.links.length > 0 && ( | ||
| <Flex gap="medium" className={styles.links}> | ||
| {config.links.map((link) => ( | ||
| <Link key={link.href} href={link.href} className={styles.link}> | ||
| {link.label} | ||
| </Link> | ||
| ))} | ||
| </Flex> | ||
| )} | ||
| </Flex> | ||
| </footer> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| .trigger { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| padding: 6px 12px; | ||
| border-radius: 6px; | ||
| border: 1px solid var(--rs-color-border-base-primary); | ||
| background: transparent; | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| font-size: 14px; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .kbd { | ||
| padding: 2px 6px; | ||
| border-radius: 4px; | ||
| border: 1px solid var(--rs-color-border-base-primary); | ||
| font-size: 12px; | ||
| } | ||
|
|
||
| .dialogContent { | ||
| max-width: 600px; | ||
| padding: 0; | ||
| min-height: 0; | ||
| position: fixed; | ||
| top: 20%; | ||
| left: 50%; | ||
| transform: translateX(-50%); | ||
| border-radius: var(--rs-radius-4); | ||
| } | ||
|
|
||
| .input { | ||
| flex: 1; | ||
| border: none; | ||
| outline: none; | ||
| background: transparent; | ||
| font-size: 16px; | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .list { | ||
| max-height: 300px; | ||
| overflow: auto; | ||
| padding: 0; | ||
| } | ||
|
|
||
| .visuallyHidden { | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| margin: -1px; | ||
| overflow: hidden; | ||
| clip: rect(0, 0, 0, 0); | ||
| white-space: nowrap; | ||
| border: 0; | ||
| } | ||
|
|
||
| .item { | ||
| padding: 12px 16px; | ||
| cursor: pointer; | ||
| border-radius: 6px; | ||
| } | ||
|
|
||
| .item[data-selected="true"] { | ||
| background: var(--rs-color-background-base-secondary); | ||
| color: var(--rs-color-foreground-accent-primary-hover); | ||
| } | ||
|
|
||
| .itemContent { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 12px; | ||
| } | ||
|
|
||
| .resultText { | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| } | ||
|
|
||
| .headingText { | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| } | ||
|
|
||
| .item[data-selected="true"] .headingText { | ||
| color: var(--rs-color-foreground-accent-primary-hover); | ||
| } | ||
|
|
||
| .separator { | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| } | ||
|
|
||
| .pageText { | ||
| color: var(--rs-color-foreground-base-primary); | ||
| } | ||
|
|
||
| .item[data-selected="true"] .pageText { | ||
| color: var(--rs-color-foreground-accent-primary-hover); | ||
| } | ||
|
|
||
| .icon { | ||
| width: 18px; | ||
| height: 18px; | ||
| color: var(--rs-color-foreground-base-secondary); | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .item[data-selected="true"] .icon { | ||
| color: var(--rs-color-foreground-accent-primary-hover); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.