pass lang to the highlighter and add lang to the end of the page title

This commit is contained in:
Lee 2024-04-23 17:32:57 +01:00
parent 63b483b119
commit 125fbf680a
2 changed files with 10 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import { ActionMenu } from "@/app/components/action-menu";
import { Metadata } from "next";
import moment from "moment";
import { notFound } from "next/navigation";
import { CodeBlock } from "@/app/components/codeBlock";
import { CodeBlock } from "@/app/components/code-block";
import { detectLanguage } from "@/app/common/lang-detection/detection";
type PasteProps = {
@ -61,7 +61,7 @@ export async function generateMetadata({
}
return {
title: `Paste - ${id}`,
title: `Paste - ${id}.${data.language}`,
description: `Created: ${moment(data.created)}\n\nClick to view the paste.`,
};
}
@ -83,7 +83,7 @@ export default async function Paste({
</div>
<div className="p-1 hljs !bg-transparent text-sm">
<CodeBlock code={data.content} />
<CodeBlock code={data.content} language={data.language} />
</div>
</div>
);

View File

@ -8,13 +8,19 @@ type CodeBlockProps = {
* The code to highlight.
*/
code: string;
/**
* The language of the code.
*/
language: string;
};
export function CodeBlock({ code }: CodeBlockProps): ReactElement {
export function CodeBlock({ code, language }: CodeBlockProps): ReactElement {
return (
<SyntaxHighlighter
className="!bg-transparent text-xs"
style={atomOneDark}
language={language}
showLineNumbers
codeTagProps={{
style: {