Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@addiscorp/kit",
"version": "0.2.3",
"version": "0.2.4",
"description": "The header, footer, theme and tool-site layout every Addis site shares, in each project's own brand colours.",
"license": "Apache-2.0",
"type": "module",
Expand Down
5 changes: 4 additions & 1 deletion src/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export type FooterProps = {
year?: number;
/** Anything else for the end of the footer, before the theme switch. */
children?: ReactNode;
/** A small line under the footer row, e.g. trademark notices. */
note?: ReactNode;
};

export function Footer({ site, owner = ADDIS, year = new Date().getFullYear(), children }: FooterProps) {
export function Footer({ site, owner = ADDIS, year = new Date().getFullYear(), children, note }: FooterProps) {
return (
<footer className="ak-foot">
<a className="ak-credit" href={owner.href}>
Expand All @@ -34,6 +36,7 @@ export function Footer({ site, owner = ADDIS, year = new Date().getFullYear(), c
<span>{site}</span>
<ThemeToggle />
</span>
{note && <p className="ak-foot-note">{note}</p>}
</footer>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/kit.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
.ak-credit { display: inline-flex; align-items: center; gap: 8px; color: var(--ak-ink); text-decoration: none; }
.ak-credit img, .ak-owner-mark { width: 32px; height: 32px; border-radius: 50%; }
.ak-foot-end { display: inline-flex; align-items: center; gap: 12px; }
.ak-foot-note { flex-basis: 100%; margin: 0; font-size: 11px; line-height: 1.6; color: var(--ak-soft); opacity: .8; }

/* The theme switch */
.ak-theme-toggle { box-sizing: border-box; border: 0; background: transparent; border-radius: 4px; color: inherit; cursor: pointer; display: inline-flex; height: 32px; width: 32px; align-items: center; justify-content: center; padding: 8px; }
Expand Down
24 changes: 14 additions & 10 deletions src/tool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { LinkComponent } from '../header/index.js';
import { Footer } from '../footer/index.js';
import { CopyButton } from './copy.js';
import { MARKS } from './marks.js';
import { TOOLS, toolInfo, type ToolId } from './tools.js';
import { TOOLS, toolInfo, toolName, type ToolId } from './tools.js';

export { TOOLS, toolInfo, type ToolId, type ToolInfo } from './tools.js';
export { TOOLS, toolInfo, toolName, type ToolId, type ToolInfo } from './tools.js';
export { MARKS } from './marks.js';
export { CopyButton } from './copy.js';

Expand All @@ -30,28 +30,30 @@ export function Mark({ tool, size = 26 }: { tool: ToolId; size?: number }) {
export type HeaderLink = { label: string; href: string };

/** Everything a tool site shows sits inside this: it sets the tool's colours, the header and the footer. */
export function ToolSite({ tool, home = '/', docs = '/docs/', links = [], Link = PlainLink, children }: {
export function ToolSite({ tool, home = '/', docs = '/docs/', links = [], footnote, Link = PlainLink, children }: {
tool: ToolId;
home?: string;
docs?: string;
/** More header links, after docs, for what only this tool has. */
links?: HeaderLink[];
/** A small line under the footer, e.g. trademark notices. */
footnote?: ReactNode;
Link?: LinkComponent;
children: ReactNode;
}) {
return (
<div className="akt" data-tool={tool}>
<main className="akt-main">
<header className="akt-header">
<Link className="akt-brand" href={home}><Mark tool={tool} />{tool}</Link>
<Link className="akt-brand" href={home}><Mark tool={tool} />{toolName(tool)}</Link>
<nav aria-label="Main">
<Link href={docs}>docs</Link>
{links.map((link) => <Link key={link.href} href={link.href}>{link.label}</Link>)}
</nav>
</header>
{children}
</main>
<Footer site={toolInfo(tool).domain} />
<Footer site={toolInfo(tool).domain} note={footnote} />
</div>
);
}
Expand Down Expand Up @@ -147,7 +149,7 @@ export type Benefit = { title: string; text: string };
export function Why({ tool, benefits }: { tool: ToolId; benefits: [Benefit, Benefit, Benefit] }) {
return (
<section className="akt-why">
<h2>Why {tool}<small>the short version</small></h2>
<h2>Why {toolName(tool)}<small>the short version</small></h2>
<div className="akt-cards">
{benefits.map((benefit) => (
<div className="akt-card" key={benefit.title}>
Expand All @@ -161,7 +163,7 @@ export function Why({ tool, benefits }: { tool: ToolId; benefits: [Benefit, Bene
<div className="akt-family">
{TOOLS.filter((t) => t.id !== tool).map((t) => (
<a key={t.id} className="akt-row" href={`https://${t.domain}`}>
<strong><Mark tool={t.id} size={18} />{t.id}</strong>
<strong><Mark tool={t.id} size={18} />{t.name ?? t.id}</strong>
<span>{t.short}</span>
</a>
))}
Expand All @@ -175,7 +177,7 @@ export function Why({ tool, benefits }: { tool: ToolId; benefits: [Benefit, Bene
export type DocsPage = { href: string; title: string };

/** The docs, after rixse.dev: the pages down the side, the page on the right. */
export function DocsLayout({ tool, pages, pathname, eyebrow = 'Documentation', title, lede, note, home = '/', Link = PlainLink, children }: {
export function DocsLayout({ tool, pages, pathname, eyebrow = 'Documentation', title, lede, note, footnote, home = '/', Link = PlainLink, children }: {
tool: ToolId;
pages: DocsPage[];
pathname: string;
Expand All @@ -184,6 +186,8 @@ export function DocsLayout({ tool, pages, pathname, eyebrow = 'Documentation', t
lede?: string;
/** A small note under the page list, e.g. what the docs describe. */
note?: string;
/** A small line under the footer, e.g. trademark notices. */
footnote?: ReactNode;
home?: string;
Link?: LinkComponent;
children: ReactNode;
Expand All @@ -193,7 +197,7 @@ export function DocsLayout({ tool, pages, pathname, eyebrow = 'Documentation', t
<div className="akt akt-docs" data-tool={tool}>
<div className="akt-docs-grid">
<aside className="akt-side">
<Link className="akt-brand" href={home}><Mark tool={tool} />{tool}<span className="akt-brand-docs">docs</span></Link>
<Link className="akt-brand" href={home}><Mark tool={tool} />{toolName(tool)}<span className="akt-brand-docs">docs</span></Link>
<nav aria-label="Docs">
{pages.map((page) => (
<Link key={page.href} href={page.href} aria-current={here(page.href) ? 'page' : undefined}>{page.title}</Link>
Expand All @@ -208,7 +212,7 @@ export function DocsLayout({ tool, pages, pathname, eyebrow = 'Documentation', t
<div className="akt-prose">{children}</div>
</article>
</div>
<Footer site={toolInfo(tool).domain} />
<Footer site={toolInfo(tool).domain} note={footnote} />
</div>
);
}
Expand Down
9 changes: 8 additions & 1 deletion src/tool/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type ToolInfo = {
domain: string;
/** One line, as the family list shows it. */
short: string;
/** The name as shown, when it isn't the id: `SecureCore`. */
name?: string;
};

export const TOOLS: ToolInfo[] = [
Expand All @@ -17,11 +19,16 @@ export const TOOLS: ToolInfo[] = [
{ id: 'gelada', domain: 'gelada.addis.gg', short: 'OS sandboxes, without a container.' },
{ id: 'harar', domain: 'harar.addis.gg', short: 'A simple vault for your keys.' },
{ id: 'p8', domain: 'p8.addis.gg', short: 'PHP in pure Rust. Memory-safe.' },
{ id: 'securecore', domain: 'securecore.addis.gg', short: 'Every WordPress plugin in its own sandbox.' },
{ id: 'securecore', name: 'SecureCore', domain: 'securecore.addis.gg', short: 'Every WordPress plugin in its own sandbox.' },
];

export function toolInfo(id: ToolId): ToolInfo {
const info = TOOLS.find((t) => t.id === id);
if (!info) throw new Error(`unknown tool: ${id}`);
return info;
}

/** A tool's name as every site shows it: its display name, else its id. */
export function toolName(id: ToolId): string {
return toolInfo(id).name ?? id;
}
23 changes: 23 additions & 0 deletions tests/tool.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,26 @@ test('docs mark the page you are on, with or without a trailing slash', () => {
assert.equal(doc.querySelector('.akt-code pre').textContent, 'p8 hello.php');
assert.ok(doc.querySelector('.akt-code .akt-copy'));
});

test('a tool with a display name shows it everywhere it is named; the others show their id', () => {
const benefits = [{ title: 'a', text: '1' }, { title: 'b', text: '2' }, { title: 'c', text: '3' }];
const site = page(h(kit.ToolSite, { tool: 'securecore' }, h(kit.Why, { tool: 'securecore', benefits })));
assert.equal(site.querySelector('.akt-header .akt-brand').textContent, 'SecureCore');
assert.equal(site.querySelector('.akt-why h2').textContent, 'Why SecureCorethe short version');
assert.match(site.querySelector('.ak-foot').textContent, /securecore\.addis\.gg/, 'the domain stays lowercase');
const docs = page(h(kit.DocsLayout, { tool: 'securecore', pages: [{ href: '/docs/', title: 'Overview' }], pathname: '/docs/', title: 'Overview' }, h('p', null, 'x')));
assert.equal(docs.querySelector('.akt-side .akt-brand').textContent, 'SecureCoredocs');
// In another tool's family list: the display name for securecore, the id for every other tool.
const names = [...page(h(kit.Why, { tool: 'harar', benefits })).querySelectorAll('.akt-row strong')].map((s) => s.textContent);
assert.deepEqual(names, kit.TOOLS.filter((t) => t.id !== 'harar').map((t) => (t.id === 'securecore' ? 'SecureCore' : t.id)));
assert.equal(page(h(kit.ToolSite, { tool: 'harar' }, null)).querySelector('.akt-brand').textContent, 'harar');
});

test('a site’s footnote is a line in its footer, on the site and in its docs; without one there is none', () => {
const note = 'WordPress® is a registered trademark of the WordPress Foundation.';
const site = page(h(kit.ToolSite, { tool: 'securecore', footnote: note }, h('p', null, 'hi')));
assert.equal(site.querySelector('.ak-foot .ak-foot-note').textContent, note);
const docs = page(h(kit.DocsLayout, { tool: 'securecore', pages: [], pathname: '/docs/', title: 'Overview', footnote: note }, h('p', null, 'x')));
assert.equal(docs.querySelector('.ak-foot .ak-foot-note').textContent, note);
assert.equal(page(h(kit.ToolSite, { tool: 'harar' }, h('p', null, 'hi'))).querySelector('.ak-foot-note'), null);
});
Loading