@@ -26,22 +26,31 @@ export function generateStaticParams() {
2626export async function generateMetadata ( { params } : PageProps < "/legal/[slug]" > ) : Promise < Metadata > {
2727 const { slug } = await params
2828 if ( ! isLegalSlug ( slug ) ) return { }
29- return { title : pages [ slug ] . title , alternates : { canonical : `/legal/${ slug } ` } }
29+ const legal = await getSettings ( "legal" )
30+ const published = Boolean ( legal [ pages [ slug ] . field ] . trim ( ) )
31+ return {
32+ title : pages [ slug ] . title ,
33+ alternates : { canonical : `/legal/${ slug } ` } ,
34+ // Placeholder pages shouldn't end up in search results.
35+ ...( published ? { } : { robots : { index : false } } ) ,
36+ }
3037}
3138
3239/** Operator-provided Markdown → sanitized HTML. */
3340function renderMarkdown ( md : string ) : string {
3441 const html = marked . parse ( md , { async : false , gfm : true , breaks : false } )
3542 return sanitizeHtml ( html , {
36- allowedTags : sanitizeHtml . defaults . allowedTags . concat ( [ "h1" , " h2", "img" ] ) ,
43+ allowedTags : sanitizeHtml . defaults . allowedTags . concat ( [ "h2" , "img" ] ) ,
3744 allowedAttributes : {
38- a : [ "href" , "title" , "name" , " target", "rel" ] ,
45+ a : [ "href" , "title" , "target" , "rel" ] ,
3946 img : [ "src" , "alt" , "title" , "width" , "height" ] ,
4047 th : [ "align" ] ,
4148 td : [ "align" ] ,
4249 } ,
4350 allowedSchemes : [ "http" , "https" , "mailto" , "tel" ] ,
4451 transformTags : {
52+ // The page already has an <h1>; demote Markdown top-level headings.
53+ h1 : "h2" ,
4554 a : ( tagName , attribs ) => {
4655 const external = / ^ h t t p s ? : \/ \/ / . test ( attribs . href ?? "" )
4756 return {
@@ -94,10 +103,6 @@ export default async function LegalPage({ params }: PageProps<"/legal/[slug]">)
94103 < FileText className = "size-4 text-muted-foreground" aria-hidden />
95104 </ span >
96105 < p className = "mt-5 text-[15px] font-medium" > The operator of this instance hasn't published this page yet.</ p >
97- < p className = "mt-1.5 max-w-sm text-[13.5px] leading-relaxed text-muted-foreground" >
98- Administrators can add it in Admin → Settings → Legal. It's written in Markdown and appears here
99- right away.
100- </ p >
101106 </ div >
102107 ) }
103108 </ div >
0 commit comments