refactor: Update findNavigationLink to include subitems in search
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 52s
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 52s
This commit is contained in:
parent
6695c7c023
commit
48a644b74a
@ -119,15 +119,17 @@ export const navigation: NavigationSection[] = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function findNavigationLink(namespace: string, href: string) {
|
export function findNavigationLink(namespace: string, href: string): NavigationLink | undefined {
|
||||||
const currentUrl = `/${namespace}/${href}`.replace(/\/+/g, "/").replace(/\/$/, "");
|
const currentUrl = `/${namespace}/${href}`.replace(/\/+/g, "/").replace(/\/$/, "");
|
||||||
|
|
||||||
const links = navigation.flatMap((section) => section.links);
|
const foundLink = navigation
|
||||||
const subitems = links.flatMap((link) => link.subitems);
|
.flatMap((section) => section.links)
|
||||||
const allLinks = new Set([...links, ...subitems]);
|
.find((link) => {
|
||||||
const foundLink = Array.from(allLinks).find((link) => link.href === currentUrl);
|
link.href === currentUrl ||
|
||||||
|
link.subitems.some((subitem) => {
|
||||||
console.log({ allLinks, currentUrl });
|
subitem.href === currentUrl;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return foundLink;
|
return foundLink;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export default {
|
|||||||
class: "flex min-h-full bg-white dark:bg-slate-900",
|
class: "flex min-h-full bg-white dark:bg-slate-900",
|
||||||
},
|
},
|
||||||
|
|
||||||
image: null,
|
image: "/og.webp",
|
||||||
|
|
||||||
// prerender: true,
|
// prerender: true,
|
||||||
prefetchStaticAssets: "hover",
|
prefetchStaticAssets: "hover",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import type { PageContext } from "vike/types";
|
import type { PageContext } from "vike/types";
|
||||||
|
|
||||||
import { snippetsService } from "@/services/SnippetsService";
|
import { snippetsService } from "@/services/SnippetsService";
|
||||||
|
import { findNavigationLink } from "@/lib/navigation";
|
||||||
import { docsService } from "@/services/DocsService";
|
import { docsService } from "@/services/DocsService";
|
||||||
import { readingTime } from "reading-time-estimator";
|
import { readingTime } from "reading-time-estimator";
|
||||||
import { useConfig } from "vike-react/useConfig";
|
import { useConfig } from "vike-react/useConfig";
|
||||||
@ -15,6 +16,7 @@ export async function data(pageContext: PageContext) {
|
|||||||
const { key } = pageContext.routeParams;
|
const { key } = pageContext.routeParams;
|
||||||
|
|
||||||
const doc = await docsService.getDoc("certifications", key);
|
const doc = await docsService.getDoc("certifications", key);
|
||||||
|
const link = findNavigationLink("docs", key);
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
throw render(404);
|
throw render(404);
|
||||||
@ -25,6 +27,7 @@ export async function data(pageContext: PageContext) {
|
|||||||
config({
|
config({
|
||||||
title: buildTitle(doc.title),
|
title: buildTitle(doc.title),
|
||||||
description: doc.description,
|
description: doc.description,
|
||||||
|
image: link?.og?.image || "/og.webp",
|
||||||
});
|
});
|
||||||
|
|
||||||
docsService.transform(doc);
|
docsService.transform(doc);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ export async function data(pageContext: PageContext) {
|
|||||||
config({
|
config({
|
||||||
title: buildTitle(doc.title),
|
title: buildTitle(doc.title),
|
||||||
description: doc.description,
|
description: doc.description,
|
||||||
image: link?.og?.image || "notfound",
|
image: link?.og?.image || "/og.webp",
|
||||||
});
|
});
|
||||||
|
|
||||||
docsService.transform(doc);
|
docsService.transform(doc);
|
||||||
|
|||||||
BIN
app/public/og.webp
Normal file
BIN
app/public/og.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
og_maker.afphoto
Normal file
BIN
og_maker.afphoto
Normal file
Binary file not shown.
BIN
og_maker.afphoto~lock~
Normal file
BIN
og_maker.afphoto~lock~
Normal file
Binary file not shown.
BIN
og_maker.afphoto~lock~:com.dropbox.ignored
Normal file
BIN
og_maker.afphoto~lock~:com.dropbox.ignored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user