Skip to content

Build your personal knowledge base with Trilium Notes

feat(website): add sticky section nav and card heading-links to home

Elian Dorandaed6c141bc0
diff --git a/apps/website/src/assets/boxicons/bx-chevron-right.svg b/apps/website/src/assets/boxicons/bx-chevron-right.svg
new file mode 100644
index 0000000000..0c13652179
--- /dev/null
+++ b/apps/website/src/assets/boxicons/bx-chevron-right.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><!--Boxicons v3.0 https://boxicons.com | License https://docs.boxicons.com/free--><path d="M10.707 17.707 16.414 12l-5.707-5.707-1.414 1.414L13.586 12l-4.293 4.293z"/></svg>
diff --git a/apps/website/src/components/Card.tsx b/apps/website/src/components/Card.tsx
index 721cf42419..2b22c9c840 100644
--- a/apps/website/src/components/Card.tsx
+++ b/apps/website/src/components/Card.tsx
@@ -1,7 +1,8 @@
import { ComponentChildren, HTMLAttributes } from "preact";
import { Link } from "./Button.js";
import Icon from "./Icon.js";
-import { useTranslation } from "react-i18next";
+
+import arrowIcon from "../assets/boxicons/bx-chevron-right.svg?raw";
interface CardProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
title: ComponentChildren;
@@ -13,27 +14,31 @@ interface CardProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
}
export default function Card({ title, children, imageUrl, iconSvg, className, moreInfoUrl, ...restProps }: CardProps) {
- const { t } = useTranslation();
-
return (
- <div className={`card ${className}`} {...restProps}>
+ <div className={`card ${moreInfoUrl ? "card-linked" : ""} ${className ?? ""}`} {...restProps}>
{imageUrl && <img class="image" src={imageUrl} loading="lazy" />}
<div className="card-content">
<h3>
- {iconSvg && <Icon svg={iconSvg} />}{" "}
- <span>{title}</span>
+ {moreInfoUrl
+ ? (
+ <Link href={moreInfoUrl} className="card-heading-link" openExternally>
+ {iconSvg && <Icon svg={iconSvg} />}
+ <span>{title}</span>
+ <Icon svg={arrowIcon} className="card-arrow" />
+ </Link>
+ )
+ : (
+ <>
+ {iconSvg && <Icon svg={iconSvg} />}{" "}
+ <span>{title}</span>
+ </>
+ )}
</h3>
<div className="card-content-inner">
{children}
</div>
-
- {moreInfoUrl && (
- <div className="more-info-container">
- <Link href={moreInfoUrl} className="more-info" openExternally>{t("components.link_learn_more")}</Link>
- </div>
- )}
</div>
</div>
)
diff --git a/apps/website/src/components/Icon.tsx b/apps/website/src/components/Icon.tsx
index 72f4597dd7..f68a5d227f 100644
--- a/apps/website/src/components/Icon.tsx
+++ b/apps/website/src/components/Icon.tsx
@@ -1,9 +1,10 @@
interface IconProps {
svg: string;
+ className?: string;
}
-export default function Icon({ svg }: IconProps) {
+export default function Icon({ svg, className }: IconProps) {
return (
- <span className="bx" dangerouslySetInnerHTML={{ __html: svg }} />
+ <span className={`bx ${className ?? ""}`} dangerouslySetInnerHTML={{ __html: svg }} />
)
}
diff --git a/apps/website/src/components/Section.tsx b/apps/website/src/components/Section.tsx
index 13b213205f..b8923a89a6 100644
--- a/apps/website/src/components/Section.tsx
+++ b/apps/website/src/components/Section.tsx
@@ -3,6 +3,7 @@ import { ComponentChildren } from "preact";
import Button from "./Button.js";
interface SectionProps {
+ id?: string;
title?: string;
subtitle?: string;
cta?: { text: string; href: string };
@@ -10,9 +11,9 @@ interface SectionProps {
className?: string;
}
-export default function Section({ className, title, subtitle, cta, children }: SectionProps) {
+export default function Section({ id, className, title, subtitle, cta, children }: SectionProps) {
return (
- <section className={className}>
+ <section id={id} className={className}>
<div className="content-wrapper">
{title && <h2>{title}</h2>}
{subtitle && <p className="section-subtitle">{subtitle}</p>}
diff --git a/apps/website/src/components/SectionNav.css b/apps/website/src/components/SectionNav.css
new file mode 100644
index 0000000000..0ce2ae9dc4
--- /dev/null
+++ b/apps/website/src/components/SectionNav.css
@@ -0,0 +1,64 @@
+.section-nav {
+ position: sticky;
+ top: var(--header-height);
+ z-index: 999;
+ background: var(--header-background-color);
+ backdrop-filter: blur(20px);
+ border-bottom: 1px solid rgba(0, 0, 0, 0.08);
+ font-size: 0.85em;
+
+ @media (prefers-color-scheme: dark) {
+ border-bottom-color: rgba(255, 255, 255, 0.08);
+ }
+
+ &>.content-wrapper {
+ min-width: 80vw;
+ }
+
+ ul {
+ display: flex;
+ gap: 0.25em;
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ }
+
+ a {
+ display: block;
+ padding: 0.75em 0.9em;
+ color: var(--muted-color);
+ text-decoration: none;
+ white-space: nowrap;
+ border-bottom: 2px solid transparent;
+ transition: color 120ms ease, border-color 120ms ease;
+
+ &:hover {
+ color: var(--foreground-color);
+ text-decoration: none;
+ }
+
+ &.active {
+ color: var(--brand-1);
+ border-bottom-color: var(--brand-1);
+ }
+ }
+}
+
+/* Mobile: collapse to a horizontally-scrollable chip strip. */
+@media (max-width: 719.99px) {
+ .section-nav {
+ &>.content-wrapper {
+ min-width: 0;
+ }
+
+ ul {
+ overflow-x: auto;
+ scrollbar-width: none;
+ -webkit-overflow-scrolling: touch;
+ }
+
+ ul::-webkit-scrollbar {
+ display: none;
+ }
+ }
+}
diff --git a/apps/website/src/components/SectionNav.tsx b/apps/website/src/components/SectionNav.tsx
new file mode 100644
index 0000000000..f6a5a3fbe9
--- /dev/null
+++ b/apps/website/src/components/SectionNav.tsx
@@ -0,0 +1,81 @@
+import "./SectionNav.css";
+
+import { useEffect, useRef, useState } from "preact/hooks";
+import { useTranslation } from "react-i18next";
+
+export interface SectionNavItem {
+ id: string;
+ label: string;
+}
+
+export default function SectionNav({ items }: { items: SectionNavItem[] }) {
+ const { t } = useTranslation();
+ const [ activeId, setActiveId ] = useState<string>();
+ const activeRef = useRef<HTMLAnchorElement>(null);
+
+ useActiveSection(items, setActiveId);
+
+ // Keep the active chip in view on the horizontally-scrollable mobile strip.
+ useEffect(() => {
+ activeRef.current?.scrollIntoView({ block: "nearest", inline: "center" });
+ }, [ activeId ]);
+
+ return (
+ <nav className="section-nav" aria-label={t("section_nav.aria_label")}>
+ <div className="content-wrapper">
+ <ul>
+ {items.map((item) => {
+ const isActive = item.id === activeId;
+ return (
+ <li key={item.id}>
+ <a
+ href={`#${item.id}`}
+ className={isActive ? "active" : ""}
+ aria-current={isActive ? "true" : undefined}
+ ref={isActive ? activeRef : undefined}
+ >
+ {item.label}
+ </a>
+ </li>
+ );
+ })}
+ </ul>
+ </div>
+ </nav>
+ );
+}
+
+function useActiveSection(items: SectionNavItem[], setActiveId: (id: string) => void) {
+ useEffect(() => {
+ const sections = items
+ .map((item) => document.getElementById(item.id))
+ .filter((el): el is HTMLElement => el !== null);
+ if (sections.length === 0) {
+ return;
+ }
+
+ const visible = new Set<string>();
+ const observer = new IntersectionObserver(
+ (entries) => {
+ for (const entry of entries) {
+ if (entry.isIntersecting) {
+ visible.add(entry.target.id);
+ } else {
+ visible.delete(entry.target.id);
+ }
+ }
+ // The topmost section that has crossed the trigger line wins.
+ const current = items.find((item) => visible.has(item.id));
+ if (current) {
+ setActiveId(current.id);
+ }
+ },
+ // Trigger line sits just below the sticky header + nav; the bottom
+ // margin keeps only the upper slice of the viewport "active".
+ { rootMargin: "-160px 0px -65% 0px", threshold: 0 }
+ );
+
+ sections.forEach((section) => observer.observe(section));
+ return () => observer.disconnect();
+ }, [ items, setActiveId ]);
+}
diff --git a/apps/website/src/pages/Home/index.css b/apps/website/src/pages/Home/index.css
index 0be6876987..46fade99b7 100644
--- a/apps/website/src/pages/Home/index.css
+++ b/apps/website/src/pages/Home/index.css
@@ -244,6 +244,12 @@ section.accented {
background: linear-gradient(135deg, rgba(228, 123, 25, 0.08), rgba(79, 165, 43, 0.08));
}
+/* Offset anchor jumps so a section lands below the sticky header + section nav
+ instead of being hidden underneath them. */
+section[id] {
+ scroll-margin-top: calc(var(--header-height) + 3.5em);
+}
+
.benefits-container .card {
padding: 1em;
}
diff --git a/apps/website/src/pages/Home/index.tsx b/apps/website/src/pages/Home/index.tsx
index 928759a394..72c86b81fe 100644
--- a/apps/website/src/pages/Home/index.tsx
+++ b/apps/website/src/pages/Home/index.tsx
@@ -54,16 +54,30 @@ import Card from '../../components/Card.js';
import DownloadButton from '../../components/DownloadButton.js';
import Icon from '../../components/Icon.js';
import Section from '../../components/Section.js';
+import SectionNav, { SectionNavItem } from '../../components/SectionNav.js';
import { getPlatform } from '../../download-helper.js';
import { useColorScheme, usePageTitle } from '../../hooks.js';
import { StargazersContext } from '../../index.js';
export function Home() {
+ const { t } = useTranslation();
usePageTitle("");
+ const navItems: SectionNavItem[] = [
+ { id: "organization", label: t("section_nav.organization") },
+ { id: "productivity", label: t("section_nav.productivity") },
+ { id: "note-types", label: t("section_nav.note_types") },
+ { id: "import-export", label: t("section_nav.import") },
+ { id: "collections", label: t("section_nav.collections") },
+ { id: "scripting", label: t("section_nav.scripting") },
+ { id: "ai-integration", label: t("section_nav.ai_integration") },
+ { id: "faq", label: t("section_nav.faq") }
+ ];
+
return (
<>
<HeroSection />
+ <SectionNav items={navItems} />
<OrganizationBenefitsSection />
<ProductivityBenefitsSection />
<NoteTypesSection />
@@ -135,7 +149,7 @@ function OrganizationBenefitsSection() {
const { t } = useTranslation();
return (
<>
- <Section className="benefits organization" title={t("organization_benefits.title")}>
+ <Section id="organization" className="benefits organization" title={t("organization_benefits.title")}>
<div className="organization-split">
<div className="organization-screenshot">
<img src="/feature_tree.webp" alt={t("organization_benefits.screenshot_alt")} loading="lazy" />
@@ -155,7 +169,7 @@ function ProductivityBenefitsSection() {
const { t } = useTranslation();
return (
<>
- <Section className="benefits accented" title={t("productivity_benefits.title")}>
+ <Section id="productivity" className="benefits accented" title={t("productivity_benefits.title")}>
<div className="benefits-container grid-3-cols">
<Card iconSvg={syncIcon} title={t("productivity_benefits.sync_title")} moreInfoUrl="https://docs.triliumnotes.org/user-guide/setup/synchronization">{t("productivity_benefits.sync_content")}</Card>
<Card iconSvg={searchIcon} title={t("productivity_benefits.search_title")} moreInfoUrl="https://docs.triliumnotes.org/user-guide/concepts/navigation/search">{t("productivity_benefits.search_content")}</Card>
@@ -175,7 +189,7 @@ function ProductivityBenefitsSection() {
function NoteTypesSection() {
const { t } = useTranslation();
return (
- <Section className="note-types" title={t("note_types.title")} subtitle={t("note_types.subtitle")}>
+ <Section id="note-types" className="note-types" title={t("note_types.title")} subtitle={t("note_types.subtitle")}>
<TabbedShowcase items={[
{
title: t("note_types.text_title"),
@@ -253,7 +267,7 @@ function NoteTypesSection() {
function CollectionsSection() {
const { t } = useTranslation();
return (
- <Section className="collections" title={t("collections.title")} subtitle={t("collections.subtitle")}>
+ <Section id="collections" className="collections" title={t("collections.title")} subtitle={t("collections.subtitle")}>
<TabbedShowcase items={[
{
title: t("collections.calendar_title"),
@@ -305,7 +319,7 @@ function CollectionsSection() {
function AiIntegrationSection() {
const { t } = useTranslation();
return (
- <Section className="benefits ai-integration" title={t("ai_integration.title")} subtitle={t("ai_integration.subtitle")} cta={{ text: t("ai_integration.learn_more"), href: "https://docs.triliumnotes.org/user-guide/llm" }}>
+ <Section id="ai-integration" className="benefits ai-integration" title={t("ai_integration.title")} subtitle={t("ai_integration.subtitle")} cta={{ text: t("ai_integration.learn_more"), href: "https://docs.triliumnotes.org/user-guide/llm" }}>
<div className="feature-split">
<div className="feature-screenshot">
<img src="/feature_llm.webp" alt={t("ai_integration.screenshot_alt")} loading="lazy" />
@@ -323,7 +337,7 @@ function AiIntegrationSection() {
function ScriptingSection() {
const { t } = useTranslation();
return (
- <Section className="benefits scripting accented" title={t("scripting.title")} subtitle={t("scripting.subtitle")} cta={{ text: t("scripting.learn_more"), href: "https://docs.triliumnotes.org/user-guide/scripts" }}>
+ <Section id="scripting" className="benefits scripting accented" title={t("scripting.title")} subtitle={t("scripting.subtitle")} cta={{ text: t("scripting.learn_more"), href: "https://docs.triliumnotes.org/user-guide/scripts" }}>
<div className="feature-split">
<div className="feature-screenshot">
<img src="/feature_scripting.webp" alt={t("scripting.screenshot_alt")} loading="lazy" />
@@ -342,7 +356,7 @@ function ScriptingSection() {
function ImportSection() {
const { t } = useTranslation();
return (
- <Section className="benefits import accented" title={t("import.title")} subtitle={t("import.subtitle")}>
+ <Section id="import-export" className="benefits import accented" title={t("import.title")} subtitle={t("import.subtitle")}>
<div className="benefits-container grid-3-cols">
<Card iconSvg={importIcon} title={t("import.pillar_import_title")} moreInfoUrl="https://docs.triliumnotes.org/user-guide/concepts/import-export">
{t("import.pillar_import_description")}
@@ -388,7 +402,6 @@ interface ShowcaseItem {
}
function TabbedShowcase({ items }: { items: ShowcaseItem[] }) {
- const { t } = useTranslation();
const [ activeIndex, setActiveIndex ] = useState(0);
const active = items[activeIndex];
@@ -437,7 +450,7 @@ function TabbedShowcase({ items }: { items: ShowcaseItem[] }) {
function FaqSection() {
const { t } = useTranslation();
return (
- <Section className="faq" title={t("faq.title")}>
+ <Section id="faq" className="faq" title={t("faq.title")}>
<div className="faq-list">
<FaqItem question={t("faq.free_question")}>{t("faq.free_answer")}</FaqItem>
<FaqItem question={t("faq.mobile_question")}>{t("faq.mobile_answer")}</FaqItem>
diff --git a/apps/website/src/style.css b/apps/website/src/style.css
index 39f15c4035..4ff5fe4b50 100644
--- a/apps/website/src/style.css
+++ b/apps/website/src/style.css
@@ -14,6 +14,7 @@
--brand-2: #4fa52b;
--brand-3: #e33f3b;
--brand-foreground-color: white;
+ --header-height: 80px;
}
@media (prefers-color-scheme: dark) {
@@ -124,18 +125,26 @@ img {
display: flex;
flex-direction: column;
flex-grow: 1;
+ }
+}
+
+/* Heading-level doc link: the heading itself is the link, with an arrow
+ affordance instead of a repeated "Learn more..." text link. Used by linked
+ cards and the tabbed showcase. */
+.card-heading-link {
+ display: inline-flex;
+ align-items: center;
+ gap: 0.25em;
+ color: inherit;
+ text-decoration: none;
- .more-info-container {
- margin-top: 0.5em;
- flex-grow: 1;
- display: flex;
- flex-direction: column;
- justify-content: flex-end;
+ .card-arrow {
+ transition: transform 0.15s ease;
+ }
- .more-info {
- font-size: 0.9em;
- }
- }
+ &:hover .card-arrow,
+ &:focus-visible .card-arrow {
+ transform: translateX(4px);
}
}
diff --git a/apps/website/src/translations/en/translation.json b/apps/website/src/translations/en/translation.json
index 6eacbe55a2..0b88391cb7 100644
--- a/apps/website/src/translations/en/translation.json
+++ b/apps/website/src/translations/en/translation.json
@@ -6,6 +6,17 @@
"older_releases": "See older releases",
"server_title": "Set up a server for access on multiple devices"
},
+ "section_nav": {
+ "aria_label": "Jump to section",
+ "organization": "Organize",
+ "productivity": "Features",
+ "note_types": "Note types",
+ "import": "Import & export",
+ "collections": "Collections",
+ "scripting": "Scripting",
+ "ai_integration": "AI",
+ "faq": "FAQ"
+ },
"hero_section": {
"title": "Organize your thoughts. Build your personal knowledge base.",
"subtitle": "Trilium is an open-source solution for note-taking and organizing a personal knowledge base. Use it locally on your desktop, or sync it with your self-hosted server to keep your notes everywhere you go.",