Skip to content

Commit

Permalink
Fix search regression (#465)
Browse files Browse the repository at this point in the history
* Fix search regression

* Change “Blockquote” to “Callout” which is more semantically correct
  • Loading branch information
benface authored Aug 10, 2023
1 parent cce9e25 commit f4423c2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions algolia-crawler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ new Crawler({
selectors: '.graph-docs-current-group',
defaultValue: 'The Graph Docs',
},
lvl1: '.graph-docs-content h1 > span:first-of-type',
lvl2: '.graph-docs-content h2 > span:first-of-type',
lvl3: '.graph-docs-content h3 > span:first-of-type',
lvl4: '.graph-docs-content h4 > span:first-of-type',
lvl5: '.graph-docs-content h5 > span:first-of-type',
lvl6: '.graph-docs-content h6 > span:first-of-type',
lvl1: '.graph-docs-content h1',
lvl2: '.graph-docs-content h2',
lvl3: '.graph-docs-content h3',
lvl4: '.graph-docs-content h4',
lvl5: '.graph-docs-content h5',
lvl6: '.graph-docs-content h6',
content: '.graph-docs-content p, .graph-docs-content li',
},
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { BlockquoteHTMLAttributes } from 'react'

import { buildBorder, Spacing, Text, TextProps } from '@edgeandnode/gds'

export type BlockquoteProps = Omit<TextProps & BlockquoteHTMLAttributes<HTMLQuoteElement>, 'color'>
export type CalloutProps = Omit<TextProps, 'color'>

export const Blockquote = ({ children, ...props }: BlockquoteProps) => {
export const Callout = ({ children, ...props }: CalloutProps) => {
return (
<Text
as="blockquote"
sx={{
my: Spacing['32px'],
'/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ &:nth-child(1 of :not(style))':
Expand Down
17 changes: 11 additions & 6 deletions packages/nextra-theme/src/components/Heading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as VisuallyHidden from '@radix-ui/react-visually-hidden'
import { HTMLAttributes, useContext } from 'react'
import { ElementType, useContext } from 'react'
import { useInView } from 'react-intersection-observer'
import { useDebounce } from 'react-use'

Expand All @@ -10,13 +10,15 @@ import { DocumentContext } from '@/layout/DocumentContext'

export type HeadingProps = TextProps & {
level: 1 | 2 | 3 | 4 | 5 | 6
} & HTMLAttributes<HTMLHeadingElement>
}

const BaseHeading = ({ level, id, children, ...props }: HeadingProps) => {
const { markOutlineItem } = useContext(DocumentContext)!

const { ref, inView: inOrAboveView } = useInView({
rootMargin: '99999px 0px -90% 0px', // consider it "in or above view" if it's anywhere above 10% from the top of the viewport
rootMargin: '99999px 0px -80% 0px', // consider it "in or above view" if it's anywhere above 20% from the top of the viewport
})

useDebounce(
() => {
if (id) {
Expand All @@ -26,17 +28,20 @@ const BaseHeading = ({ level, id, children, ...props }: HeadingProps) => {
100,
[id, inOrAboveView, markOutlineItem],
)

const Heading: ElementType = `h${level}`

const { t } = useI18n<any>()

return (
<Text ref={ref} as={`h${level}`} id={id} weight="SEMIBOLD" color="White" {...props}>
{children}
<Text ref={ref} id={id} weight="SEMIBOLD" color="White" {...props}>
<Heading sx={{ display: 'inline' }}>{children}</Heading>
{id ? (
<span
sx={{
marginInlineStart: '0.35em',
opacity: Opacity['0%'],
[`h${level}:hover &, &:focus-within`]: { opacity: Opacity['100%'] },
[`*:hover > &, &:focus-within`]: { opacity: Opacity['100%'] },
transition: buildTransition('OPACITY'),
}}
>
Expand Down
4 changes: 1 addition & 3 deletions packages/nextra-theme/src/components/Paragraph.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { HTMLAttributes } from 'react'

import { Spacing, Text, TextProps } from '@edgeandnode/gds'

export type ParagraphProps = Omit<TextProps & HTMLAttributes<HTMLParagraphElement>, 'color'>
export type ParagraphProps = Omit<TextProps, 'color'>

export const Paragraph = ({ children, ...props }: ParagraphProps) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/nextra-theme/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './Blockquote'
export * from './Callout'
export * from './Code'
export * from './Difficulty'
export * from './DocSearch'
Expand Down
4 changes: 2 additions & 2 deletions packages/nextra-theme/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Divider, DividerProps, Flex, Icon, Spacing, useI18n } from '@edgeandnod
import { NPSForm } from '@edgeandnode/organisms'

import {
Blockquote,
Callout,
CodeBlock,
CodeInline,
Difficulty,
Expand All @@ -30,7 +30,7 @@ import {
import { DocumentContext, MDXLayoutNav, MDXLayoutOutline, MDXLayoutPagination, NavContext } from '@/layout'

const mdxComponents = {
blockquote: Blockquote,
blockquote: Callout,
pre: CodeBlock,
code: CodeInline,
hr: (props: DividerProps) => <Divider sx={{ my: Spacing['32px'] }} {...props} />,
Expand Down

0 comments on commit f4423c2

Please sign in to comment.