Skip to content

Commit

Permalink
[opt]: add document lang
Browse files Browse the repository at this point in the history
  • Loading branch information
stone1100 committed Jun 24, 2024
1 parent f32a329 commit 937e41b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ specific language governing permissions and limitations
under the License.
*/
import React from "react";
import { Html, Head, Main, NextScript } from "next/document";
import Document, {
Html,
Head,
Main,
NextScript,
DocumentContext,
} from "next/document";
import { getLocale } from "@site/utils/utils";

const RootDocument = () => {
const RootDocument = (props: { locale: string }) => {
const { locale } = props;
return (
<Html
lang="en"
lang={locale}
className="dark [--scroll-mt:9.875rem] [scrollbar-gutter:stable] lg:[--scroll-mt:6.3125rem]"
>
<Head>
Expand All @@ -48,5 +56,10 @@ const RootDocument = () => {
</Html>
);
};
RootDocument.getInitialProps = async (ctx: DocumentContext) => {
const initialProps = await Document.getInitialProps(ctx);
const { locale } = getLocale(ctx.asPath || "");
return { ...initialProps, locale: locale };
};

export default RootDocument;

0 comments on commit 937e41b

Please sign in to comment.