@m13v/seo-components 0.8.12 → 0.8.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -42,7 +42,9 @@ function onPosthogLoaded(fn: () => void) {
|
|
|
42
42
|
/** Derive a slug from any pathname. "/" returns "" (hidden). */
|
|
43
43
|
function slugFromPath(pathname: string | null): string {
|
|
44
44
|
if (!pathname || pathname === "/") return "";
|
|
45
|
-
|
|
45
|
+
// Return cleaned pathname (e.g. "/solutions/sap" -> "solutions/sap")
|
|
46
|
+
// The server matches by href or last-segment slug.
|
|
47
|
+
return pathname.replace(/^\/+/, "").replace(/\/+$/g, "");
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
/* ------------------------------------------------------------------ */
|
|
@@ -76,8 +76,10 @@ export function SitemapSidebar({
|
|
|
76
76
|
const [query, setQuery] = useState("");
|
|
77
77
|
const [mobileOpen, setMobileOpen] = useState(false);
|
|
78
78
|
const [activeSection, setActiveSection] = useState<string | null>(null);
|
|
79
|
+
const [hasExternalBrand, setHasExternalBrand] = useState(false);
|
|
79
80
|
const activeRef = useRef<HTMLAnchorElement | null>(null);
|
|
80
81
|
const navRef = useRef<HTMLElement | null>(null);
|
|
82
|
+
const sidebarRef = useRef<HTMLElement | null>(null);
|
|
81
83
|
|
|
82
84
|
const filtered = query
|
|
83
85
|
? pages.filter(
|
|
@@ -106,6 +108,19 @@ export function SitemapSidebar({
|
|
|
106
108
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
109
|
}, [pathname]);
|
|
108
110
|
|
|
111
|
+
// Hide sidebar brand header if a navbar with a home link already exists on the page.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const navs = document.querySelectorAll("nav");
|
|
114
|
+
for (const nav of navs) {
|
|
115
|
+
if (sidebarRef.current?.contains(nav)) continue;
|
|
116
|
+
const homeLink = nav.querySelector('a[href="/"]');
|
|
117
|
+
if (homeLink) {
|
|
118
|
+
setHasExternalBrand(true);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
109
124
|
// Track which H2 section is currently in view.
|
|
110
125
|
useEffect(() => {
|
|
111
126
|
const article = document.querySelector("article");
|
|
@@ -197,6 +212,7 @@ export function SitemapSidebar({
|
|
|
197
212
|
|
|
198
213
|
{/* Sidebar */}
|
|
199
214
|
<aside
|
|
215
|
+
ref={sidebarRef}
|
|
200
216
|
className={`
|
|
201
217
|
fixed lg:sticky top-0 left-0 z-40 h-screen shrink-0
|
|
202
218
|
w-72 bg-white dark:bg-zinc-950 border-r border-zinc-200 dark:border-zinc-800
|
|
@@ -208,19 +224,21 @@ export function SitemapSidebar({
|
|
|
208
224
|
>
|
|
209
225
|
{/* Header */}
|
|
210
226
|
<div className="p-4 border-b border-zinc-100 dark:border-zinc-800">
|
|
211
|
-
|
|
212
|
-
{
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
{!hasExternalBrand && (
|
|
228
|
+
<a href={homeHref} className="flex items-baseline gap-0 mb-4">
|
|
229
|
+
{brandLogo ?? (
|
|
230
|
+
<>
|
|
231
|
+
<span className="font-mono font-bold text-lg tracking-tight text-zinc-900 dark:text-zinc-100">
|
|
232
|
+
{brandName}
|
|
233
|
+
</span>
|
|
234
|
+
<span
|
|
235
|
+
className="w-1.5 h-1.5 rounded-full ml-0.5 mb-0.5 inline-block"
|
|
236
|
+
style={{ backgroundColor: "var(--seo-accent, #14b8a6)" }}
|
|
237
|
+
/>
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
</a>
|
|
241
|
+
)}
|
|
224
242
|
<div className="relative">
|
|
225
243
|
<svg
|
|
226
244
|
className="absolute left-2.5 top-1/2 -translate-y-1/2 text-zinc-400"
|
package/src/lib/guide-context.ts
CHANGED
|
@@ -16,7 +16,12 @@ export function getGuideContext(
|
|
|
16
16
|
contentDir?: string,
|
|
17
17
|
): GuideContext | null {
|
|
18
18
|
const dir = contentDir ?? path.join(process.cwd(), "src/app/(content)/t");
|
|
19
|
-
const
|
|
19
|
+
const guides = discoverGuides(dir);
|
|
20
|
+
// Match by last-segment slug or full href path (e.g. "solutions/sap" -> "/solutions/sap")
|
|
21
|
+
const hrefFromSlug = "/" + slug;
|
|
22
|
+
const guide = guides.find(
|
|
23
|
+
(g) => g.slug === slug || g.href === hrefFromSlug,
|
|
24
|
+
);
|
|
20
25
|
if (!guide) return null;
|
|
21
26
|
|
|
22
27
|
// Derive appDir from contentDir to locate page files by their full href
|