@m13v/seo-components 0.8.7 → 0.8.9
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
|
@@ -19,7 +19,7 @@ function slugify(text: string): string {
|
|
|
19
19
|
* This keeps the sidebar ToC clickable without requiring every page
|
|
20
20
|
* author to add id attributes manually.
|
|
21
21
|
*/
|
|
22
|
-
export function HeadingAnchors() {
|
|
22
|
+
export function HeadingAnchors({ children }: { children?: React.ReactNode } = {}) {
|
|
23
23
|
const pathname = usePathname();
|
|
24
24
|
|
|
25
25
|
useEffect(() => {
|
|
@@ -55,5 +55,5 @@ export function HeadingAnchors() {
|
|
|
55
55
|
}
|
|
56
56
|
}, [pathname]);
|
|
57
57
|
|
|
58
|
-
return null;
|
|
58
|
+
return children ? <>{children}</> : null;
|
|
59
59
|
}
|
|
@@ -25,17 +25,25 @@ export function discoverGuides(contentDir?: string): GuideEntry[] {
|
|
|
25
25
|
|
|
26
26
|
if (cachedDir === dir && cachedGuides) return cachedGuides;
|
|
27
27
|
|
|
28
|
-
// Determine
|
|
29
|
-
//
|
|
30
|
-
const
|
|
28
|
+
// Determine the Next.js app directory root from contentDir.
|
|
29
|
+
// e.g. "src/app/t" -> "src/app", "app" -> "app", "src/app/(content)/t" -> "src/app"
|
|
30
|
+
const relDir = path.relative(process.cwd(), dir);
|
|
31
|
+
const relParts = relDir.split(path.sep);
|
|
32
|
+
const appIdx = relParts.indexOf("app");
|
|
33
|
+
const appDir =
|
|
34
|
+
appIdx >= 0
|
|
35
|
+
? path.join(process.cwd(), ...relParts.slice(0, appIdx + 1))
|
|
36
|
+
: path.join(process.cwd(), "src/app");
|
|
31
37
|
const allPages = walkPages({ appDir });
|
|
32
38
|
|
|
33
39
|
// Figure out the href prefix from contentDir.
|
|
34
40
|
// e.g. "src/app/(content)/t" -> "/t", "src/app/t" -> "/t"
|
|
35
41
|
const relative = path.relative(appDir, dir);
|
|
36
42
|
const segments = relative
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
? relative
|
|
44
|
+
.split(path.sep)
|
|
45
|
+
.filter((s) => !(s.startsWith("(") && s.endsWith(")")))
|
|
46
|
+
: [];
|
|
39
47
|
const hrefPrefix = "/" + segments.join("/");
|
|
40
48
|
|
|
41
49
|
const guides: GuideEntry[] = allPages
|
package/src/lib/guide-context.ts
CHANGED
|
@@ -19,7 +19,15 @@ export function getGuideContext(
|
|
|
19
19
|
const guide = discoverGuides(dir).find((g) => g.slug === slug);
|
|
20
20
|
if (!guide) return null;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// Derive appDir from contentDir to locate page files by their full href
|
|
23
|
+
const relDir = path.relative(process.cwd(), dir);
|
|
24
|
+
const relParts = relDir.split(path.sep);
|
|
25
|
+
const appIdx = relParts.indexOf("app");
|
|
26
|
+
const appDir =
|
|
27
|
+
appIdx >= 0
|
|
28
|
+
? path.join(process.cwd(), ...relParts.slice(0, appIdx + 1))
|
|
29
|
+
: dir;
|
|
30
|
+
const pagePath = path.join(appDir, guide.href, "page.tsx");
|
|
23
31
|
let rawSource = "";
|
|
24
32
|
try {
|
|
25
33
|
rawSource = fs.readFileSync(pagePath, "utf-8");
|