Added layouts + routes
This commit is contained in:
47
src/components/dev/DevBanner.astro
Normal file
47
src/components/dev/DevBanner.astro
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
import type { Status } from '@/lib/constants/status'
|
||||
import { forEntry, formatDiagnostics } from '@/lib/diagnostics/report'
|
||||
import type { Diagnostic } from '@/lib/diagnostics/types'
|
||||
import { getSite } from '@/lib/site'
|
||||
|
||||
type Props = {
|
||||
collection: string
|
||||
id: string
|
||||
status?: Status
|
||||
diagnostics?: Diagnostic[]
|
||||
}
|
||||
|
||||
const { collection, id, status, diagnostics = [] } = Astro.props
|
||||
|
||||
const NOTICE: Partial<Record<Status, string>> = {
|
||||
draft: 'Draft – not build in production',
|
||||
unlisted: 'Unlisted – has page, but appears in no list',
|
||||
archived: 'Archived - has page, but appears in no list',
|
||||
}
|
||||
|
||||
const site = import.meta.env.Dev ? await getSite() : null
|
||||
const here = site ? [...forEntry(site.diagnostics, collection, id), ...diagnostics] : []
|
||||
const elsewhere = site ? site.diagnostics.filter((d) => !here.includes(d)) : []
|
||||
const notice = status ? NOTICE[status] : undefined
|
||||
---
|
||||
|
||||
{site && (here.length || elsewhere.length || notice) && (
|
||||
<aside class="dev-banner">
|
||||
{notice && <p class="notice">{notice}</p>}
|
||||
{here.length > 0 && (
|
||||
<ul>
|
||||
{here.map((d) => (
|
||||
<li class={d.level}>
|
||||
{d.level === 'error' ? '✖' : '▲'} {d.message}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{elsewhere.length > 0 && (
|
||||
<details>
|
||||
<summary>{elsewhere.length} problem(s) elsewhere</summary>
|
||||
<pre>{formatDiagnostics(elsewhere)}</pre>
|
||||
</details>
|
||||
)}
|
||||
</aside>
|
||||
)}
|
||||
Reference in New Issue
Block a user