javascript - 阻止特定域路径中的 Gatsby 页面出现在 Google 搜索中
问题描述
是否可以阻止特定域路径中的 Gatsby 页面出现在 Google 搜索中。
我不想阻止整个网站出现在 Google 搜索中,只是在特定路径中存在一个页面。例如www.mywebsite.co.uk/hide-me
解决方案
使用该<Helmet>
组件设置机器人的meta
标签。
const HideMe = ()=>{
return <>
<Helmet>
<meta name={`robots`} content={`noindex, nofollow`} />
</Helmet>;
<h1>I'm the Hide Me page </h1>
</>;
大多数 Gatsby 启动器都带有一个SEO
组件,其中包含 robotsmeta
标记等,如果是这种情况,您可能需要为每个传递正确prop
. 例如:
const SEO = ({ index, follow, description, lang, meta, title }) => {
const { site } = useStaticQuery(graphql`
query getAllMetadata {
site {
siteMetadata {
title
description
author
}
}
}
`,
);
const metaDescription = description ?? site.siteMetadata.description;
return <Helmet htmlAttributes={{ lang }} title={title} titleTemplate={`%s | ${site.siteMetadata.title}`}>
<meta name={`robots`} content={`${index ? `index`:`noindex`},${follow ? `follow`:`nofollow`}`}/>
<meta name={`description`} content={metaDescription}/>
<meta name={`og:title`} content={title}/>
<meta name={`og:description`} content={metaDescription}/>
<meta name={`og:type`} content={`website`}/>
<meta name={`twitter:card`} content={`summary`}/>
<meta name={`twitter:creator`} content={site.siteMetadata.author}/>
<meta name={`twitter:title`} content={title}/>
<meta name={`twitter:description`} content={metaDescription}/>
</Helmet>;
};
注意:我假设两者都是index
布尔follow
值,但可以根据需要自定义它或者更适合你的任何东西
如果这是您的情况,在您的/hide-me
页面中,您将有类似的内容:
const HideMe = ()=>{
return <>
<SEO index={false} follow={false} />
<h1>I'm the Hide Me page </h1>
</>;
rel
此外,您需要将属性添加到指向该页面的所有链接,nofollow
以避免被 Google 的爬虫跟踪。
<Link rel={`nofollow`} to={`/hide-me`}>Untracked link</Link>
此外,您可能还想从(如果有的话)文件中删除该页面,您可以使用带有规则sitemap.xml
的站点地图插件之一轻松实现它。gatsby-plugin-sitemap
exclude
推荐阅读
- .net-core - 如何使用 Angular 部署 .NET Core 应用程序
- python - 有没有办法使用 python 将 Windows 鼠标光标更改为自定义光标?
- ios - KeyboardAvoidingView 在 IOS 上无法按预期工作
- python-3.x - 如何合并重复列值的行
- django - 如何在 django 中创建字典?
- swift - 如何在 macOS 上以编程方式在 Swift 中添加 NSView
- php - 如何将自定义模块的任务添加到 Calendar SuiteCRM
- php - 在 PHP 中访问多维数组
- compilation - 我需要为另一个处理器弧重新编译吗?
- javascript - 在选择选项中显示值而不是文本