You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "tisonkun (via GitHub)" <gi...@apache.org> on 2023/03/21 11:13:11 UTC

[GitHub] [pulsar-site] tisonkun opened a new pull request, #481: [feat] Add canonical link for SEO

tisonkun opened a new pull request, #481:
URL: https://github.com/apache/pulsar-site/pull/481

   This closes https://github.com/apache/pulsar/issues/18190.
   
   ### Documentation
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ] `doc` <!-- Your PR contains doc changes. Please attach the local preview screenshots (run `./preview.sh` at root path) to your PR description, or else your PR might not get merged. -->
   - [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
   - [x] `doc-not-needed` <!-- Your PR changes do not impact docs -->
   - [ ] `doc-complete` <!-- Docs have been already added -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#issuecomment-1478824626

   Merging...
   
   Let's see if it helps.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] momo-jun commented on a diff in pull request #481: [feat] Add canonical link for SEO

Posted by "momo-jun (via GitHub)" <gi...@apache.org>.
momo-jun commented on code in PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#discussion_r1144513470


##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from '@docusaurus/theme-common';
+import {
+  DocsSidebarProvider,
+  DocsVersionProvider,
+  docVersionSearchTag,
+  useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+  const {siteConfig} = useDocusaurusContext();
+  const {versionMetadata, location, match} = props;
+  if (versionMetadata.version === 'current') {
+    // 1. The NEXT version docs should not forward to the latest stable version
+    // 2. Other plugins-doc instance (contribute, release-note, ...) happens to keep the link
+    return siteConfig.url + useBaseUrl(location.pathname);
+  }
+  const basename = location.pathname.replace(match.path, '');
+  return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+  const {versionMetadata} = props;
+  return (
+    <>
+      <SearchMetadata
+        version={versionMetadata.version}
+        tag={docVersionSearchTag(
+          versionMetadata.pluginId,
+          versionMetadata.version,
+        )}
+      />
+      <PageMetadata>
+        {versionMetadata.noIndex && (

Review Comment:
   @tisonkun, thanks for your contribution. It's really helpful and takes effect when I retry several search items.
   
   Just wondering about the second indented search result in the following case. Is it because we still index all versions?
   
   <img width="966" alt="image" src="https://user-images.githubusercontent.com/60642177/226866312-6c8fe949-8aa2-4824-8018-dce1d35b42df.png">
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on a diff in pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#discussion_r1143269164


##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from '@docusaurus/theme-common';
+import {
+  DocsSidebarProvider,
+  DocsVersionProvider,
+  docVersionSearchTag,
+  useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+  const {siteConfig} = useDocusaurusContext();
+  const {versionMetadata, location, match} = props;
+  if (versionMetadata.version === 'current') {
+    // 1. The NEXT version docs should not forward to the latest stable version
+    // 2. Other plugins-doc instance (contribute, release-note, ...) happens to keep the link
+    return siteConfig.url + useBaseUrl(location.pathname);
+  }
+  const basename = location.pathname.replace(match.path, '');
+  return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+  const {versionMetadata} = props;
+  return (
+    <>
+      <SearchMetadata
+        version={versionMetadata.version}
+        tag={docVersionSearchTag(
+          versionMetadata.pluginId,
+          versionMetadata.version,
+        )}
+      />
+      <PageMetadata>
+        {versionMetadata.noIndex && (

Review Comment:
   Actually, if we properly configure `noIndex`, we can exclude old versions docs being indexed by the search engine.
   
   The canonical link tweak can bring old links don't exist in latest version, but as we set up redirections properly, it's not a big problem.
   
   cc @vinayrajsn @momo-jun @dave2wave thoughts?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on a diff in pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#discussion_r1143255957


##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from '@docusaurus/theme-common';
+import {
+  DocsSidebarProvider,
+  DocsVersionProvider,
+  docVersionSearchTag,
+  useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+  const {siteConfig} = useDocusaurusContext();
+  const {versionMetadata, location, match} = props;
+  if (versionMetadata.version === 'current') {
+    // 1. The NEXT version docs should not forward to the latest stable version
+    // 2. Other plugins-doc instance (contribute, release-note, ...) happens to keep the link
+    return siteConfig.url + useBaseUrl(location.pathname);
+  }
+  const basename = location.pathname.replace(match.path, '');
+  return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+  const {versionMetadata} = props;
+  return (
+    <>
+      <SearchMetadata
+        version={versionMetadata.version}
+        tag={docVersionSearchTag(
+          versionMetadata.pluginId,
+          versionMetadata.version,
+        )}
+      />
+      <PageMetadata>
+        {versionMetadata.noIndex && (
+          <meta name="robots" content="noindex, nofollow" />
+        )}
+        <link rel="canonical" href={createCanonicalHref(props)}/>

Review Comment:
   Only this line and the function `createCanonicalHref` are changed. Other lines are ejected internal logics which are already existing.



##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from '@docusaurus/theme-common';
+import {
+  DocsSidebarProvider,
+  DocsVersionProvider,
+  docVersionSearchTag,
+  useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+  const {siteConfig} = useDocusaurusContext();
+  const {versionMetadata, location, match} = props;
+  if (versionMetadata.version === 'current') {
+    // 1. The NEXT version docs should not forward to the latest stable version
+    // 2. Other plugins-doc instance (contribute, release-note, ...) happens to keep the link
+    return siteConfig.url + useBaseUrl(location.pathname);
+  }
+  const basename = location.pathname.replace(match.path, '');
+  return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+  const {versionMetadata} = props;
+  return (
+    <>
+      <SearchMetadata
+        version={versionMetadata.version}
+        tag={docVersionSearchTag(
+          versionMetadata.pluginId,
+          versionMetadata.version,
+        )}
+      />
+      <PageMetadata>
+        {versionMetadata.noIndex && (
+          <meta name="robots" content="noindex, nofollow" />
+        )}
+        <link rel="canonical" href={createCanonicalHref(props)}/>

Review Comment:
   Only this line and the function `createCanonicalHref` are added. Other lines are ejected internal logics which are already existing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun merged pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun merged PR #481:
URL: https://github.com/apache/pulsar-site/pull/481


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] momo-jun commented on pull request #481: [feat] Add canonical link for SEO

Posted by "momo-jun (via GitHub)" <gi...@apache.org>.
momo-jun commented on PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#issuecomment-1484836106

   Hi @tisonkun, I wanted to ask a follow-up question on the logic that decides which canonical URLs to return in the Google results.
   
   IIUC, the current adopted strategy is to enable two types of canonical links:
   - `next` version uses `/next/` in the canonical URLs
   - all the other versions use the latest stable version number in the canonical URLs
   
   Then what logic decides the canonical URL to return in the Google results if the keyword exists in both the `next` version and earlier versions? In my observation, the behavior is random, so I'm wondering about the logic behind this.
   
   For example, for "pulsar throttling", the next version shows: 
   <img width="877" alt="image" src="https://user-images.githubusercontent.com/60642177/227905409-d430a281-6184-4979-94f1-83e5aa01e8a2.png">
   
   And for "pulsar functions", the latest stable version shows:
   <img width="847" alt="image" src="https://user-images.githubusercontent.com/60642177/227905570-c219ae7f-9be7-474d-860c-aa9a0b07067a.png">
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#issuecomment-1477655722

   We need a full rebuild to regenerate the head metadata for all pages :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#issuecomment-1486903668

   > the behavior is random
   
   Yes. IIRC there are some approaches we can hint the search engine about page "weight", but I'm not quite clear how we can implement it for our website now :)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar-site] tisonkun commented on a diff in pull request #481: [feat] Add canonical link for SEO

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #481:
URL: https://github.com/apache/pulsar-site/pull/481#discussion_r1144570593


##########
src/theme/DocPage/index.tsx:
##########
@@ -0,0 +1,74 @@
+import React from 'react';
+import clsx from 'clsx';
+import {HtmlClassNameProvider, PageMetadata, ThemeClassNames,} from '@docusaurus/theme-common';
+import {
+  DocsSidebarProvider,
+  DocsVersionProvider,
+  docVersionSearchTag,
+  useDocRouteMetadata,
+} from '@docusaurus/theme-common/internal';
+import DocPageLayout from '@theme/DocPage/Layout';
+import NotFound from '@theme/NotFound';
+import SearchMetadata from '@theme/SearchMetadata';
+import type {Props} from '@theme/DocPage';
+import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+
+function createCanonicalHref(props: Props): string {
+  const {siteConfig} = useDocusaurusContext();
+  const {versionMetadata, location, match} = props;
+  if (versionMetadata.version === 'current') {
+    // 1. The NEXT version docs should not forward to the latest stable version
+    // 2. Other plugins-doc instance (contribute, release-note, ...) happens to keep the link
+    return siteConfig.url + useBaseUrl(location.pathname);
+  }
+  const basename = location.pathname.replace(match.path, '');
+  return siteConfig.url + useBaseUrl(`/docs/${basename}`);
+}
+function DocPageMetadata(props: Props): JSX.Element {
+  const {versionMetadata} = props;
+  return (
+    <>
+      <SearchMetadata
+        version={versionMetadata.version}
+        tag={docVersionSearchTag(
+          versionMetadata.pluginId,
+          versionMetadata.version,
+        )}
+      />
+      <PageMetadata>
+        {versionMetadata.noIndex && (

Review Comment:
   Search engine reindex pages periodically.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org