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 links = navigation.flatMap((section) => section.links);
|
||||
const subitems = links.flatMap((link) => link.subitems);
|
||||
const allLinks = new Set([...links, ...subitems]);
|
||||
const foundLink = Array.from(allLinks).find((link) => link.href === currentUrl);
|
||||
|
||||
console.log({ allLinks, currentUrl });
|
||||
const foundLink = navigation
|
||||
.flatMap((section) => section.links)
|
||||
.find((link) => {
|
||||
link.href === currentUrl ||
|
||||
link.subitems.some((subitem) => {
|
||||
subitem.href === currentUrl;
|
||||
});
|
||||
});
|
||||
|
||||
return foundLink;
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ export default {
|
||||
class: "flex min-h-full bg-white dark:bg-slate-900",
|
||||
},
|
||||
|
||||
image: null,
|
||||
image: "/og.webp",
|
||||
|
||||
// prerender: true,
|
||||
prefetchStaticAssets: "hover",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import type { PageContext } from "vike/types";
|
||||
|
||||
import { snippetsService } from "@/services/SnippetsService";
|
||||
import { findNavigationLink } from "@/lib/navigation";
|
||||
import { docsService } from "@/services/DocsService";
|
||||
import { readingTime } from "reading-time-estimator";
|
||||
import { useConfig } from "vike-react/useConfig";
|
||||
@ -15,6 +16,7 @@ export async function data(pageContext: PageContext) {
|
||||
const { key } = pageContext.routeParams;
|
||||
|
||||
const doc = await docsService.getDoc("certifications", key);
|
||||
const link = findNavigationLink("docs", key);
|
||||
|
||||
if (!doc) {
|
||||
throw render(404);
|
||||
@ -25,6 +27,7 @@ export async function data(pageContext: PageContext) {
|
||||
config({
|
||||
title: buildTitle(doc.title),
|
||||
description: doc.description,
|
||||
image: link?.og?.image || "/og.webp",
|
||||
});
|
||||
|
||||
docsService.transform(doc);
|
||||
|
||||
@ -27,7 +27,7 @@ export async function data(pageContext: PageContext) {
|
||||
config({
|
||||
title: buildTitle(doc.title),
|
||||
description: doc.description,
|
||||
image: link?.og?.image || "notfound",
|
||||
image: link?.og?.image || "/og.webp",
|
||||
});
|
||||
|
||||
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