Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(web): turn shared notebooks into a navigable website

tianma-if62390b218f16
diff --git a/apps/web/src/components/PublicNotebookSharePage.tsx b/apps/web/src/components/PublicNotebookSharePage.tsx
index c725e0d1..39acf1f4 100644
--- a/apps/web/src/components/PublicNotebookSharePage.tsx
+++ b/apps/web/src/components/PublicNotebookSharePage.tsx
@@ -1,77 +1,13 @@
import { useQuery } from "@tanstack/react-query";
-import { BookOpen, FileText, Folder, LoaderCircle } from "lucide-react";
+import { LoaderCircle } from "lucide-react";
import { useEffect, useMemo } from "react";
import { useTranslation } from "react-i18next";
-import { Link, useParams } from "react-router";
-import type { PublicNotebookShare } from "@edgeever/shared";
+import { useParams } from "react-router";
import { api } from "@/lib/api";
import { Button } from "@/components/ui/button";
import { PublicShareArticle } from "./PublicSharePage";
-
-const NotebookContents = ({
- share,
- token,
- selectedId,
-}: {
- share: PublicNotebookShare;
- token: string;
- selectedId?: string;
-}) => {
- const { t } = useTranslation();
- const tree = useMemo(() => {
- const children = new Map<string | null, PublicNotebookShare["notebooks"]>();
- const memos = new Map<string, PublicNotebookShare["memos"]>();
- for (const notebook of share.notebooks) {
- const siblings = children.get(notebook.parentId) ?? [];
- siblings.push(notebook);
- children.set(notebook.parentId, siblings);
- }
- for (const memo of share.memos) {
- const siblings = memos.get(memo.notebookId) ?? [];
- siblings.push(memo);
- memos.set(memo.notebookId, siblings);
- }
- return { children, memos };
- }, [share]);
- const renderNotebook = (id: string, visited: ReadonlySet<string>) => {
- if (visited.has(id)) return null;
- const path = new Set(visited).add(id);
- return (
- <ul className="space-y-1 border-l border-slate-200 pl-3">
- {(tree.memos.get(id) ?? []).map((memo) => (
- <li key={memo.id}>
- <Link
- to={`/share/notebook/${encodeURIComponent(token)}/${encodeURIComponent(memo.id)}`}
- aria-current={selectedId === memo.id ? "page" : undefined}
- className={`flex items-start gap-2 rounded-md px-2 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-emerald-500 ${selectedId === memo.id ? "bg-emerald-50 font-medium text-emerald-800" : "text-slate-600 hover:bg-slate-100"}`}
- >
- <FileText className="mt-0.5 h-4 w-4 shrink-0" />
- <span className="break-words">
- {memo.title?.trim() || t("common.untitledMemo")}
- </span>
- </Link>
- </li>
- ))}
- {(tree.children.get(id) ?? []).map((notebook) => (
- <li key={notebook.id}>
- <details open>
- <summary className="flex cursor-pointer items-center gap-2 px-2 py-2 text-sm font-medium text-slate-800">
- <Folder className="h-4 w-4 shrink-0" />
- <span className="break-words">{notebook.name}</span>
- </summary>
- {renderNotebook(notebook.id, path)}
- </details>
- </li>
- ))}
- </ul>
- );
- };
- return (
- <nav aria-label={t("sharing.notebookContents")}>
- {renderNotebook(share.notebookId, new Set())}
- </nav>
- );
-};
+import { PublicNotebookSite } from "./PublicNotebookSite";
+import { withEnvironmentTitlePrefix } from "@/lib/environment-title";
export const PublicNotebookSharePage = () => {
const { t } = useTranslation();
@@ -108,7 +44,13 @@ export const PublicNotebookSharePage = () => {
robots.content = "noindex,nofollow,noarchive";
document.head.appendChild(robots);
const previous = document.title;
- document.title = `${note?.title?.trim() || share?.name || t("sharing.notebookTitle")} · EdgeEver`;
+ document.title = withEnvironmentTitlePrefix(
+ `${note?.title?.trim() || share?.name || t("sharing.notebookTitle")} · EdgeEver`,
+ {
+ development: import.meta.env.DEV,
+ profile: __EDGEEVER_DEVELOPMENT_PROFILE__,
+ },
+ );
return () => {
robots.remove();
document.title = previous;
@@ -136,39 +78,14 @@ export const PublicNotebookSharePage = () => {
</main>
);
return (
- <main className="min-h-[100dvh] bg-slate-50 lg:flex lg:items-start">
- <aside className="border-b border-slate-200 bg-card p-4 lg:sticky lg:top-0 lg:max-h-[100dvh] lg:w-72 lg:shrink-0 lg:overflow-auto lg:border-b-0 lg:border-r">
- <Link
- to={`/share/notebook/${encodeURIComponent(token)}`}
- className="mb-4 flex items-center gap-2 break-words text-lg font-semibold text-slate-900"
- >
- <BookOpen className="h-5 w-5 shrink-0 text-emerald-700" />
- {share.name}
- </Link>
- <details className="lg:hidden">
- <summary className="cursor-pointer py-2 text-sm font-medium">
- {t("sharing.notebookContents")}
- </summary>
- <NotebookContents share={share} token={token} selectedId={memoId} />
- </details>
- <div className="hidden lg:block">
- <NotebookContents share={share} token={token} selectedId={memoId} />
- </div>
- </aside>
- <div className="min-w-0 flex-1">
- {!memoId ? (
- <section className="mx-auto max-w-3xl p-8">
- <h1 className="text-3xl font-bold">{share.name}</h1>
- <p className="my-5 text-slate-500">
- {t(
- share.memos.length
- ? "sharing.notebookWelcome"
- : "sharing.notebookEmpty",
- )}
- </p>
- <NotebookContents share={share} token={token} />
- </section>
- ) : memo.isPending ? (
+ <PublicNotebookSite
+ key={token}
+ share={share}
+ token={token}
+ selectedId={memoId}
+ >
+ {memoId &&
+ (memo.isPending ? (
<div className="flex min-h-60 items-center justify-center">
<LoaderCircle
className="h-6 w-6 animate-spin"
@@ -176,9 +93,15 @@ export const PublicNotebookSharePage = () => {
/>
</div>
) : note && share.memos.some((item) => item.id === memoId) ? (
- <PublicShareArticle share={note} token={token} access={access} />
+ <PublicShareArticle
+ key={memoId}
+ share={note}
+ token={token}
+ access={access}
+ layout="site"
+ />
) : (
- <section className="space-y-4 p-8">
+ <section className="mx-auto max-w-4xl space-y-4 px-5 py-12 sm:px-10">
<h1 className="text-xl font-semibold">
{t("sharing.publicUnavailable")}
</h1>
@@ -189,8 +112,7 @@ export const PublicNotebookSharePage = () => {
{t("sharing.retry")}
</Button>
</section>
- )}
- </div>
- </main>
+ ))}
+ </PublicNotebookSite>
);
};
diff --git a/apps/web/src/components/PublicNotebookSite.tsx b/apps/web/src/components/PublicNotebookSite.tsx
new file mode 100644
index 00000000..3959e9a3
--- /dev/null
+++ b/apps/web/src/components/PublicNotebookSite.tsx
@@ -0,0 +1,672 @@
+import type { PublicNotebookShare } from "@edgeever/shared";
+import {
+ ArrowLeft,
+ ArrowRight,
+ BookOpen,
+ ChevronRight,
+ Menu,
+ PanelLeftClose,
+ PanelLeftOpen,
+ Search,
+ X,
+} from "lucide-react";
+import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { Link, useLocation } from "react-router";
+import { Button } from "@/components/ui/button";
+import {
+ Collapsible,
+ CollapsibleContent,
+ CollapsibleTrigger,
+} from "@/components/ui/collapsible";
+import {
+ Drawer,
+ DrawerClose,
+ DrawerContent,
+ DrawerDescription,
+ DrawerHeader,
+ DrawerTitle,
+ DrawerTrigger,
+} from "@/components/ui/drawer";
+import { Input } from "@/components/ui/input";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipProvider,
+ TooltipTrigger,
+} from "@/components/ui/tooltip";
+import { cn } from "@/lib/utils";
+
+type Notebook = PublicNotebookShare["notebooks"][number];
+type Memo = PublicNotebookShare["memos"][number];
+type Section = { notebook: Notebook; path: Notebook[]; memos: Memo[] };
+
+const linkClass =
+ "rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-900/20 focus-visible:ring-offset-2";
+
+const NavigationNotes = ({
+ memos,
+ selectedId,
+ href,
+ onNavigate,
+}: {
+ memos: Memo[];
+ selectedId?: string;
+ href: (id: string) => string;
+ onNavigate: () => void;
+}) => {
+ const { t } = useTranslation();
+ const selected = useRef<HTMLAnchorElement>(null);
+ useEffect(() => {
+ selected.current?.scrollIntoView({ block: "nearest" });
+ }, [selectedId]);
+ return (
+ <ul className="space-y-0.5">
+ {memos.map((memo) => {
+ const title = memo.title?.trim() || t("common.untitledMemo");
+ return (
+ <li key={memo.id}>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Link
+ ref={selectedId === memo.id ? selected : undefined}
+ to={href(memo.id)}
+ onClick={onNavigate}
+ aria-current={selectedId === memo.id ? "page" : undefined}
+ className={cn(
+ linkClass,
+ "block px-3 py-2 text-[13px] leading-5 transition-colors",
+ selectedId === memo.id
+ ? "bg-slate-100 font-medium text-slate-950"
+ : "text-slate-500 hover:bg-slate-100/70 hover:text-slate-900",
+ )}
+ >
+ <span className="line-clamp-2 break-words">{title}</span>
+ </Link>
+ </TooltipTrigger>
+ <TooltipContent side="right" className="max-w-72 break-words">
+ {title}
+ </TooltipContent>
+ </Tooltip>
+ </li>
+ );
+ })}
+ </ul>
+ );
+};
+
+const NavigationSection = ({
+ section,
+ selectedId,
+ containsSelection,
+ href,
+ onNavigate,
+}: {
+ section: Section;
+ selectedId?: string;
+ containsSelection: boolean;
+ href: (id: string) => string;
+ onNavigate: () => void;
+}) => {
+ const [open, setOpen] = useState(containsSelection);
+ useEffect(() => {
+ if (containsSelection) setOpen(true);
+ }, [selectedId, containsSelection]);
+ return (
+ <Collapsible open={open} onOpenChange={setOpen} className="mt-5">
+ <CollapsibleTrigger
+ className={cn(
+ linkClass,
+ "group flex w-full items-center justify-between gap-3 px-3 py-2 text-left text-[13px] font-semibold text-slate-900 hover:bg-slate-100/70",
+ )}
+ >
+ <span className="min-w-0 break-words">
+ {section.path
+ .slice(1)
+ .map((item) => item.name)
+ .join(" / ")}
+ </span>
+ <ChevronRight className="size-3.5 shrink-0 text-slate-400 transition-transform group-data-[state=open]:rotate-90" />
+ </CollapsibleTrigger>
+ <CollapsibleContent className="pt-1">
+ <NavigationNotes
+ memos={section.memos}
+ selectedId={selectedId}
+ href={href}
+ onNavigate={onNavigate}
+ />
+ </CollapsibleContent>
+ </Collapsible>
+ );
+};
+
+const NoteTitle = ({ memo }: { memo: Memo }) => {
+ const { t } = useTranslation();
+ return (
+ <span className="min-w-0 break-words">
+ {memo.title?.trim() || t("common.untitledMemo")}
+ </span>
+ );
+};
+
+const HomepageContents = ({
+ sections,
+ matchingIds,
+ filtering,
+ href,
+ onNavigate,
+}: {
+ sections: Section[];
+ matchingIds: ReadonlySet<string>;
+ filtering: boolean;
+ href: (id: string) => string;
+ onNavigate: () => void;
+}) => {
+ const { t } = useTranslation();
+ const { children, visibleSections } = useMemo(() => {
+ const children = new Map<string, Section[]>();
+ const visibleSections = new Set<string>();
+ for (const section of sections) {
+ const parent = section.path.at(-2);
+ if (parent) {
+ const siblings = children.get(parent.id) ?? [];
+ siblings.push(section);
+ children.set(parent.id, siblings);
+ }
+ if (
+ !filtering ||
+ section.memos.some((memo) => matchingIds.has(memo.id))
+ ) {
+ for (const ancestor of section.path) visibleSections.add(ancestor.id);
+ }
+ }
+ return { children, visibleSections };
+ }, [sections, matchingIds, filtering]);
+ const renderContents = (section: Section, nested: boolean): ReactNode => (
+ <ul
+ className={cn(
+ "space-y-2 pl-6",
+ nested ? "mt-2 list-[circle]" : "list-disc",
+ )}
+ >
+ {section.memos
+ .filter((memo) => matchingIds.has(memo.id))
+ .map((memo) => (
+ <li key={memo.id} className="pl-1 marker:text-slate-400">
+ <Link
+ to={href(memo.id)}
+ onClick={onNavigate}
+ className={cn(
+ linkClass,
+ "break-words text-slate-700 underline decoration-slate-400 decoration-1 underline-offset-4 transition-colors hover:text-slate-950 hover:decoration-slate-900 focus-visible:text-slate-950 focus-visible:decoration-slate-900",
+ )}
+ >
+ <NoteTitle memo={memo} />
+ </Link>
+ </li>
+ ))}
+ {(children.get(section.notebook.id) ?? [])
+ .filter((child) => visibleSections.has(child.notebook.id))
+ .map((child) => (
+ <li
+ key={child.notebook.id}
+ id={`section-${child.notebook.id}`}
+ className="scroll-mt-24 pt-3 pl-1 marker:text-slate-400"
+ >
+ <span className="break-words font-semibold text-slate-900">
+ {child.notebook.name}
+ </span>
+ {(child.memos.some((memo) => matchingIds.has(memo.id)) ||
+ children
+ .get(child.notebook.id)
+ ?.some((item) => visibleSections.has(item.notebook.id))) &&
+ renderContents(child, true)}
+ </li>
+ ))}
+ </ul>
+ );
+ return (
+ <nav
+ aria-label={t("sharing.notebookContents")}
+ id={`section-${sections[0]?.notebook.id}`}
+ className="mt-9 scroll-mt-24 text-base leading-7 sm:text-[17px] sm:leading-8"
+ >
+ <h2 className="mb-6 border-b border-slate-200 pb-4 text-2xl font-semibold tracking-tight">
+ {t("sharing.notebookContents")}
+ </h2>
+ {sections[0] && renderContents(sections[0], false)}
+ </nav>
+ );
+};
+
+export const PublicNotebookSite = ({
+ share,
+ token,
+ selectedId,
+ children,
+}: {
+ share: PublicNotebookShare;
+ token: string;
+ selectedId?: string;
+ children?: ReactNode;
+}) => {
+ const { t } = useTranslation();
+ const { hash } = useLocation();
+ const [search, setSearch] = useState("");
+ const [mobileOpen, setMobileOpen] = useState(false);
+ const [sidebarOpen, setSidebarOpen] = useState(true);
+ const root = `/share/notebook/${encodeURIComponent(token)}`;
+ const href = (id: string) => `${root}/${encodeURIComponent(id)}`;
+ const sections = useMemo(() => {
+ const result: Section[] = [];
+ const notebooks = new Map(share.notebooks.map((item) => [item.id, item]));
+ const children = new Map<string, Notebook[]>();
+ const memos = new Map<string, Memo[]>();
+ for (const notebook of share.notebooks) {
+ if (!notebook.parentId) continue;
+ const siblings = children.get(notebook.parentId) ?? [];
+ siblings.push(notebook);
+ children.set(notebook.parentId, siblings);
+ }
+ for (const memo of share.memos) {
+ const siblings = memos.get(memo.notebookId) ?? [];
+ siblings.push(memo);
+ memos.set(memo.notebookId, siblings);
+ }
+ const visited = new Set<string>();
+ const visit = (notebook: Notebook, path: Notebook[]) => {
+ if (visited.has(notebook.id)) return;
+ visited.add(notebook.id);
+ const nextPath = [...path, notebook];
+ result.push({
+ notebook,
+ path: nextPath,
+ memos: memos.get(notebook.id) ?? [],
+ });
+ for (const child of children.get(notebook.id) ?? [])
+ visit(child, nextPath);
+ };
+ visit(
+ notebooks.get(share.notebookId) ?? {
+ id: share.notebookId,
+ parentId: null,
+ name: share.name,
+ },
+ [],
+ );
+ return result;
+ }, [share]);
+ const notes = useMemo(
+ () =>
+ sections.flatMap((section) =>
+ section.memos.map((memo) => ({ memo, section })),
+ ),
+ [sections],
+ );
+ const query = search.trim().toLocaleLowerCase();
+ const matches = useMemo(
+ () =>
+ notes.filter(({ memo }) =>
+ (memo.title?.trim() || t("common.untitledMemo"))
+ .toLocaleLowerCase()
+ .includes(query),
+ ),
+ [notes, query, t],
+ );
+ const matchingIds = useMemo(
+ () => new Set(matches.map(({ memo }) => memo.id)),
+ [matches],
+ );
+ const index = notes.findIndex(({ memo }) => memo.id === selectedId);
+ const current = notes[index];
+ const navigate = () => {
+ setMobileOpen(false);
+ setSearch("");
+ };
+ useEffect(() => {
+ // Reset reading position only on navigation, never on the periodic content refresh.
+ if (!selectedId && hash) {
+ try {
+ document
+ .getElementById(decodeURIComponent(hash.slice(1)))
+ ?.scrollIntoView({ block: "start", behavior: "instant" });
+ } catch {
+ // A malformed fragment must not prevent the site from rendering.
+ }
+ } else {
+ window.scrollTo({ top: 0, behavior: "instant" });
+ }
+ }, [selectedId, token, hash]);
+ const contents = (
+ <TooltipProvider delayDuration={400}>
+ <div className="flex min-h-0 flex-1 flex-col">
+ <div className="px-6 pb-4">
+ <div className="relative">
+ <Search className="pointer-events-none absolute left-3 top-2.5 size-3.5 text-slate-400" />
+ <Input
+ type="search"
+ value={search}
+ onChange={(event) => setSearch(event.target.value)}
+ placeholder={t("sharing.siteSearch")}
+ aria-label={t("sharing.siteSearch")}
+ className="h-9 border-transparent bg-slate-100/70 pl-9 pr-9 text-xs focus-visible:border-slate-300"
+ />
+ {search && (
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ className="absolute right-1.5 top-1"
+ aria-label={t("sharing.siteClearSearch")}
+ onClick={() => setSearch("")}
+ >
+ <X className="size-3.5" />
+ </Button>
+ )}
+ </div>
+ </div>
+ <nav
+ aria-label={t("sharing.notebookContents")}
+ className="min-h-0 flex-1 overflow-y-auto px-5 pb-6"
+ >
+ <Link
+ to={root}
+ onClick={navigate}
+ aria-current={!selectedId ? "page" : undefined}
+ className={cn(
+ linkClass,
+ "block px-3 py-2 text-[13px] font-medium",
+ !selectedId
+ ? "text-slate-900"
+ : "text-slate-600 hover:bg-slate-100",
+ )}
+ >
+ {t("sharing.siteHome")}
+ </Link>
+ {query ? (
+ <>
+ <p className="px-2 py-2 text-xs text-slate-500" role="status">
+ {t("sharing.siteResults", { count: matches.length })}
+ </p>
+ <ul>
+ {matches.map(({ memo, section }) => (
+ <li key={memo.id}>
+ <Link
+ to={href(memo.id)}
+ onClick={navigate}
+ className={cn(
+ linkClass,
+ "block px-3 py-2 text-[13px] leading-5 text-slate-600 hover:bg-slate-100/70",
+ )}
+ >
+ <NoteTitle memo={memo} />
+ <span className="mt-1 block text-xs text-slate-400">
+ {section.path.map((item) => item.name).join(" / ")}
+ </span>
+ </Link>
+ </li>
+ ))}
+ </ul>
+ {!matches.length && (
+ <p className="px-2 py-4 text-sm text-slate-500">
+ {t("sharing.siteNoResults")}
+ </p>
+ )}
+ </>
+ ) : (
+ <>
+ {sections[0] && (
+ <NavigationNotes
+ memos={sections[0].memos}
+ selectedId={selectedId}
+ href={href}
+ onNavigate={navigate}
+ />
+ )}
+ {sections
+ .slice(1)
+ .filter((section) => section.memos.length)
+ .map((section) => (
+ <NavigationSection
+ key={section.notebook.id}
+ section={section}
+ selectedId={selectedId}
+ containsSelection={
+ current?.section.notebook.id === section.notebook.id
+ }
+ href={href}
+ onNavigate={navigate}
+ />
+ ))}
+ </>
+ )}
+ </nav>
+ <div className="px-8 py-5 text-[11px] text-slate-400">
+ {t("sharing.sitePoweredBy")}
+ </div>
+ </div>
+ </TooltipProvider>
+ );
+ return (
+ <div
+ data-site-theme="default"
+ className="min-h-[100dvh] bg-card text-slate-900"
+ >
+ <a
+ href="#notebook-site-content"
+ className="sr-only z-[60] rounded-md bg-card p-3 focus:not-sr-only focus:fixed focus:left-4 focus:top-4"
+ >
+ {t("sharing.siteSkipToContent")}
+ </a>
+ <header className="sticky top-0 z-30 flex h-16 items-center justify-between gap-4 border-b border-slate-200 bg-card/95 px-4 backdrop-blur sm:px-6">
+ <Link
+ to={root}
+ onClick={navigate}
+ className={cn(
+ linkClass,
+ "flex min-w-0 items-center gap-3 font-semibold",
+ )}
+ >
+ <span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-slate-100 text-slate-700">
+ <BookOpen className="size-5" />
+ </span>
+ <span className="truncate">{share.name}</span>
+ </Link>
+ <div className="flex shrink-0 items-center gap-3">
+ <Button
+ variant="ghost"
+ size="icon"
+ className="hidden lg:inline-flex"
+ aria-label={t(
+ sidebarOpen
+ ? "sharing.siteHideContents"
+ : "sharing.siteShowContents",
+ )}
+ title={t(
+ sidebarOpen
+ ? "sharing.siteHideContents"
+ : "sharing.siteShowContents",
+ )}
+ aria-expanded={sidebarOpen}
+ aria-controls="notebook-site-sidebar"
+ onClick={() => setSidebarOpen((open) => !open)}
+ >
+ {sidebarOpen ? (
+ <PanelLeftClose className="size-4" />
+ ) : (
+ <PanelLeftOpen className="size-4" />
+ )}
+ </Button>
+ <span className="hidden text-xs text-slate-500 sm:block">
+ {t("sharing.readOnly")}
+ </span>
+ <Drawer
+ open={mobileOpen}
+ onOpenChange={setMobileOpen}
+ shouldScaleBackground={false}
+ >
+ <DrawerTrigger asChild>
+ <Button variant="outline" size="sm" className="lg:hidden">
+ <Menu className="size-4" />
+ {t("sharing.notebookContents")}
+ </Button>
+ </DrawerTrigger>
+ <DrawerContent className="h-[85dvh] bg-card">
+ <DrawerHeader className="relative pr-12">
+ <DrawerClose asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ aria-label={t("common.close")}
+ className="absolute right-3 top-2"
+ >
+ <X className="size-4" />
+ </Button>
+ </DrawerClose>
+ <DrawerTitle>{share.name}</DrawerTitle>
+ <DrawerDescription>
+ {t("sharing.siteNoteCount", { count: notes.length })}
+ </DrawerDescription>
+ </DrawerHeader>
+ {contents}
+ </DrawerContent>
+ </Drawer>
+ </div>
+ </header>
+ <div className="mx-auto flex max-w-[1600px] items-start">
+ <aside
+ id="notebook-site-sidebar"
+ className={cn(
+ "sticky top-16 hidden h-[calc(100dvh-4rem)] w-72 shrink-0 flex-col border-r border-slate-200/70 bg-card pt-6",
+ sidebarOpen && "lg:flex",
+ )}
+ >
+ {contents}
+ </aside>
+ <main
+ id="notebook-site-content"
+ tabIndex={-1}
+ className="min-w-0 flex-1 outline-none"
+ >
+ {!selectedId ? (
+ <div className="mx-auto max-w-5xl px-5 py-10 sm:px-10 sm:py-14">
+ <p className="mb-4 text-sm font-medium text-slate-500">
+ {t("sharing.siteNoteCount", { count: notes.length })}
+ </p>
+ <h1 className="break-words text-3xl font-bold tracking-tight sm:text-4xl">
+ {share.name}
+ </h1>
+ {!notes.length && (
+ <p className="mt-4 text-sm text-slate-500">
+ {t("sharing.notebookEmpty")}
+ </p>
+ )}
+ {query && (
+ <p className="mt-6 text-sm text-slate-500" role="status">
+ {t("sharing.siteResults", { count: matches.length })}
+ </p>
+ )}
+ {(!query || matches.length > 0) && (
+ <HomepageContents
+ sections={sections}
+ matchingIds={matchingIds}
+ filtering={Boolean(query)}
+ href={href}
+ onNavigate={navigate}
+ />
+ )}
+ {query && !matches.length && (
+ <p className="py-10 text-sm text-slate-500">
+ {t("sharing.siteNoResults")}
+ </p>
+ )}
+ </div>
+ ) : (
+ <>
+ <nav
+ aria-label={t("sharing.siteBreadcrumb")}
+ className="mx-auto flex max-w-4xl flex-wrap items-center gap-2 px-5 pt-7 text-xs leading-6 text-slate-500 sm:px-10"
+ >
+ <Link
+ to={root}
+ onClick={navigate}
+ className={cn(linkClass, "hover:text-slate-900")}
+ >
+ {t("sharing.siteHome")}
+ </Link>
+ {current?.section.path.map((notebook) => (
+ <span key={notebook.id} className="contents">
+ <ChevronRight className="size-3 shrink-0" />
+ <Link
+ to={`${root}#section-${notebook.id}`}
+ onClick={navigate}
+ className={cn(
+ linkClass,
+ "break-words hover:text-slate-900",
+ )}
+ >
+ {notebook.name}
+ </Link>
+ </span>
+ ))}
+ {current && (
+ <>
+ <ChevronRight className="size-3 shrink-0" />
+ <span
+ aria-current="page"
+ className="break-words text-slate-700"
+ >
+ <NoteTitle memo={current.memo} />
+ </span>
+ </>
+ )}
+ </nav>
+ {children}
+ {current && (
+ <nav
+ aria-label={t("sharing.siteReadingNavigation")}
+ className="mx-auto grid max-w-4xl grid-cols-2 gap-4 border-t border-slate-200 px-5 py-8 sm:px-10"
+ >
+ {notes[index - 1] ? (
+ <Link
+ to={href(notes[index - 1].memo.id)}
+ onClick={navigate}
+ className={cn(linkClass, "min-w-0 p-3 hover:bg-slate-50")}
+ >
+ <span className="mb-2 flex items-center gap-2 text-xs text-slate-500">
+ <ArrowLeft className="size-3.5" />
+ {t("sharing.sitePrevious")}
+ </span>
+ <span className="text-sm font-medium">
+ <NoteTitle memo={notes[index - 1].memo} />
+ </span>
+ </Link>
+ ) : (
+ <span />
+ )}
+ {notes[index + 1] && (
+ <Link
+ to={href(notes[index + 1].memo.id)}
+ onClick={navigate}
+ className={cn(
+ linkClass,
+ "min-w-0 p-3 text-right hover:bg-slate-50",
+ )}
+ >
+ <span className="mb-2 flex items-center justify-end gap-2 text-xs text-slate-500">
+ {t("sharing.siteNext")}
+ <ArrowRight className="size-3.5" />
+ </span>
+ <span className="text-sm font-medium">
+ <NoteTitle memo={notes[index + 1].memo} />
+ </span>
+ </Link>
+ )}
+ </nav>
+ )}
+ </>
+ )}
+ </main>
+ </div>
+ </div>
+ );
+};
diff --git a/apps/web/src/components/PublicSharePage.tsx b/apps/web/src/components/PublicSharePage.tsx
index fa94ebcf..6aff3943 100644
--- a/apps/web/src/components/PublicSharePage.tsx
+++ b/apps/web/src/components/PublicSharePage.tsx
@@ -7,6 +7,7 @@ import { Clock3, FileText, LoaderCircle, LockKeyhole, ShieldCheck } from "lucide
import { lazy, Suspense, useEffect, useMemo, useState, type CSSProperties, type FormEvent, type MouseEvent } from "react";
import { useTranslation } from "react-i18next";
import { useParams } from "react-router";
+import { cn } from "@/lib/utils";
import { ApiRequestError, api } from "@/lib/api";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -279,7 +280,17 @@ export const PublicSharePage = () => {
return <main className="min-h-[100dvh] bg-slate-50"><PublicShareArticle share={share} token={token} /></main>;
};
-export const PublicShareArticle = ({ share, token, access }: { share: PublicMemoShare; token: string; access?: ShareBodyAccess }) => {
+export const PublicShareArticle = ({
+ share,
+ token,
+ access,
+ layout = "standalone",
+}: {
+ share: PublicMemoShare;
+ token: string;
+ access?: ShareBodyAccess;
+ layout?: "standalone" | "site";
+}) => {
const { t, i18n } = useTranslation();
const publishedBodyFont = parsePublishedNoteBodyFont(share.bodyFont);
@@ -287,9 +298,14 @@ export const PublicShareArticle = ({ share, token, access }: { share: PublicMemo
if (publishedBodyFont === undefined) return undefined;
if (!publishedBodyFont) {
delete document.documentElement.dataset.editorBodyFont;
- document.documentElement.style.removeProperty("--editor-body-font-family");
+ document.documentElement.style.removeProperty(
+ "--editor-body-font-family",
+ );
} else {
- applyEditorBodyFontPreference({ choice: publishedBodyFont, customFamily: "" });
+ applyEditorBodyFontPreference({
+ choice: publishedBodyFont,
+ customFamily: "",
+ });
}
return () => {
applyEditorBodyFontPreference();
@@ -298,40 +314,99 @@ export const PublicShareArticle = ({ share, token, access }: { share: PublicMemo
const prose = resolveNoteProse(share.prose);
return (
- <div className="edgeever-public-share px-4 py-6 sm:px-8 sm:py-10">
- <article className="mx-auto max-w-4xl overflow-hidden rounded-2xl border border-slate-200 bg-card shadow-sm">
- <header className="border-b border-slate-200 px-5 py-6 sm:px-10 sm:py-8">
- <div className="mb-5 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-xs text-slate-500">
- <span className="flex shrink-0 items-center gap-1.5 font-semibold text-slate-700">
- <ShieldCheck className="h-4 w-4" /> EdgeEver · {t("sharing.readOnly")}
- </span>
+ <div
+ className={cn(
+ "edgeever-public-share",
+ layout === "site" ? "py-6 sm:py-8" : "px-4 py-6 sm:px-8 sm:py-10",
+ )}
+ >
+ <article
+ className={cn(
+ "mx-auto max-w-4xl overflow-hidden",
+ layout === "standalone" &&
+ "rounded-2xl border border-slate-200 bg-card shadow-sm",
+ )}
+ >
+ <header
+ className={cn(
+ "px-5 sm:px-10",
+ layout === "site"
+ ? "flex flex-col pb-5"
+ : "border-b border-slate-200 py-6 sm:py-8",
+ )}
+ >
+ <div
+ className={cn(
+ "flex flex-wrap items-center justify-between gap-x-4 gap-y-2 text-xs text-slate-500",
+ layout === "site" ? "order-2 mt-4" : "mb-5",
+ )}
+ >
+ {layout === "standalone" && (
+ <span className="flex shrink-0 items-center gap-1.5 font-semibold text-slate-700">
+ <ShieldCheck className="h-4 w-4" /> EdgeEver ·{" "}
+ {t("sharing.readOnly")}
+ </span>
+ )}
<span className="flex items-center gap-1.5">
<Clock3 className="h-4 w-4" />
{t("sharing.publicUpdated", {
- time: new Intl.DateTimeFormat(i18n.resolvedLanguage || i18n.language, { dateStyle: "medium", timeStyle: "short" }).format(new Date(share.updatedAt)),
+ time: new Intl.DateTimeFormat(
+ i18n.resolvedLanguage || i18n.language,
+ { dateStyle: "medium", timeStyle: "short" },
+ ).format(new Date(share.updatedAt)),
})}
</span>
</div>
- <h1 className="text-3xl font-bold tracking-tight text-slate-950 sm:text-4xl">
+ <h1
+ className={cn(
+ "break-words text-3xl font-bold tracking-tight text-slate-950 sm:text-4xl",
+ layout === "site" && "order-1",
+ )}
+ >
{share.title?.trim() || t("common.untitledMemo")}
</h1>
{share.tags.length > 0 ? (
- <div className="mt-4 flex flex-wrap gap-2">
- {share.tags.map((tag) => <span key={tag} className="rounded-full bg-slate-100 px-2.5 py-1 text-xs text-slate-600">#{tag}</span>)}
+ <div
+ className={cn(
+ "mt-4 flex flex-wrap gap-2",
+ layout === "site" && "order-3",
+ )}
+ >
+ {share.tags.map((tag) => (
+ <span
+ key={tag}
+ className="rounded-full bg-slate-100 px-2.5 py-1 text-xs text-slate-600"
+ >
+ #{tag}
+ </span>
+ ))}
</div>
) : null}
</header>
<div
- className="edgeever-editor px-1 py-4 sm:px-4 sm:py-7"
+ className={cn(
+ "edgeever-editor",
+ layout === "site" ? "py-4 sm:py-5" : "px-1 py-4 sm:px-4 sm:py-7",
+ )}
data-editor-theme="default"
data-note-palette={prose.palette}
style={noteProseCssVariables(prose) as CSSProperties}
>
{prose.customCss ? (
- <style dangerouslySetInnerHTML={{ __html: sanitizeAndScopeCss(prose.customCss) }} />
+ <style
+ dangerouslySetInnerHTML={{
+ __html: sanitizeAndScopeCss(prose.customCss),
+ }}
+ />
) : null}
<SharedDocument
- locale={(i18n.resolvedLanguage || i18n.language || "zh-CN").startsWith("en") ? "en-US" : "zh-CN"}
+ locale={
+ (i18n.resolvedLanguage || i18n.language || "zh-CN").startsWith(
+ "en",
+ )
+ ? "en-US"
+ : "zh-CN"
+ }
share={share}
token={token}
access={access}
diff --git a/apps/web/src/styles/globals.css b/apps/web/src/styles/globals.css
index 698b685e..9f9ad43d 100644
--- a/apps/web/src/styles/globals.css
+++ b/apps/web/src/styles/globals.css
@@ -510,7 +510,10 @@ body,
/* Public share pages are standalone and must scroll the document. */
html:has(.edgeever-public-share),
html:has(.edgeever-public-share) body,
-html:has(.edgeever-public-share) #root {
+html:has(.edgeever-public-share) #root,
+html:has([data-site-theme]),
+html:has([data-site-theme]) body,
+html:has([data-site-theme]) #root {
height: auto;
min-height: 100%;
overflow: auto;
@@ -1321,6 +1324,16 @@ html[data-edgeever-extension-theme] .edgeever-memo-divider {
}
}
+[data-site-theme="default"] .edgeever-public-share .ProseMirror {
+ padding-inline: 20px;
+}
+
+@media (min-width: 640px) {
+ [data-site-theme="default"] .edgeever-public-share .ProseMirror {
+ padding-inline: 40px;
+ }
+}
+
.ProseMirror .edgeever-search-match {
border-radius: 0.2rem;
background-color: var(--search-match);
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index fdac7be0..5e8c42fe 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -2550,6 +2550,22 @@ export const enUS = {
expandOutlineHeading: "Expand {{name}}",
},
sharing: {
+ siteHideContents: "Hide contents",
+ siteShowContents: "Show contents",
+ siteHome: "Home",
+ siteSearch: "Search note titles",
+ siteClearSearch: "Clear search",
+ siteNoteCount: "{{count}} notes",
+ siteWelcome: "Explore the notes and topics, and find something that interests you.",
+ siteResults: "{{count}} notes found",
+ siteNoResults: "No matching notes. Try another keyword.",
+ sitePoweredBy: "Powered by EdgeEver",
+ siteSkipToContent: "Skip to content",
+ siteBreadcrumb: "Breadcrumb",
+ siteReadingNavigation: "Reading navigation",
+ sitePrevious: "Previous",
+ siteNext: "Next",
+
notebookChoose: "Choose a notebook to share",
notebookTitle: "Share notebook",
notebookScopeHint: "All notes and attachments in this notebook and its sub-notebooks will be public. New or moved-in content is shared automatically, and saved edits appear live. Anyone with the link can view without signing in.",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index 5770d0bc..bd3c758d 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -2539,6 +2539,22 @@ export const ja = {
expandOutlineHeading: "{{name}} を開く",
},
sharing: {
+ siteHideContents: "目次を隠す",
+ siteShowContents: "目次を表示",
+ siteHome: "ホーム",
+ siteSearch: "ノートのタイトルを検索",
+ siteClearSearch: "検索をクリア",
+ siteNoteCount: "{{count}} 件のノート",
+ siteWelcome: "ノートやカテゴリから、興味のある内容を見つけてください。",
+ siteResults: "{{count}} 件のノートが見つかりました",
+ siteNoResults: "該当するノートがありません。別のキーワードをお試しください。",
+ sitePoweredBy: "Powered by EdgeEver",
+ siteSkipToContent: "本文へスキップ",
+ siteBreadcrumb: "現在の位置",
+ siteReadingNavigation: "閲覧ナビゲーション",
+ sitePrevious: "前のノート",
+ siteNext: "次のノート",
+
notebookChoose: "共有するノートブックを選択",
notebookTitle: "ノートブックを共有",
notebookScopeHint: "このノートブックとすべての子ノートブックのノートや添付ファイルが公開されます。新規・移動した内容は自動で公開され、保存した編集も反映されます。リンクがあればログインせずに閲覧できます。",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index dade383a..1ab62490 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -2539,6 +2539,22 @@ export const pl = {
expandOutlineHeading: "Rozwiń {{name}}",
},
sharing: {
+ siteHideContents: "Ukryj spis treści",
+ siteShowContents: "Pokaż spis treści",
+ siteHome: "Strona główna",
+ siteSearch: "Szukaj tytułów notatek",
+ siteClearSearch: "Wyczyść wyszukiwanie",
+ siteNoteCount: "Notatki: {{count}}",
+ siteWelcome: "Przeglądaj notatki i tematy, aby znaleźć interesujące treści.",
+ siteResults: "Znalezione notatki: {{count}}",
+ siteNoResults: "Brak pasujących notatek. Spróbuj innego słowa.",
+ sitePoweredBy: "Obsługiwane przez EdgeEver",
+ siteSkipToContent: "Przejdź do treści",
+ siteBreadcrumb: "Bieżąca lokalizacja",
+ siteReadingNavigation: "Nawigacja między notatkami",
+ sitePrevious: "Poprzednia",
+ siteNext: "Następna",
+
notebookChoose: "Wybierz notatnik do udostępnienia",
notebookTitle: "Udostępnij notatnik",
notebookScopeHint: "Wszystkie notatki i załączniki w tym notatniku oraz jego podnotatnikach będą publiczne. Nowe i przeniesione treści są udostępniane automatycznie, a zapisane zmiany są widoczne na bieżąco. Każdy z linkiem może je przeglądać bez logowania.",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 05a221dd..11af92ad 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -2548,6 +2548,22 @@ export const zhCN = {
expandOutlineHeading: "展开 {{name}}",
},
sharing: {
+ siteHideContents: "收起目录",
+ siteShowContents: "展开目录",
+ siteHome: "首页",
+ siteSearch: "搜索笔记标题",
+ siteClearSearch: "清除搜索",
+ siteNoteCount: "{{count}} 篇笔记",
+ siteWelcome: "浏览这里的笔记与栏目,找到你感兴趣的内容。",
+ siteResults: "找到 {{count}} 篇笔记",
+ siteNoResults: "没有找到匹配的笔记,请试试其他关键词。",
+ sitePoweredBy: "由 EdgeEver 提供支持",
+ siteSkipToContent: "跳转到正文",
+ siteBreadcrumb: "当前位置",
+ siteReadingNavigation: "阅读导航",
+ sitePrevious: "上一篇",
+ siteNext: "下一篇",
+
notebookChoose: "选择要分享的笔记本",
notebookTitle: "分享笔记本",
notebookScopeHint: "此笔记本及所有子笔记本中的笔记和附件都会公开。新增或移入的内容自动公开,编辑后的内容实时同步。任何获得链接的人都可无需登录访问。",