A yolo test of codex
This commit is contained in:
@@ -1,9 +1,74 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import RegisterDetail from '@/app/registers/RegisterDetail';
|
||||
import {Container, Row} from "react-bootstrap";
|
||||
import { getRegisters } from '@/services/register.service';
|
||||
|
||||
const buildRegisterSummary = (register: { description: string; text: string; modes: { text: string }[] }) => {
|
||||
const trimLine = (line: string) => line.trim();
|
||||
const isInfoLine = (line: string) =>
|
||||
line.length > 0 &&
|
||||
!line.startsWith('//') &&
|
||||
!line.startsWith('(R') &&
|
||||
!line.startsWith('(W') &&
|
||||
!line.startsWith('(R/W') &&
|
||||
!line.startsWith('*') &&
|
||||
!/^bits?\s+\d/i.test(line);
|
||||
|
||||
const modeLines = register.modes.flatMap(mode => mode.text.split('\n')).map(trimLine).filter(isInfoLine);
|
||||
const textLines = register.text.split('\n').map(trimLine).filter(isInfoLine);
|
||||
const descriptionLines = register.description.split('\n').map(trimLine).filter(isInfoLine);
|
||||
|
||||
const rawSummary = [...textLines, ...modeLines, ...descriptionLines].join(' ').replace(/\s+/g, ' ').trim();
|
||||
if (!rawSummary) return 'Spectrum Next register details and bit-level behavior.';
|
||||
if (rawSummary.length <= 180) return rawSummary;
|
||||
return `${rawSummary.slice(0, 177).trimEnd()}...`;
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ hex: string }> }): Promise<Metadata> {
|
||||
const registers = await getRegisters();
|
||||
const { hex } = await params;
|
||||
const targetHex = decodeURIComponent(hex).toLowerCase();
|
||||
const register = registers.find(r => r.hex_address.toLowerCase() === targetHex);
|
||||
|
||||
if (!register) {
|
||||
return {
|
||||
title: 'Register Not Found | Spectrum Next Explorer',
|
||||
robots: { index: false, follow: false },
|
||||
};
|
||||
}
|
||||
|
||||
const summary = buildRegisterSummary(register);
|
||||
const title = `${register.hex_address} ${register.name} | Spectrum Next Explorer`;
|
||||
const imageUrl = `/registers/${register.hex_address}/opengraph-image`;
|
||||
|
||||
return {
|
||||
title,
|
||||
description: summary,
|
||||
openGraph: {
|
||||
title,
|
||||
description: summary,
|
||||
type: 'article',
|
||||
url: `/registers/${register.hex_address}`,
|
||||
images: [
|
||||
{
|
||||
url: imageUrl,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: `${register.hex_address} ${register.name}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
title,
|
||||
description: summary,
|
||||
images: [imageUrl],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default async function RegisterDetailPage({ params }: { params: Promise<{ hex: string }> }) {
|
||||
const registers = await getRegisters();
|
||||
const { hex } = await params;
|
||||
|
||||
Reference in New Issue
Block a user