Skip to content

Commit b6343b4

Browse files
authored
Merge pull request #8589 from sagemathinc/unlist-proxied-share-pages-8587
next/share: insert noindex and nofollow meta tags for github, gist and unlisted pages
2 parents 4ada777 + 56c37c8 commit b6343b4

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/packages/next/lib/share/proxy/get-public-path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ export default async function getProxyPublicPath({
115115

116116
const now = new Date();
117117
await pool.query(
118-
"INSERT INTO public_paths (id, url, project_id, path, description, last_edited, last_saved, created) VALUES($1, $2, $3, $4, $5, $6, $7, $8)",
119-
[id, publicPathUrl, project_id, path, description, now, now, now],
118+
"INSERT INTO public_paths (id, url, project_id, path, description, last_edited, last_saved, created, unlisted) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
119+
[id, publicPathUrl, project_id, path, description, now, now, now, true],
120120
);
121121
return {
122122
id,

src/packages/next/pages/share/public_paths/[...id].tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,30 @@ export default (props: PublicPathProps) => (
1919
<>
2020
<PublicPath {...props} />
2121
<NextHead>
22-
<meta property="og:type" content="article"/>
23-
<meta property="og:title" content={props.path}/>
22+
<meta property="og:type" content="article" />
23+
<meta property="og:title" content={props.path} />
2424

2525
{props.description && (
26-
<meta property="og:description" content={props.description}/>
27-
)}
28-
{props.ogUrl && (
29-
<meta property="og:url" content={props.ogUrl}/>
30-
)}
31-
{props.ogImage && (
32-
<meta property="og:image" content={props.ogImage}/>
26+
<meta property="og:description" content={props.description} />
3327
)}
28+
{props.ogUrl && <meta property="og:url" content={props.ogUrl} />}
29+
{props.ogImage && <meta property="og:image" content={props.ogImage} />}
3430
{props.created && (
35-
<meta property="article:published_time" content={props.created}/>
31+
<meta property="article:published_time" content={props.created} />
3632
)}
3733
{props.last_edited && (
38-
<meta property="article:modified_time" content={props.last_edited}/>
34+
<meta property="article:modified_time" content={props.last_edited} />
35+
)}
36+
37+
{/* Prevent search engine indexing of unlisted content or proxied content from external URLs */}
38+
{(props.unlisted ||
39+
(props.url &&
40+
(props.url.startsWith("github/") ||
41+
props.url.startsWith("gist/")))) && (
42+
<>
43+
<meta name="robots" content="noindex, nofollow" />
44+
<meta name="googlebot" content="noindex, nofollow" />
45+
</>
3946
)}
4047
</NextHead>
4148
</>
@@ -81,7 +88,8 @@ export async function getServerSideProps(context) {
8188

8289
// Add image path for social media sharing
8390
//
84-
customize.props.ogImage = customize.props.customize.logoSquareURL ||
91+
customize.props.ogImage =
92+
customize.props.customize.logoSquareURL ||
8593
`${customize.props.customize.siteURL}${ogShareLogo.src}`;
8694
}
8795

0 commit comments

Comments
 (0)