Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 3x 8x 8x 9x 9x 8x 8x 9x 9x 8x 20x 8x 7x 7x 14x 7x 14x 7x 9x 8x 9x | import type { BreadcrumbItem } from "@nuxt/ui";
import { sortDecisions } from "#layers/decisions/shared/decisionReports.ts";
/** One decision's rendered report and the ones decided either side of it; `ready` settles on load. */
export const useDecisionPage = () => {
const route = useRoute();
const { t } = useI18n();
const id = computed(() => (typeof route.params.id === "string" ? route.params.id : ""));
const path = computed(() => `/docs/decisions/${id.value}`);
const reports = useDecisionReports();
const content = useAsyncData(
() => `decision-${id.value}`,
() => queryCollection("docs").path(path.value).first(),
{ watch: [path] },
);
const report = computed(
() => reports.value.find((candidate) => candidate.id === id.value) ?? null,
);
const around = computed(() => {
const ordered = sortDecisions(reports.value, "oldest");
const { previous, next } = neighbours(
ordered,
ordered.findIndex((candidate) => candidate.id === id.value),
);
const link = (entry: typeof previous) =>
entry ? { to: `/decisions/${entry.id}`, title: entry.title } : null;
return { previous: link(previous), next: link(next) };
});
const crumbs = computed<BreadcrumbItem[]>(() => [
{ label: t("decisions.title"), to: "/decisions", icon: "i-lucide-compass" },
{ label: report.value?.number ?? id.value, class: "font-mono" },
]);
return {
id,
page: content.data,
report,
source: computed(() => report.value?.path ?? `${path.value.slice(1)}.md`),
crumbs,
around,
ready: content,
};
};
|