@barodoc/theme-docs 6.1.0 → 7.1.0

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
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@barodoc/theme-docs",
3
- "version": "6.1.0",
3
+ "version": "7.1.0",
4
4
  "description": "Documentation theme for Barodoc",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "exports": {
7
8
  ".": "./src/index.ts",
9
+ "./theme": "./src/theme.ts",
8
10
  "./components": "./src/components/index.ts",
9
11
  "./components/*": "./src/components/*",
10
12
  "./layouts/*": "./src/layouts/*",
@@ -34,7 +36,7 @@
34
36
  "rehype-katex": "^7.0.1",
35
37
  "remark-math": "^6.0.0",
36
38
  "tailwind-merge": "^3.4.0",
37
- "@barodoc/core": "6.0.0"
39
+ "@barodoc/core": "7.0.0"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "astro": "^5.0.0",
@@ -27,11 +27,21 @@ if (filePath) {
27
27
  for (const line of raw.split("\n")) {
28
28
  const [name, email] = line.split("|");
29
29
  if (!name || seen.has(email)) continue;
30
- const hash = email.trim().toLowerCase();
31
- seen.set(email, {
32
- name: name.trim(),
33
- email: email.trim(),
34
- avatarUrl: `https://gravatar.com/avatar/${await computeHash(hash)}?s=64&d=mp`,
30
+
31
+ const trimmedEmail = email.trim();
32
+ const trimmedName = name.trim();
33
+
34
+ const noreplyMatch = trimmedEmail.match(
35
+ /^(\d+\+)?([^@]+)@users\.noreply\.github\.com$/
36
+ );
37
+ const avatarUrl = noreplyMatch
38
+ ? `https://github.com/${noreplyMatch[2]}.png?size=64`
39
+ : `https://gravatar.com/avatar/${await computeHash(trimmedEmail.toLowerCase())}?s=64&d=mp`;
40
+
41
+ seen.set(trimmedEmail, {
42
+ name: trimmedName,
43
+ email: trimmedEmail,
44
+ avatarUrl,
35
45
  });
36
46
  }
37
47
  contributors = Array.from(seen.values());
@@ -55,17 +65,23 @@ async function computeHash(input: string): Promise<string> {
55
65
  <div class="bd-contributors">
56
66
  <span class="bd-contributors-label">Contributors</span>
57
67
  <div class="bd-contributors-avatars">
58
- {contributors.map((c) => (
59
- <img
60
- src={c.avatarUrl}
61
- alt={c.name}
62
- title={c.name}
63
- class="bd-contributor-avatar"
64
- loading="lazy"
65
- width="28"
66
- height="28"
67
- />
68
- ))}
68
+ <img
69
+ src={contributors[0].avatarUrl}
70
+ alt={contributors[0].name}
71
+ title={contributors[0].name}
72
+ class="bd-contributor-avatar"
73
+ loading="lazy"
74
+ width="28"
75
+ height="28"
76
+ />
77
+ {contributors.length > 1 && (
78
+ <span
79
+ class="bd-contributor-count"
80
+ title={contributors.slice(1).map((c) => c.name).join(", ")}
81
+ >
82
+ +{contributors.length - 1}
83
+ </span>
84
+ )}
69
85
  </div>
70
86
  </div>
71
87
  )}
@@ -10,9 +10,15 @@ import {
10
10
  } from "./ui/tooltip";
11
11
  import { cn } from "../lib/utils";
12
12
 
13
+ interface TabItem {
14
+ label: string;
15
+ href: string;
16
+ }
17
+
13
18
  interface DocHeaderProps {
14
19
  siteName: string;
15
20
  logo?: string;
21
+ tabs?: TabItem[];
16
22
  githubUrl?: string;
17
23
  hasMultipleLocales?: boolean;
18
24
  currentLocale?: string;
@@ -46,6 +52,7 @@ function getLocalizedUrl(
46
52
  export function DocHeader({
47
53
  siteName,
48
54
  logo,
55
+ tabs = [],
49
56
  githubUrl,
50
57
  hasMultipleLocales,
51
58
  currentLocale = "en",
@@ -92,7 +99,7 @@ export function DocHeader({
92
99
  <TooltipProvider>
93
100
  <header className="sticky top-0 z-50 w-full min-w-0 border-b border-[var(--bd-border)] bg-[var(--bd-bg)]/95 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--bd-bg)]/80">
94
101
  <div className="flex h-14 items-center justify-between gap-2 px-4 sm:px-6 max-w-[1280px] mx-auto min-w-0">
95
- {/* Logo */}
102
+ {/* Logo + Tabs */}
96
103
  <div className="flex items-center gap-6 min-w-0 shrink">
97
104
  <a
98
105
  href="/"
@@ -101,6 +108,27 @@ export function DocHeader({
101
108
  {logo && <img src={logo} alt={siteName} className="h-7 w-7 shrink-0" />}
102
109
  <span className="text-[15px] tracking-tight truncate">{siteName}</span>
103
110
  </a>
111
+ {tabs.length > 0 && (
112
+ <nav className="hidden md:flex items-center gap-1">
113
+ {tabs.map((tab) => {
114
+ const isActive = currentPath === tab.href || currentPath.startsWith(tab.href + "/");
115
+ return (
116
+ <a
117
+ key={tab.href}
118
+ href={tab.href}
119
+ className={cn(
120
+ "px-3 py-1.5 text-[13px] font-medium rounded-lg transition-colors",
121
+ isActive
122
+ ? "text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-950/50"
123
+ : "text-[var(--bd-text-secondary)] hover:text-[var(--bd-text)] hover:bg-[var(--bd-bg-subtle)]"
124
+ )}
125
+ >
126
+ {tab.label}
127
+ </a>
128
+ );
129
+ })}
130
+ </nav>
131
+ )}
104
132
  </div>
105
133
 
106
134
  {/* Right side actions */}
@@ -18,6 +18,7 @@ const localeLabels: Record<string, string> = config.i18n?.labels || {};
18
18
  client:load
19
19
  siteName={config.name}
20
20
  logo={config.logo}
21
+ tabs={config.tabs}
21
22
  githubUrl={config.topbar?.github}
22
23
  hasMultipleLocales={hasMultipleLocales}
23
24
  currentLocale={currentLocale}
@@ -58,4 +58,6 @@ const groups = config.navigation.map((group) => ({
58
58
  groups={groups}
59
59
  siteName={config.name}
60
60
  logo={config.logo}
61
+ tabs={config.tabs}
62
+ currentPath={currentPath}
61
63
  />
@@ -21,13 +21,20 @@ interface NavGroup {
21
21
  defaultOpen?: boolean;
22
22
  }
23
23
 
24
+ interface TabItem {
25
+ label: string;
26
+ href: string;
27
+ }
28
+
24
29
  interface MobileNavSheetProps {
25
30
  groups: NavGroup[];
26
31
  siteName: string;
27
32
  logo?: string;
33
+ tabs?: TabItem[];
34
+ currentPath?: string;
28
35
  }
29
36
 
30
- export function MobileNavSheet({ groups, siteName, logo }: MobileNavSheetProps) {
37
+ export function MobileNavSheet({ groups, siteName, logo, tabs = [], currentPath = "" }: MobileNavSheetProps) {
31
38
  const [open, setOpen] = React.useState(false);
32
39
 
33
40
  React.useEffect(() => {
@@ -61,6 +68,27 @@ export function MobileNavSheet({ groups, siteName, logo }: MobileNavSheetProps)
61
68
  </SheetTitle>
62
69
  </SheetHeader>
63
70
  <ScrollArea className="h-[calc(100vh-65px)]">
71
+ {tabs.length > 0 && (
72
+ <div className="px-4 pt-4 pb-2 flex flex-col gap-1 border-b border-[var(--bd-border)]">
73
+ {tabs.map((tab) => {
74
+ const isActive = currentPath === tab.href || currentPath.startsWith(tab.href + "/");
75
+ return (
76
+ <a
77
+ key={tab.href}
78
+ href={tab.href}
79
+ className={cn(
80
+ "px-3 py-2 text-sm font-medium rounded-lg transition-colors",
81
+ isActive
82
+ ? "text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-950/50"
83
+ : "text-[var(--bd-text-secondary)] hover:text-[var(--bd-text)] hover:bg-[var(--bd-bg-subtle)]"
84
+ )}
85
+ >
86
+ {tab.label}
87
+ </a>
88
+ );
89
+ })}
90
+ </div>
91
+ )}
64
92
  <div className="px-2 py-4">
65
93
  <DocsSidebar groups={groups} />
66
94
  </div>
@@ -12,6 +12,7 @@ export { DocTabs } from "./mdx/DocTabs.tsx";
12
12
  export { DocAccordion, SimpleAccordion } from "./mdx/DocAccordion.tsx";
13
13
 
14
14
  // New MDX Components (Mintlify-style)
15
+ export { Callout } from "./mdx/Callout.tsx";
15
16
  export { CodeGroup } from "./mdx/CodeGroup.tsx";
16
17
  export { Badge } from "./mdx/Badge.tsx";
17
18
  export { Frame } from "./mdx/Frame.tsx";
@@ -28,6 +29,11 @@ export { ImageZoom } from "./mdx/ImageZoom.tsx";
28
29
  export { Video } from "./mdx/Video.tsx";
29
30
  export { ApiPlayground } from "./mdx/ApiPlayground.tsx";
30
31
  export { ApiEndpoint } from "./mdx/ApiEndpoint.tsx";
32
+ export { Card, CardGroup } from "./mdx/Card.tsx";
33
+ export { CodeItem } from "./mdx/CodeItem.tsx";
34
+ export { ApiParams } from "./mdx/ApiParams.tsx";
35
+ export { ApiParam } from "./mdx/ApiParam.tsx";
36
+ export { ApiResponse } from "./mdx/ApiResponse.tsx";
31
37
 
32
38
  export { VersionSwitcher } from "./VersionSwitcher.tsx";
33
39
 
@@ -0,0 +1,27 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiParamProps {
4
+ name: string;
5
+ type: string;
6
+ required?: boolean;
7
+ description?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ export function ApiParam({ name, type, required = false, description, children }: ApiParamProps) {
12
+ return (
13
+ <div className="flex flex-col gap-1 py-3 border-b border-[var(--bd-border)] last:border-b-0">
14
+ <div className="flex items-center gap-2">
15
+ <code className="text-sm font-semibold text-[var(--bd-text)]">{name}</code>
16
+ <span className="text-xs text-[var(--bd-text-secondary)]">{type}</span>
17
+ {required && (
18
+ <span className="px-1.5 py-0.5 text-xs font-medium text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30 rounded">
19
+ required
20
+ </span>
21
+ )}
22
+ </div>
23
+ {description && <p className="text-sm text-[var(--bd-text-secondary)]">{description}</p>}
24
+ {children}
25
+ </div>
26
+ );
27
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiParamsProps {
4
+ title?: string;
5
+ children?: ReactNode;
6
+ }
7
+
8
+ export function ApiParams({ title = "Parameters", children }: ApiParamsProps) {
9
+ return (
10
+ <div className="my-4 px-2">
11
+ <h4 className="text-sm font-semibold text-[var(--bd-text)] mb-2">{title}</h4>
12
+ <div className="border border-[var(--bd-border)] rounded-lg overflow-hidden">
13
+ <div className="divide-y divide-[var(--bd-border)] px-4">{children}</div>
14
+ </div>
15
+ </div>
16
+ );
17
+ }
@@ -0,0 +1,32 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface ApiResponseProps {
4
+ status: number;
5
+ description?: string;
6
+ children?: ReactNode;
7
+ }
8
+
9
+ const statusColors: Record<number, string> = {
10
+ 200: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
11
+ 201: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
12
+ 204: "bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400",
13
+ 400: "bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400",
14
+ 401: "bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",
15
+ 403: "bg-orange-100 dark:bg-orange-900/30 text-orange-700 dark:text-orange-400",
16
+ 404: "bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",
17
+ 500: "bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",
18
+ };
19
+
20
+ export function ApiResponse({ status, description, children }: ApiResponseProps) {
21
+ const statusColor = statusColors[status] || "bg-gray-100 dark:bg-gray-900/30 text-gray-700 dark:text-gray-400";
22
+
23
+ return (
24
+ <div className="my-4 px-2">
25
+ <div className="flex items-center gap-2 mb-2">
26
+ <span className={`px-2 py-0.5 text-xs font-bold rounded ${statusColor}`}>{status}</span>
27
+ {description && <span className="text-sm text-[var(--bd-text-secondary)]">{description}</span>}
28
+ </div>
29
+ <div className="border border-[var(--bd-border)] rounded-lg overflow-hidden px-2">{children}</div>
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,104 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ type CalloutType = "info" | "warning" | "tip" | "danger" | "note";
4
+
5
+ interface CalloutProps {
6
+ type?: CalloutType;
7
+ title?: string;
8
+ children?: ReactNode;
9
+ }
10
+
11
+ const styles: Record<CalloutType, { container: string; iconBg: string; icon: string; title: string }> = {
12
+ info: {
13
+ container: "bg-blue-50/70 dark:bg-blue-500/10 border-l-blue-500",
14
+ iconBg: "bg-blue-100 dark:bg-blue-500/20",
15
+ icon: "text-blue-600 dark:text-blue-400",
16
+ title: "text-blue-900 dark:text-blue-200",
17
+ },
18
+ note: {
19
+ container: "bg-gray-50/70 dark:bg-gray-500/10 border-l-gray-400",
20
+ iconBg: "bg-gray-100 dark:bg-gray-500/20",
21
+ icon: "text-gray-600 dark:text-gray-400",
22
+ title: "text-gray-900 dark:text-gray-200",
23
+ },
24
+ warning: {
25
+ container: "bg-orange-50/70 dark:bg-orange-500/10 border-l-orange-500",
26
+ iconBg: "bg-orange-100 dark:bg-orange-500/20",
27
+ icon: "text-orange-600 dark:text-orange-400",
28
+ title: "text-orange-900 dark:text-orange-200",
29
+ },
30
+ tip: {
31
+ container: "bg-green-50/70 dark:bg-green-500/10 border-l-green-500",
32
+ iconBg: "bg-green-100 dark:bg-green-500/20",
33
+ icon: "text-green-600 dark:text-green-400",
34
+ title: "text-green-900 dark:text-green-200",
35
+ },
36
+ danger: {
37
+ container: "bg-red-50/70 dark:bg-red-500/10 border-l-red-500",
38
+ iconBg: "bg-red-100 dark:bg-red-500/20",
39
+ icon: "text-red-600 dark:text-red-400",
40
+ title: "text-red-900 dark:text-red-200",
41
+ },
42
+ };
43
+
44
+ const icons: Record<CalloutType, ReactNode> = {
45
+ info: (
46
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
47
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
48
+ </svg>
49
+ ),
50
+ note: (
51
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
52
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
53
+ </svg>
54
+ ),
55
+ warning: (
56
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
57
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
58
+ </svg>
59
+ ),
60
+ tip: (
61
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
62
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" />
63
+ </svg>
64
+ ),
65
+ danger: (
66
+ <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
67
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
68
+ </svg>
69
+ ),
70
+ };
71
+
72
+ const defaultTitles: Record<CalloutType, string> = {
73
+ info: "Info",
74
+ note: "Note",
75
+ warning: "Warning",
76
+ tip: "Tip",
77
+ danger: "Danger",
78
+ };
79
+
80
+ export function Callout({ type = "info", title, children }: CalloutProps) {
81
+ const style = styles[type];
82
+ const icon = icons[type];
83
+ const displayTitle = title || defaultTitles[type];
84
+
85
+ return (
86
+ <div className={`not-prose my-5 rounded-lg border-l-4 overflow-hidden ${style.container}`}>
87
+ <div className="px-4 py-3.5">
88
+ <div className="flex items-start gap-3">
89
+ <div className={`shrink-0 flex items-center justify-center w-6 h-6 rounded-md ${style.iconBg}`}>
90
+ <div className={style.icon}>{icon}</div>
91
+ </div>
92
+ <div className="flex-1 min-w-0">
93
+ {displayTitle && (
94
+ <p className={`font-semibold text-[13px] mb-1 ${style.title}`}>{displayTitle}</p>
95
+ )}
96
+ <div className="text-[13px] text-zinc-700 dark:text-zinc-300 leading-relaxed [&>p]:m-0 [&>p+p]:mt-1.5">
97
+ {children}
98
+ </div>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ </div>
103
+ );
104
+ }
@@ -0,0 +1,66 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface CardProps {
4
+ title: string;
5
+ icon?: string;
6
+ href?: string;
7
+ children?: ReactNode;
8
+ }
9
+
10
+ export function Card({ title, icon, href, children }: CardProps) {
11
+ const Tag = href ? "a" : "div";
12
+ return (
13
+ <Tag
14
+ href={href}
15
+ className={`card-component not-prose group block p-4 rounded-lg border border-[var(--bd-border)] bg-[var(--bd-bg)] no-underline ${
16
+ href
17
+ ? "cursor-pointer hover:border-primary-300 dark:hover:border-primary-600 hover:shadow-md transition-all duration-200"
18
+ : ""
19
+ }`}
20
+ >
21
+ <div className="flex flex-col gap-3">
22
+ {icon && (
23
+ <div className="flex items-center justify-center w-10 h-10 rounded-lg bg-[var(--bd-bg-subtle)] group-hover:bg-primary-50 dark:group-hover:bg-primary-950/50 transition-colors">
24
+ <span className="text-xl">{icon}</span>
25
+ </div>
26
+ )}
27
+ <div className="flex-1 min-w-0">
28
+ <div className="flex items-center gap-2">
29
+ <h3 className="font-semibold text-[var(--bd-text)] group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors">
30
+ {title}
31
+ </h3>
32
+ {href && (
33
+ <svg
34
+ className="w-4 h-4 text-[var(--bd-text-muted)] opacity-0 -translate-x-2 group-hover:opacity-100 group-hover:translate-x-0 transition-all duration-200"
35
+ fill="none"
36
+ stroke="currentColor"
37
+ viewBox="0 0 24 24"
38
+ >
39
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" />
40
+ </svg>
41
+ )}
42
+ </div>
43
+ <div className="mt-1 text-sm text-[var(--bd-text-secondary)] group-hover:text-[var(--bd-text)] leading-relaxed transition-colors">
44
+ {children}
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </Tag>
49
+ );
50
+ }
51
+
52
+ interface CardGroupProps {
53
+ cols?: 1 | 2 | 3 | 4;
54
+ children?: ReactNode;
55
+ }
56
+
57
+ const gridCols: Record<number, string> = {
58
+ 1: "grid-cols-1",
59
+ 2: "grid-cols-1 sm:grid-cols-2",
60
+ 3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
61
+ 4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
62
+ };
63
+
64
+ export function CardGroup({ cols = 2, children }: CardGroupProps) {
65
+ return <div className={`not-prose grid gap-5 my-6 ${gridCols[cols]}`}>{children}</div>;
66
+ }
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ interface CodeItemProps {
4
+ title?: string;
5
+ children?: ReactNode;
6
+ }
7
+
8
+ export function CodeItem({ title = "", children }: CodeItemProps) {
9
+ return (
10
+ <div className="code-item" data-title={title}>
11
+ {children}
12
+ </div>
13
+ );
14
+ }
package/src/index.ts CHANGED
@@ -1,152 +1,2 @@
1
- import type { AstroIntegration } from "astro";
2
- import type { ThemeExport, ResolvedBarodocConfig } from "@barodoc/core";
3
- import mdx from "@astrojs/mdx";
4
- import react from "@astrojs/react";
5
- import tailwindcss from "@tailwindcss/vite";
6
- import remarkMath from "remark-math";
7
- import rehypeKatex from "rehype-katex";
8
-
9
- export interface DocsThemeOptions {
10
- customCss?: string[];
11
- }
12
-
13
- /** HAST node with optional children and properties */
14
- interface HastNode {
15
- type: string;
16
- children?: HastNode[];
17
- properties?: Record<string, unknown>;
18
- tagName?: string;
19
- value?: string;
20
- }
21
-
22
- function getTextContent(node: HastNode): string {
23
- if (node.type === "text") return node.value ?? "";
24
- if (node.children?.length) return node.children.map(getTextContent).join("");
25
- return "";
26
- }
27
-
28
- function isEmptyLine(node: HastNode): boolean {
29
- if (node.type !== "element" || node.tagName !== "span") return false;
30
- const cls = node.properties?.className;
31
- const isLine =
32
- Array.isArray(cls) && cls.some((c) => c === "line" || (typeof c === "string" && c.includes("line")));
33
- if (!isLine) return false;
34
- return /^\s*$/.test(getTextContent(node));
35
- }
36
-
37
- /** Removes leading and trailing empty span.line so only the code area is visible. */
38
- function createTrimEmptyLinesTransformer() {
39
- return {
40
- name: "barodoc-trim-empty-lines",
41
- code(node: HastNode) {
42
- const lines = node.children;
43
- if (!lines?.length) return;
44
- let start = 0;
45
- let end = lines.length;
46
- while (start < end && isEmptyLine(lines[start])) start++;
47
- while (end > start && isEmptyLine(lines[end - 1])) end--;
48
- node.children = lines.slice(start, end);
49
- },
50
- };
51
- }
52
-
53
- function createLineNumbersTransformer() {
54
- return {
55
- name: "barodoc-line-numbers",
56
- pre(node: { properties?: Record<string, unknown> }) {
57
- (this as { addClassToHast: (node: unknown, cls: string) => void }).addClassToHast(node, "line-numbers");
58
- },
59
- };
60
- }
61
-
62
- function createThemeIntegration(
63
- config: ResolvedBarodocConfig,
64
- options?: DocsThemeOptions
65
- ): AstroIntegration {
66
- const lineNumbers = config?.lineNumbers === true;
67
- return {
68
- name: "@barodoc/theme-docs",
69
- hooks: {
70
- "astro:config:setup": async ({ updateConfig, injectRoute, logger }) => {
71
- logger.info("Setting up Barodoc docs theme...");
72
-
73
- // Inject routes
74
- injectRoute({
75
- pattern: "/",
76
- entrypoint: "@barodoc/theme-docs/pages/index.astro",
77
- });
78
-
79
- injectRoute({
80
- pattern: "/docs/[...slug]",
81
- entrypoint: "@barodoc/theme-docs/pages/docs/[...slug].astro",
82
- });
83
-
84
- // Blog routes
85
- if (config?.blog?.enabled !== false) {
86
- injectRoute({
87
- pattern: "/blog",
88
- entrypoint: "@barodoc/theme-docs/pages/blog/index.astro",
89
- });
90
- injectRoute({
91
- pattern: "/blog/[...slug]",
92
- entrypoint: "@barodoc/theme-docs/pages/blog/[...slug].astro",
93
- });
94
- }
95
-
96
- // Changelog route
97
- injectRoute({
98
- pattern: "/changelog",
99
- entrypoint: "@barodoc/theme-docs/pages/changelog/index.astro",
100
- });
101
-
102
- // Update Astro config with integrations and Vite plugins
103
- updateConfig({
104
- integrations: [
105
- mdx({
106
- remarkPlugins: [remarkMath],
107
- rehypePlugins: [rehypeKatex],
108
- }),
109
- react(),
110
- ],
111
- vite: {
112
- plugins: [tailwindcss()],
113
- optimizeDeps: {
114
- include: ["mermaid"],
115
- },
116
- ssr: {
117
- noExternal: [],
118
- },
119
- resolve: {
120
- dedupe: ["react", "react-dom"],
121
- },
122
- },
123
- markdown: {
124
- shikiConfig: {
125
- themes: {
126
- light: "github-light",
127
- dark: "github-dark",
128
- },
129
- transformers: [
130
- createTrimEmptyLinesTransformer(),
131
- ...(lineNumbers ? [createLineNumbersTransformer()] : []),
132
- ],
133
- },
134
- },
135
- });
136
-
137
- logger.info("Docs theme routes injected");
138
- },
139
- },
140
- };
141
- }
142
-
143
- export default function docsTheme(options?: DocsThemeOptions): ThemeExport {
144
- return {
145
- name: "@barodoc/theme-docs",
146
- integration: (config) => createThemeIntegration(config, options),
147
- styles: options?.customCss || [],
148
- };
149
- }
150
-
151
- // Re-export components for easy access
1
+ // Component exports - safe for client-side bundling
152
2
  export * from "./components/index.ts";
@@ -2,6 +2,7 @@
2
2
  import BaseLayout from "./BaseLayout.astro";
3
3
  import Header from "../components/Header.astro";
4
4
  import Banner from "../components/Banner.astro";
5
+ import CodeCopy from "../components/CodeCopy.astro";
5
6
  import { defaultLocale } from "virtual:barodoc/i18n";
6
7
  import { getLocaleFromPath } from "@barodoc/core";
7
8
 
@@ -10,12 +11,13 @@ interface Props {
10
11
  description?: string;
11
12
  date?: Date;
12
13
  author?: string;
14
+ avatar?: string;
13
15
  image?: string;
14
16
  tags?: string[];
15
17
  readingTime?: string;
16
18
  }
17
19
 
18
- const { title, description, date, author, image, tags = [], readingTime } = Astro.props;
20
+ const { title, description, date, author, avatar, image, tags = [], readingTime } = Astro.props;
19
21
  const currentPath = Astro.url.pathname;
20
22
  const i18nConfig = { defaultLocale, locales: [defaultLocale] };
21
23
  const currentLocale = getLocaleFromPath(currentPath, i18nConfig);
@@ -47,7 +49,18 @@ const currentLocale = getLocaleFromPath(currentPath, i18nConfig);
47
49
  </p>
48
50
  )}
49
51
  <div class="mt-4 flex items-center gap-3 text-sm text-[var(--bd-text-muted)]">
50
- {author && <span>{author}</span>}
52
+ {author && (
53
+ <span class="flex items-center gap-2">
54
+ {avatar && (
55
+ <img
56
+ src={avatar}
57
+ alt={author}
58
+ class="w-6 h-6 rounded-full object-cover ring-1 ring-[var(--bd-border)]"
59
+ />
60
+ )}
61
+ <span>{author}</span>
62
+ </span>
63
+ )}
51
64
  {author && date && <span class="text-[var(--bd-border)]">&middot;</span>}
52
65
  {date && (
53
66
  <time datetime={date.toISOString()}>
@@ -75,6 +88,7 @@ const currentLocale = getLocaleFromPath(currentPath, i18nConfig);
75
88
  <div class="prose prose-gray dark:prose-invert max-w-none">
76
89
  <slot />
77
90
  </div>
91
+ <CodeCopy />
78
92
 
79
93
  <!-- Back to blog -->
80
94
  <div class="mt-12 pt-8 border-t border-[var(--bd-border)]">
@@ -31,6 +31,7 @@ const readTime = readingTime(post.body ?? "");
31
31
  description={post.data.description || post.data.excerpt}
32
32
  date={post.data.date ? new Date(post.data.date) : undefined}
33
33
  author={post.data.author}
34
+ avatar={post.data.avatar}
34
35
  image={post.data.image}
35
36
  tags={post.data.tags}
36
37
  readingTime={readTime.text}
@@ -74,7 +74,18 @@ const sortedPosts = posts.sort((a, b) => {
74
74
  </p>
75
75
  )}
76
76
  <div class="mt-auto pt-2 flex items-center gap-2 text-xs text-[var(--bd-text-muted)]">
77
- {post.data.author && <span>{post.data.author}</span>}
77
+ {post.data.author && (
78
+ <span class="flex items-center gap-1.5">
79
+ {post.data.avatar && (
80
+ <img
81
+ src={post.data.avatar}
82
+ alt={post.data.author}
83
+ class="w-4 h-4 rounded-full object-cover"
84
+ />
85
+ )}
86
+ <span>{post.data.author}</span>
87
+ </span>
88
+ )}
78
89
  {post.data.author && post.data.date && <span>&middot;</span>}
79
90
  {post.data.date && (
80
91
  <time datetime={new Date(post.data.date).toISOString()}>
@@ -125,7 +125,7 @@ breadcrumbs.push({ label: doc.data.title });
125
125
  lastUpdated={lastUpdated}
126
126
  breadcrumbs={breadcrumbs}
127
127
  readingTime={readTime.text}
128
- filePath={doc.id}
128
+ filePath={`src/content/docs/${doc.id}`}
129
129
  >
130
130
  {category && (
131
131
  <p class="text-xs font-semibold uppercase tracking-widest text-primary-600 dark:text-primary-400 mb-3">
@@ -43,10 +43,24 @@ const features = [
43
43
  <header class="sticky top-0 z-50 border-b border-[var(--bd-border)] bg-[var(--bd-bg)]/95 backdrop-blur-md">
44
44
  <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
45
45
  <div class="flex h-16 items-center justify-between">
46
- <a href="/" class="flex items-center gap-2.5 font-semibold text-[var(--bd-text)]">
47
- {config.logo && <img src={config.logo} alt={config.name} class="h-7 w-7" />}
48
- <span class="text-lg">{config.name}</span>
49
- </a>
46
+ <div class="flex items-center gap-6">
47
+ <a href="/" class="flex items-center gap-2.5 font-semibold text-[var(--bd-text)]">
48
+ {config.logo && <img src={config.logo} alt={config.name} class="h-7 w-7" />}
49
+ <span class="text-lg">{config.name}</span>
50
+ </a>
51
+ {config.tabs && config.tabs.length > 0 && (
52
+ <nav class="hidden md:flex items-center gap-1">
53
+ {config.tabs.map((tab: { label: string; href: string }) => (
54
+ <a
55
+ href={tab.href}
56
+ class="px-3 py-1.5 text-sm font-medium rounded-lg text-[var(--bd-text-secondary)] hover:text-[var(--bd-text)] hover:bg-[var(--bd-bg-subtle)] transition-colors"
57
+ >
58
+ {tab.label}
59
+ </a>
60
+ ))}
61
+ </nav>
62
+ )}
63
+ </div>
50
64
  <div class="flex items-center gap-2">
51
65
  {config.topbar?.github && (
52
66
  <a
@@ -983,6 +983,22 @@
983
983
  margin-left: 0;
984
984
  }
985
985
 
986
+ .bd-contributor-count {
987
+ display: inline-flex;
988
+ align-items: center;
989
+ justify-content: center;
990
+ width: 1.75rem;
991
+ height: 1.75rem;
992
+ border-radius: 9999px;
993
+ border: 2px solid var(--bd-bg);
994
+ margin-left: -0.375rem;
995
+ background: var(--bd-bg-subtle);
996
+ color: var(--bd-text-muted);
997
+ font-size: 0.6875rem;
998
+ font-weight: 600;
999
+ cursor: default;
1000
+ }
1001
+
986
1002
  /* ==========================================================================
987
1003
  Version Switcher
988
1004
  ========================================================================== */
package/src/theme.ts ADDED
@@ -0,0 +1,145 @@
1
+ import type { AstroIntegration } from "astro";
2
+ import type { ThemeExport, ResolvedBarodocConfig } from "@barodoc/core";
3
+ import mdx from "@astrojs/mdx";
4
+ import react from "@astrojs/react";
5
+ import tailwindcss from "@tailwindcss/vite";
6
+ import remarkMath from "remark-math";
7
+ import rehypeKatex from "rehype-katex";
8
+
9
+ export interface DocsThemeOptions {
10
+ customCss?: string[];
11
+ }
12
+
13
+ /** HAST node with optional children and properties */
14
+ interface HastNode {
15
+ type: string;
16
+ children?: HastNode[];
17
+ properties?: Record<string, unknown>;
18
+ tagName?: string;
19
+ value?: string;
20
+ }
21
+
22
+ function getTextContent(node: HastNode): string {
23
+ if (node.type === "text") return node.value ?? "";
24
+ if (node.children?.length) return node.children.map(getTextContent).join("");
25
+ return "";
26
+ }
27
+
28
+ function isEmptyLine(node: HastNode): boolean {
29
+ if (node.type !== "element" || node.tagName !== "span") return false;
30
+ const cls = node.properties?.className;
31
+ const isLine =
32
+ Array.isArray(cls) && cls.some((c) => c === "line" || (typeof c === "string" && c.includes("line")));
33
+ if (!isLine) return false;
34
+ return /^\s*$/.test(getTextContent(node));
35
+ }
36
+
37
+ /** Removes leading and trailing empty span.line so only the code area is visible. */
38
+ function createTrimEmptyLinesTransformer() {
39
+ return {
40
+ name: "barodoc-trim-empty-lines",
41
+ code(node: HastNode) {
42
+ const lines = node.children;
43
+ if (!lines?.length) return;
44
+ let start = 0;
45
+ let end = lines.length;
46
+ while (start < end && isEmptyLine(lines[start])) start++;
47
+ while (end > start && isEmptyLine(lines[end - 1])) end--;
48
+ node.children = lines.slice(start, end);
49
+ },
50
+ };
51
+ }
52
+
53
+ function createLineNumbersTransformer() {
54
+ return {
55
+ name: "barodoc-line-numbers",
56
+ pre(node: { properties?: Record<string, unknown> }) {
57
+ (this as { addClassToHast: (node: unknown, cls: string) => void }).addClassToHast(node, "line-numbers");
58
+ },
59
+ };
60
+ }
61
+
62
+ function createThemeIntegration(
63
+ config: ResolvedBarodocConfig,
64
+ options?: DocsThemeOptions
65
+ ): AstroIntegration {
66
+ const lineNumbers = config?.lineNumbers === true;
67
+ return {
68
+ name: "@barodoc/theme-docs",
69
+ hooks: {
70
+ "astro:config:setup": async ({ updateConfig, injectRoute, logger }) => {
71
+ logger.info("Setting up Barodoc docs theme...");
72
+
73
+ injectRoute({
74
+ pattern: "/",
75
+ entrypoint: "@barodoc/theme-docs/pages/index.astro",
76
+ });
77
+
78
+ injectRoute({
79
+ pattern: "/docs/[...slug]",
80
+ entrypoint: "@barodoc/theme-docs/pages/docs/[...slug].astro",
81
+ });
82
+
83
+ if (config?.blog?.enabled !== false) {
84
+ injectRoute({
85
+ pattern: "/blog",
86
+ entrypoint: "@barodoc/theme-docs/pages/blog/index.astro",
87
+ });
88
+ injectRoute({
89
+ pattern: "/blog/[...slug]",
90
+ entrypoint: "@barodoc/theme-docs/pages/blog/[...slug].astro",
91
+ });
92
+ }
93
+
94
+ injectRoute({
95
+ pattern: "/changelog",
96
+ entrypoint: "@barodoc/theme-docs/pages/changelog/index.astro",
97
+ });
98
+
99
+ updateConfig({
100
+ integrations: [
101
+ mdx({
102
+ remarkPlugins: [remarkMath],
103
+ rehypePlugins: [rehypeKatex],
104
+ }),
105
+ react(),
106
+ ],
107
+ vite: {
108
+ plugins: [tailwindcss()],
109
+ optimizeDeps: {
110
+ include: ["mermaid"],
111
+ },
112
+ ssr: {
113
+ noExternal: [],
114
+ },
115
+ resolve: {
116
+ dedupe: ["react", "react-dom"],
117
+ },
118
+ },
119
+ markdown: {
120
+ shikiConfig: {
121
+ themes: {
122
+ light: "github-light",
123
+ dark: "github-dark",
124
+ },
125
+ transformers: [
126
+ createTrimEmptyLinesTransformer(),
127
+ ...(lineNumbers ? [createLineNumbersTransformer()] : []),
128
+ ],
129
+ },
130
+ },
131
+ });
132
+
133
+ logger.info("Docs theme routes injected");
134
+ },
135
+ },
136
+ };
137
+ }
138
+
139
+ export default function docsTheme(options?: DocsThemeOptions): ThemeExport {
140
+ return {
141
+ name: "@barodoc/theme-docs",
142
+ integration: (config) => createThemeIntegration(config, options),
143
+ styles: options?.customCss || [],
144
+ };
145
+ }