All files / packages/design-system-2-site/src/lib/zeroheight fixes.js

100% Statements 13/13
80% Branches 4/5
100% Functions 1/1
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                      2x                                                               2x                                       2x                                 29x 29x 29x 30x 1x 1x 1x   29x    
/**
 * Local fixes, reapplied on every `zh:pull`. Synced files are generated, so a
 * correction goes here instead of into the file. Each rule says why.
 *
 *   - `LINK_ALIASES`: Zeroheight page uids that no longer exist (dead links
 *     in Zeroheight itself) -> the live page they meant
 *   - `LINK_ROUTES`: links to pages we don't port -> a site route or URL
 *   - `CONTENT_FIXES`: text replacements on the converted markdown
 */
 
/** @type {Record<string, { to: string, reason: string }>} */
export const LINK_ALIASES = {
  '319e5f': {
    to: '0213f9',
    reason: '"Read the technical documentation" in every Styling Hooks Overview: old page, now Component-Level Styling Hooks',
  },
  591960: { to: '777f5a', reason: 'Global Styling Hooks: old uid' },
  '16a791': { to: '01c12a', reason: 'Modals: old uid' },
  '83309d': { to: '63cc01', reason: 'Old Icons page (hidden), now Icons > Usage' },
  '21245c': { to: '09f001', reason: 'Empty State: old styleguide uid' },
  '312197': { to: '204931', reason: 'Builder Validation: old page, now a Builder tab' },
  '42090b': { to: '25d63d', reason: 'User Engagement: old uid' },
  '732cfe': { to: '25d63d', reason: 'Onboarding: old page, now a User Engagement tab' },
  '00beb9': { to: '25d63d', reason: 'User Engagement Copy: old page, now part of User Engagement' },
  '38b949': { to: '92a50f', reason: 'Global Focus Patterns: old page, now Global Focus' },
  '7241f7': { to: '12db58', reason: 'Interface Patterns: old page, now Interface Feedback' },
  '53eb31': { to: '33e9af', reason: 'Patterns > Layout card: old uid' },
  // Old Conversation Design subpages, now tabs of one page.
  '14b4d4': { to: '33c7b6', reason: 'Bot Personality: now a Conversation Design tab' },
  '26120c': { to: '33c7b6', reason: 'Accessibility and Inclusion: now a Conversation Design tab' },
  '56047e': { to: '33c7b6', reason: 'A Conversation: now part of Conversation Design' },
  '66cace': { to: '33c7b6', reason: 'Language and Style: now a Conversation Design tab' },
  '769bf8': { to: '33c7b6', reason: 'Best Practices: now a Conversation Design tab' },
  '9649ad': { to: '33c7b6', reason: 'Message Entries: now part of Conversation Design' },
  '995913': { to: '33c7b6', reason: 'Resources and FAQs: now a Conversation Design tab' },
  '11cfec': { to: '11979d', reason: 'Box "box theme" link: old page, now Themes' },
  '95c37a': {
    to: '52a7c7',
    reason: 'Get Started "Agentic Experiences" card: deleted page (broken in Zeroheight too), now AI and SLDS 2',
  },
};
 
/** @type {Record<string, { to: string, reason: string }>} */
export const LINK_ROUTES = {
  541420: {
    to: 'https://v1.lightningdesignsystem.com/components/alert/',
    reason: 'Alert is hidden in Zeroheight (no SLDS 2 page yet), so link the SLDS 1 page like Zeroheight does',
  },
  '54feb0': {
    to: 'https://v1.lightningdesignsystem.com/components/scoped-notifications/',
    reason: 'Prompt links Scoped Notifications on the old Patterns page; no SLDS 2 page yet, so link the SLDS 1 page',
  },
  '98b493': {
    to: '/styling-api/styling-hook-index',
    reason: 'Styling Hook Index is generated from design-tokens (app route), so the Zeroheight page is not ported',
  },
};
 
/**
 * @typedef {{ file: RegExp, find: string | RegExp, replace: string, reason: string }} ContentFix
 * `file` matches the content-relative path (e.g. `components/badge--usage.md`).
 * @type {ContentFix[]}
 */
export const CONTENT_FIXES = [
  {
    file: /^components\/(tabs|textarea)(--usage)?\.md$/,
    find: /::image\{src="zeroheight:\/\/image\/\d+\/86f23071cc18354957108a999dc7032338f0280ce5e47e9ede43f3b32b886fbe"[^}]*\}\n\n/g,
    replace: '',
    reason: 'Tabs States and Textarea Anatomy: image deleted in Zeroheight, the next image is the real one',
  },
];
 
/**
 * @param {string} md
 * @param {string} file content-relative path
 * @param {ContentFix[]} [fixes]
 * @returns {{ md: string, applied: string[] }} `applied` lists the reasons of rules that changed something
 */
export function applyContentFixes(md, file, fixes = CONTENT_FIXES) {
  /** @type {string[]} */
  const applied = [];
  let out = md;
  for (const fix of fixes) {
    if (!fix.file.test(file)) continue;
    const next = out.replace(fix.find, fix.replace);
    Eif (next !== out) applied.push(fix.reason);
    out = next;
  }
  return { md: out, applied };
}