Copilot commented on code in PR #2029: URL: https://github.com/apache/apisix-website/pull/2029#discussion_r3076954673
########## config/breadcrumb.js: ########## @@ -0,0 +1,127 @@ +const SITE_URL = 'https://apisix.apache.org'; + +/** + * Generate BreadcrumbList JSON-LD structured data from a URL path. + * + * Example for /docs/apisix/plugins/limit-req/: + * Home > Docs > APISIX > Plugins > limit-req + */ +function buildBreadcrumbs(urlPath) { + // Remove trailing index.html and normalize + const cleanPath = urlPath + .replace(/\/index\.html$/, '/') + .replace(/\.html$/, '/'); + + // Split into segments, filter empties + const segments = cleanPath.split('/').filter(Boolean); + + if (segments.length === 0) return null; // homepage, no breadcrumb needed + + // Build breadcrumb items + const items = [ + { + '@type': 'ListItem', + position: 1, + name: 'Home', + item: SITE_URL + '/', + }, + ]; + + // Human-readable labels for known path segments + const labels = { + docs: 'Docs', + apisix: 'APISIX', + blog: 'Blog', + plugins: 'Plugins', + 'learning-center': 'Learning Center', + 'ingress-controller': 'Ingress Controller', + 'helm-chart': 'Helm Chart', + docker: 'Docker', + 'ai-gateway': 'AI Gateway', + downloads: 'Downloads', + team: 'Team', + contribute: 'Contribute', + showcase: 'Showcase', + help: 'Help', + articles: 'Articles', + events: 'Events', + general: 'General', + zh: 'Chinese', + }; + + let currentPath = ''; + for (let i = 0; i < segments.length; i++) { + const seg = segments[i]; + currentPath += '/' + seg; + + // Skip 'zh' locale prefix in breadcrumb display + if (seg === 'zh' && i === 0) continue; + + const name = labels[seg] || seg.replace(/-/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()); + + items.push({ + '@type': 'ListItem', + position: items.length + 1, + name, + item: SITE_URL + currentPath + '/', + }); + } + + // Don't generate breadcrumbs for single-level pages (just Home > Page) + if (items.length <= 1) return null; Review Comment: The guard for “single-level pages (just Home > Page)” doesn’t match the condition here: `items` always contains `Home`, so a single-level page produces `items.length === 2` and will still generate breadcrumbs. Either adjust the condition (e.g., treat `items.length <= 2` as single-level) or update/remove the comment so the behavior and intent are consistent. ```suggestion if (items.length <= 2) return null; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
