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
89 changes: 71 additions & 18 deletions packages/docs/src/app/docs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,21 @@ const tabName = (token: Token) =>
? ((token as Tokens.Code).lang ?? '').match(/\btab="([^"]+)"/)?.[1]
: undefined;

/** `<!-- steps -->` right before an ordered list turns it into numbered steps on a rail. */
const isStepsMarker = (token: Token) =>
token.type === 'html' && /^<!--\s*steps\s*-->\s*$/.test(token.raw);
/**
* A marker comment right before a list changes how it renders:
* `<!-- steps -->` turns an ordered list into numbered steps on a rail,
* `<!-- cards -->` 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*(steps|cards)\s*-->\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
Expand All @@ -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;
}
Expand Down Expand Up @@ -222,6 +239,47 @@ export function renderMarkdown(
const usedIds = new Set<string>();
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 `<div class="link-card">${parser.parseInline(inline)}</div>`;
}
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
? `<span class="link-card-host">${escapeHtml(new URL(link.href).host.replace(/^www\./, ''))}</span>`
: '';
return `<a class="link-card${external ? ' link-card-external' : ''}" ${attrs}><span class="link-card-title">${title}<span class="link-card-arrow" aria-hidden="true">${external ? '↗' : '→'}</span></span>${description ? `<span class="link-card-body">${description}</span>` : ''}${host}</a>`;
};

const marked = new Marked({
gfm: true,
extensions: [
Expand Down Expand Up @@ -282,7 +340,10 @@ export function renderMarkdown(
.join(' ');
return `<figure class="${classes}">${header}${pre}</figure>\n`;
},
list(token: Tokens.List & { steps?: boolean }) {
list(token: MarkedList) {
if (token.cards) {
return `<div class="link-cards">${token.items.map((item) => linkCard(this.parser, item)).join('')}</div>\n`;
}
if (!token.steps) {
return false;
}
Expand Down Expand Up @@ -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 `<a ${attrs}>${inner}</a>`;
const { attrs } = linkTarget(href);
const titleAttr = title ? ` title="${escapeHtml(title)}"` : '';
return `<a ${attrs}${titleAttr}>${inner}</a>`;
},
},
});
Expand Down
8 changes: 5 additions & 3 deletions packages/docs/src/content/getting-started/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
<!-- cards -->

- [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.
9 changes: 6 additions & 3 deletions packages/docs/src/content/getting-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
<!-- cards -->

- [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.
20 changes: 12 additions & 8 deletions packages/docs/src/content/resources/examples-and-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
<!-- cards -->

- [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.
<!-- cards -->

- [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

Expand Down
81 changes: 81 additions & 0 deletions packages/docs/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,87 @@ pre {
white-space: nowrap;
}

/* Link cards, from a `<!-- cards -->` 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);
Expand Down
Loading