feat: prevent search engines from indexing Discover feed content as page descriptions
This commit is contained in:
@@ -29,6 +29,7 @@ import {FAB} from '../util/fab/FAB'
|
||||
import {type ListMethods} from '../util/List'
|
||||
import {LoadLatestBtn} from '../util/load-latest/LoadLatestBtn'
|
||||
import {MainScrollProvider} from '../util/MainScrollProvider'
|
||||
import {NoSnippetWrapper} from '../util/NoSnippetWrapper'
|
||||
|
||||
const POLL_FREQ = 60e3 // 60sec
|
||||
|
||||
@@ -132,7 +133,8 @@ export function FeedPage({
|
||||
|
||||
const shouldPrefetch = isNative && isPageAdjacent
|
||||
return (
|
||||
<View testID={testID} {...(isDiscoverFeed && {'data-nosnippet': true})}>
|
||||
<NoSnippetWrapper enabled={isDiscoverFeed}>
|
||||
<View testID={testID}>
|
||||
<MainScrollProvider>
|
||||
<FeedFeedbackProvider value={feedFeedback}>
|
||||
<PostFeed
|
||||
@@ -167,10 +169,13 @@ export function FeedPage({
|
||||
onPress={onPressCompose}
|
||||
icon={<ComposeIcon2 strokeWidth={1.5} size={29} style={s.white} />}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={_(msg({message: `New post`, context: 'action'}))}
|
||||
accessibilityLabel={_(
|
||||
msg({message: `New post`, context: 'action'}),
|
||||
)}
|
||||
accessibilityHint=""
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</NoSnippetWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import {type ViewProps} from 'react-native'
|
||||
// @ts-expect-error untyped
|
||||
import {unstable_createElement} from 'react-native-web'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
|
||||
interface Props extends ViewProps {
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* NoSnippetWrapper prevents search engines from displaying snippets of its content.
|
||||
*
|
||||
* If running on web and enabled, wraps children in a <div> with data-nosnippet attribute.
|
||||
* Otherwise, renders children directly.
|
||||
*
|
||||
* @param enabled - Whether to apply the data-nosnippet attribute.
|
||||
* @param viewProps - Additional props for the wrapper element.
|
||||
*/
|
||||
export function NoSnippetWrapper({enabled, ...viewProps}: Props) {
|
||||
if (isWeb && enabled) {
|
||||
return unstable_createElement('div', {
|
||||
...viewProps,
|
||||
'data-nosnippet': '',
|
||||
})
|
||||
}
|
||||
|
||||
return <>{viewProps.children}</>
|
||||
}
|
||||
Reference in New Issue
Block a user