diff --git a/packages/docs/src/app/docs/markdown.ts b/packages/docs/src/app/docs/markdown.ts index 5eb6cd68..ec9398b5 100644 --- a/packages/docs/src/app/docs/markdown.ts +++ b/packages/docs/src/app/docs/markdown.ts @@ -81,9 +81,21 @@ const tabName = (token: Token) => ? ((token as Tokens.Code).lang ?? '').match(/\btab="([^"]+)"/)?.[1] : undefined; -/** `` right before an ordered list turns it into numbered steps on a rail. */ -const isStepsMarker = (token: Token) => - token.type === 'html' && /^\s*$/.test(token.raw); +/** + * A marker comment right before a list changes how it renders: + * `` turns an ordered list into numbered steps on a rail, + * `` turns a list of `[Title](href): description` items into + * a grid of link cards. + */ +const listMarker = (token: Token) => + token.type === 'html' + ? (token.raw.match(/^\s*$/)?.[1] as + | 'steps' + | 'cards' + | undefined) + : undefined; + +type MarkedList = Tokens.List & { steps?: boolean; cards?: boolean }; /** * Rewrites the token tree before rendering, at every level so it also @@ -94,10 +106,15 @@ function transformTokens(tokens: Token[]): Token[] { const out: Token[] = []; for (let i = 0; i < tokens.length; i++) { const token = tokens[i]; - if (isStepsMarker(token)) { + const marker = listMarker(token); + if (marker) { const list = tokens.slice(i + 1).find((t) => t.type !== 'space'); - if (list?.type === 'list' && (list as Tokens.List).ordered) { - (list as Tokens.List & { steps?: boolean }).steps = true; + if (list?.type === 'list') { + if (marker === 'steps' && (list as Tokens.List).ordered) { + (list as MarkedList).steps = true; + } else if (marker === 'cards') { + (list as MarkedList).cards = true; + } } continue; } @@ -222,6 +239,47 @@ export function renderMarkdown( const usedIds = new Set(); let tabGroups = 0; + /** Resolves an in-app link against the base href and marks it for the router. */ + const linkTarget = (href: string) => { + const external = /^https?:\/\//.test(href); + const internal = href.startsWith('/'); + return { + external, + attrs: [ + `href="${internal ? baseHref + href : href}"`, + internal ? `data-internal="${href}"` : '', + external ? 'target="_blank" rel="noopener noreferrer"' : '', + ] + .filter(Boolean) + .join(' '), + }; + }; + + /** One `[Title](href): description` list item as a card. */ + const linkCard = ( + parser: { parseInline: (tokens: Token[]) => string }, + item: Tokens.ListItem, + ) => { + const inline = + (item.tokens[0] as Tokens.Text | undefined)?.tokens ?? item.tokens; + const [first, ...rest] = inline; + if (first?.type !== 'link') { + return ``; + } + const link = first as Tokens.Link; + const { external, attrs } = linkTarget(link.href); + const title = parser.parseInline(link.tokens); + // Links inside the description would nest inside the card's link. + const description = parser + .parseInline(rest) + .replace(/<\/?a\b[^>]*>/g, '') + .replace(/^\s*[:,\u2013\u2014-]\s*/, ''); + const host = external + ? `${escapeHtml(new URL(link.href).host.replace(/^www\./, ''))}` + : ''; + return `${title}${description ? `${description}` : ''}${host}`; + }; + const marked = new Marked({ gfm: true, extensions: [ @@ -282,7 +340,10 @@ export function renderMarkdown( .join(' '); return `
${header}${pre}
\n`; }, - list(token: Tokens.List & { steps?: boolean }) { + list(token: MarkedList) { + if (token.cards) { + return `\n`; + } if (!token.steps) { return false; } @@ -345,17 +406,9 @@ export function renderMarkdown( }, link({ href, title, tokens }: Tokens.Link) { const inner = this.parser.parseInline(tokens); - const external = /^https?:\/\//.test(href); - const internal = href.startsWith('/'); - const attrs = [ - `href="${internal ? baseHref + href : href}"`, - internal ? `data-internal="${href}"` : '', - title ? `title="${escapeHtml(title)}"` : '', - external ? 'target="_blank" rel="noopener noreferrer"' : '', - ] - .filter(Boolean) - .join(' '); - return `${inner}`; + const { attrs } = linkTarget(href); + const titleAttr = title ? ` title="${escapeHtml(title)}"` : ''; + return `${inner}`; }, }, }); diff --git a/packages/docs/src/content/getting-started/introduction.md b/packages/docs/src/content/getting-started/introduction.md index 5ffafe95..3d828977 100644 --- a/packages/docs/src/content/getting-started/introduction.md +++ b/packages/docs/src/content/getting-started/introduction.md @@ -33,6 +33,8 @@ The rc file holds project defaults. Every value in it can be overridden on the c ## Where to go next -1. [Install the CLI](/docs/getting-started/installation) in your project. -2. Follow the [Quick start](/docs/getting-started/quick-start) to run your first flow. -3. Learn the three measurement modes in [Basic user flows](/docs/user-flows/basics). + + +- [Installation](/docs/getting-started/installation): Install the CLI in your project, or start from an empty folder. +- [Quick start](/docs/getting-started/quick-start): Initialise a config and run your first flow in minutes. +- [Basic user flows](/docs/user-flows/basics): Learn the navigation, timespan and snapshot measurement modes. diff --git a/packages/docs/src/content/getting-started/quick-start.md b/packages/docs/src/content/getting-started/quick-start.md index 7f500820..383b2a28 100644 --- a/packages/docs/src/content/getting-started/quick-start.md +++ b/packages/docs/src/content/getting-started/quick-start.md @@ -90,6 +90,9 @@ npx user-flow --ufPath=./user-flows-new --outPath=./user-flows-reports --url=htt ## Next steps -- Add interactions and the other measurement modes in [Basic user flows](/docs/user-flows/basics). -- Read the full option lists for [`init`](/docs/cli/init) and [`collect`](/docs/cli/collect). -- Put the flow into your pipeline with the [GitHub workflow](/docs/integrations/github-workflow). + + +- [Basic user flows](/docs/user-flows/basics): Add interactions and the other measurement modes. +- [init command](/docs/cli/init): The full option list for creating and updating the rc file. +- [collect command](/docs/cli/collect): The full option list for running flows and writing reports. +- [GitHub workflow](/docs/integrations/github-workflow): Put the flow into your pipeline and get a report on every pull request. diff --git a/packages/docs/src/content/resources/examples-and-links.md b/packages/docs/src/content/resources/examples-and-links.md index 97a5752c..f9880a9b 100644 --- a/packages/docs/src/content/resources/examples-and-links.md +++ b/packages/docs/src/content/resources/examples-and-links.md @@ -12,17 +12,21 @@ ## Related projects -- [user-flow-gh-action](https://github.com/push-based/user-flow-gh-action), the GitHub action that runs the CLI and comments on pull requests. -- [@push-based/user-flow-nx-plugin](https://www.npmjs.com/package/@push-based/user-flow-nx-plugin), the Nx plugin. + + +- [user-flow-gh-action](https://github.com/push-based/user-flow-gh-action): The GitHub action that runs the CLI and comments on pull requests. +- [@push-based/user-flow-nx-plugin](https://www.npmjs.com/package/@push-based/user-flow-nx-plugin): The Nx plugin. ## Lighthouse and Chrome DevTools -- [Lighthouse user flows](https://web.dev/lighthouse-user-flows/) introduces the navigation, timespan and snapshot modes. -- [Understanding the Lighthouse result](https://github.com/GoogleChrome/lighthouse/blob/master/docs/understanding-results.md) explains the JSON structure. -- [Lighthouse configuration](https://github.com/GoogleChrome/lighthouse/blob/main/docs/configuration.md) documents every config property. -- [Lighthouse viewer](https://googlechrome.github.io/lighthouse/viewer/) renders a JSON report in the browser. -- [Chrome DevTools Recorder](https://developer.chrome.com/docs/devtools/recorder/) records and exports user flows. -- [Recorder features](https://m.youtube.com/watch?v=PupwBARjaYU) in a short video. + + +- [Lighthouse user flows](https://web.dev/lighthouse-user-flows/): Introduces the navigation, timespan and snapshot modes. +- [Understanding the Lighthouse result](https://github.com/GoogleChrome/lighthouse/blob/master/docs/understanding-results.md): Explains the JSON structure. +- [Lighthouse configuration](https://github.com/GoogleChrome/lighthouse/blob/main/docs/configuration.md): Documents every config property. +- [Lighthouse viewer](https://googlechrome.github.io/lighthouse/viewer/): Renders a JSON report in the browser. +- [Chrome DevTools Recorder](https://developer.chrome.com/docs/devtools/recorder/): Records and exports user flows. +- [Recorder features](https://m.youtube.com/watch?v=PupwBARjaYU): The Recorder's features in a short video. ## Getting help diff --git a/packages/docs/src/styles.scss b/packages/docs/src/styles.scss index 69ed50df..cc9281b2 100644 --- a/packages/docs/src/styles.scss +++ b/packages/docs/src/styles.scss @@ -631,6 +631,87 @@ pre { white-space: nowrap; } +/* Link cards, from a `` list: the landing page's section cards for next steps and further reading. */ +.link-cards { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); + gap: var(--space-3); + margin: var(--space-4) 0 var(--space-8); +} + +.prose a.link-card { + display: flex; + flex-direction: column; + gap: var(--space-1-5); + padding: var(--space-4) var(--space-5); + border: 1px solid var(--border-strong); + border-radius: var(--radius-lg); + background: var(--surface-raised); + color: var(--text); + text-decoration: none; + transition: + translate var(--duration-base) var(--ease-out), + box-shadow var(--duration-base) var(--ease-out), + border-color var(--duration-base) ease-out; + + &:hover { + translate: 0 -3px; + box-shadow: var(--shadow-md); + border-color: var(--accent-outline); + } + + &:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 2px; + } +} + +.link-card-title { + display: flex; + align-items: baseline; + justify-content: space-between; + gap: var(--space-2); + font-weight: 600; + line-height: 1.5rem; + color: var(--text-heading); + transition: color var(--duration-fast) ease-out; + + .link-card:hover & { + color: var(--link); + } +} + +.link-card-arrow { + flex: none; + color: var(--text-subtle); + transition: + translate var(--duration-base) var(--ease-out), + color var(--duration-base) ease-out; + + .link-card:hover & { + color: var(--link); + translate: 3px 0; + } + + .link-card-external:hover & { + translate: 2px -2px; + } +} + +.link-card-body { + font-size: 0.875rem; + line-height: 1.375rem; + color: var(--text-muted); +} + +.link-card-host { + margin-top: auto; + padding-top: var(--space-1); + font-family: var(--font-mono); + font-size: 0.75rem; + color: var(--text-subtle); +} + /* Callouts, from GitHub style `> [!TIP]` block quotes */ .callout { margin: 0 0 var(--space-6);