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 | 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 8x 4x 4x 3x 3x 6x 3x 4x 4x 4x | import type { BreadcrumbItem } from "@nuxt/ui";
import { BENCHMARKS_PATH } from "#layers/benchmarks/app/utils/benchmarks.ts";
/** One benchmark's rendered page and its gallery neighbours; `ready` settles once both load. */
export const useBenchmarkPage = () => {
const route = useRoute();
const { t } = useI18n();
const id = computed(() => (typeof route.params.id === "string" ? route.params.id : ""));
const path = computed(() => `${BENCHMARKS_PATH}${id.value}`);
const gallery = useBenchmarks();
const benchmarks = gallery.data;
const content = useAsyncData(
() => `benchmark-${id.value}`,
() => queryCollection("docs").path(path.value).first(),
{ watch: [path] },
);
const index = computed(() =>
benchmarks.value.findIndex((candidate) => candidate.id === id.value),
);
const benchmark = computed(() => benchmarks.value[index.value] ?? null);
const around = computed(() => {
const { previous, next } = neighbours(benchmarks.value, index.value);
const link = (entry: typeof previous) =>
entry ? { to: `/benchmarks/${entry.id}`, title: entry.title } : null;
return { previous: link(previous), next: link(next) };
});
const crumbs = computed<BreadcrumbItem[]>(() => [
{ label: t("benchmarks.title"), to: "/benchmarks", icon: "i-lucide-bookmark" },
{ label: benchmark.value?.title ?? id.value },
]);
return {
id,
page: content.data,
benchmark,
source: computed(() => `${path.value.slice(1)}.md`),
crumbs,
around,
ready: Promise.all([gallery, content]),
};
};
|