feat: created example section for parsing params

This commit is contained in:
Leyla Becker 2026-02-18 12:48:31 -06:00
parent d4c62539c5
commit bd4ed7f8b6

View file

@ -206,6 +206,319 @@ parts of a url:
})(); })();
</script> </script>
## Understanding Query Parameters
Query parameters are the part of a URL that comes after the `?`. They consist of key-value pairs that pass data to the page. Let's break down how they work:
<style>
.query-container {
margin: 1em 0;
}
.query-example {
font-family: monospace;
font-size: 1.2em;
padding: 1em;
background: var(--code-background, #f5f5f5);
border: 1px solid var(--border-color, #ddd);
border-radius: 8px;
margin-bottom: 1em;
overflow-x: auto;
white-space: nowrap;
}
.query-example span,
.query-legend-item {
transition: opacity 0.2s, box-shadow 0.2s;
cursor: pointer;
}
.query-legend {
display: flex;
flex-direction: column;
gap: 0.75em;
padding: 1em;
background: var(--code-background, #f5f5f5);
border: 1px solid var(--border-color, #ddd);
border-radius: 8px;
}
.query-legend-item {
display: flex;
align-items: flex-start;
gap: 0.5em;
}
.query-legend-item .query-legend-label {
font-weight: 600;
min-width: 8em;
}
.query-legend-item[data-qparam] .query-legend-label {
min-width: auto;
}
.query-legend-item .query-legend-desc {
color: #666;
font-size: 0.9em;
}
.query-legend-color {
width: 1em;
height: 1em;
border-radius: 3px;
flex-shrink: 0;
margin-top: 0.2em;
}
/* Structure colors - each UNIQUE */
.query-part-delimiter { color: #db2777; }
.query-legend-delimiter { background: #db2777; }
.query-part-key { color: #2563eb; }
.query-legend-key { background: #2563eb; }
.query-part-equals { color: #ca8a04; }
.query-legend-equals { background: #ca8a04; }
.query-part-value { color: #16a34a; }
.query-legend-value { background: #16a34a; }
.query-part-separator { color: #9333ea; }
.query-legend-separator { background: #9333ea; }
/* Parameter group highlighting in URL */
.query-param-group {
display: inline;
border-radius: 0.25em;
transition: box-shadow 0.2s, background 0.2s;
}
.query-container.hovering .query-param-group.highlighted {
border-radius: 0.25em;
box-shadow:
inset 0 0 0.5em 0.25em rgba(0, 0, 0, 0.06),
0 0 0.75rem 0.5rem rgba(0, 0, 0, 0.06),
0 0 1.25rem 1rem rgba(0, 0, 0, 0.04),
0 0 2rem 1.5rem rgba(0, 0, 0, 0.02);
}
/* Base: dim everything when hovering (NOT param-groups, only their children) */
.query-container.hovering .query-example > span[data-qpart],
.query-container.hovering .query-param-group > span[data-qpart],
.query-container.hovering .query-legend-item {
opacity: 0.3;
}
/* Highlighted spans in URL */
.query-container.hovering .query-example span[data-qpart].highlighted {
opacity: 1 !important;
border-radius: 0.25em;
box-shadow:
inset 0 0 0.5em 0.25em rgba(0, 0, 0, 0.06),
0 0 0.75rem 0.5rem rgba(0, 0, 0, 0.06),
0 0 1.25rem 1rem rgba(0, 0, 0, 0.04),
0 0 2rem 1.5rem rgba(0, 0, 0, 0.02);
}
/* Spans inside highlighted param groups should have full opacity */
.query-container.hovering .query-param-group.highlighted > span[data-qpart] {
opacity: 1 !important;
}
.query-container .query-legend-item.highlighted {
opacity: 1 !important;
padding: 0.5em 0.75em;
margin: -0.5em -0.75em;
border-radius: 0.5em;
box-shadow:
inset 0 0 0.5em 0.25em rgba(0, 0, 0, 0.06),
0 0 0.75rem 0.5rem rgba(0, 0, 0, 0.06),
0 0 1.25rem 1rem rgba(0, 0, 0, 0.04),
0 0 2rem 1.5rem rgba(0, 0, 0, 0.02);
}
.query-legend-section {
margin-top: 1em;
padding-top: 0.75em;
border-top: 1px solid var(--border-color, #ddd);
}
.query-legend-section-title {
font-weight: 600;
font-size: 0.85em;
color: #666;
margin-bottom: 0.5em;
}
/* Parameter legend labels - styled as code blocks */
.query-param-label {
font-family: monospace;
font-size: 0.9em;
background: var(--inline-code-background, rgba(0, 0, 0, 0.06));
padding: 0.15em 0.4em;
border-radius: 4px;
border: 1px solid var(--border-color, rgba(0, 0, 0, 0.1));
min-width: auto;
}
</style>
<div class="query-container" id="query-container">
<div class="query-example" role="figure" aria-label="Query parameter example">
<span class="query-part-delimiter" data-qpart="delimiter">?</span><span class="query-param-group" data-qparam="size"><span class="query-part-key" data-qpart="key" data-qparam="size">size</span><span class="query-part-equals" data-qpart="equals" data-qparam="size">=</span><span class="query-part-value" data-qpart="value" data-qparam="size">medium</span></span><span class="query-part-separator" data-qpart="separator">&</span><span class="query-param-group" data-qparam="color"><span class="query-part-key" data-qpart="key" data-qparam="color">color</span><span class="query-part-equals" data-qpart="equals" data-qparam="color">=</span><span class="query-part-value" data-qpart="value" data-qparam="color">light%20blue</span></span><span class="query-part-separator" data-qpart="separator">&</span><span class="query-param-group" data-qparam="utm"><span class="query-part-key" data-qpart="key" data-qparam="utm">utm_source</span><span class="query-part-equals" data-qpart="equals" data-qparam="utm">=</span><span class="query-part-value" data-qpart="value" data-qparam="utm">facebook</span></span><span class="query-part-separator" data-qpart="separator">&</span><span class="query-param-group" data-qparam="fbclid"><span class="query-part-key" data-qpart="key" data-qparam="fbclid">fbclid</span><span class="query-part-equals" data-qpart="equals" data-qparam="fbclid">=</span><span class="query-part-value" data-qpart="value" data-qparam="fbclid">abc123xyz</span></span>
</div>
<div class="query-legend" role="list" aria-label="Query parameter legend">
<div class="query-legend-section-title">Structure</div>
<div class="query-legend-item" role="listitem" data-qpart="delimiter">
<span class="query-legend-color query-legend-delimiter" aria-hidden="true"></span>
<span class="query-legend-label query-label-delimiter">? Delimiter</span>
<span class="query-legend-desc">Marks the start of query parameters in a URL</span>
</div>
<div class="query-legend-item" role="listitem" data-qpart="key">
<span class="query-legend-color query-legend-key" aria-hidden="true"></span>
<span class="query-legend-label query-label-key">Key</span>
<span class="query-legend-desc">The name of the data being passed</span>
</div>
<div class="query-legend-item" role="listitem" data-qpart="equals">
<span class="query-legend-color query-legend-equals" aria-hidden="true"></span>
<span class="query-legend-label query-label-equals">= Assignment</span>
<span class="query-legend-desc">Connects each key to its value</span>
</div>
<div class="query-legend-item" role="listitem" data-qpart="value">
<span class="query-legend-color query-legend-value" aria-hidden="true"></span>
<span class="query-legend-label query-label-value">Value</span>
<span class="query-legend-desc">The actual data being passed</span>
</div>
<div class="query-legend-item" role="listitem" data-qpart="separator">
<span class="query-legend-color query-legend-separator" aria-hidden="true"></span>
<span class="query-legend-label query-label-separator">& Separator</span>
<span class="query-legend-desc">Separates multiple key-value pairs</span>
</div>
<div class="query-legend-section">
<div class="query-legend-section-title">Parameters in this example</div>
</div>
<div class="query-legend-item" role="listitem" data-qparam="size">
<span class="query-legend-label query-param-label">size=medium</span>
<span class="query-legend-desc">Useful parameter — tells the page which size to select</span>
</div>
<div class="query-legend-item" role="listitem" data-qparam="color">
<span class="query-legend-label query-param-label">color=light%20blue</span>
<span class="query-legend-desc">Useful parameter — tells the page which color variant to show</span>
</div>
<div class="query-legend-item" role="listitem" data-qparam="utm">
<span class="query-legend-label query-param-label">utm_source=facebook</span>
<span class="query-legend-desc">⚠️ Tracking parameter — tells the site you came from Facebook</span>
</div>
<div class="query-legend-item" role="listitem" data-qparam="fbclid">
<span class="query-legend-label query-param-label">fbclid=abc123xyz</span>
<span class="query-legend-desc">⚠️ Tracking parameter — Facebook's click ID to track your activity</span>
</div>
</div>
</div>
<script>
(function() {
const container = document.getElementById('query-container');
const queryExample = container.querySelector('.query-example');
const exampleSpans = container.querySelectorAll('.query-example span[data-qpart]');
const paramGroups = container.querySelectorAll('.query-param-group');
const legendItems = container.querySelectorAll('.query-legend-item');
function clearHighlights() {
container.classList.remove('hovering');
exampleSpans.forEach(s => s.classList.remove('highlighted'));
paramGroups.forEach(g => g.classList.remove('highlighted'));
legendItems.forEach(l => l.classList.remove('highlighted'));
}
// Hovering spans in the example URL - highlight only that single element + related legend items
exampleSpans.forEach(span => {
span.addEventListener('mouseenter', (e) => {
e.stopPropagation(); // Prevent parent group from triggering
clearHighlights();
container.classList.add('hovering');
// Highlight only THIS span
span.classList.add('highlighted');
// Highlight the Structure legend item for this part type
const qpart = span.dataset.qpart;
if (qpart) {
legendItems.forEach(item => {
if (item.dataset.qpart === qpart) {
item.classList.add('highlighted');
}
});
}
// Highlight the Parameter legend item for this parameter
const qparam = span.dataset.qparam;
if (qparam) {
legendItems.forEach(item => {
if (item.dataset.qparam === qparam) {
item.classList.add('highlighted');
}
});
}
});
span.addEventListener('mouseleave', clearHighlights);
});
// Hovering legend items
legendItems.forEach(item => {
item.addEventListener('mouseenter', () => {
clearHighlights();
container.classList.add('hovering');
// Highlight this legend item
item.classList.add('highlighted');
const qpart = item.dataset.qpart;
const qparam = item.dataset.qparam;
// Structure legend: highlight ALL matching URL parts
if (qpart) {
exampleSpans.forEach(span => {
if (span.dataset.qpart === qpart) {
span.classList.add('highlighted');
}
});
}
// Parameter legend (example): highlight the param GROUP container
if (qparam) {
paramGroups.forEach(group => {
if (group.dataset.qparam === qparam) {
group.classList.add('highlighted');
}
});
}
// Scroll to first matching element
let scrollTarget = null;
if (qpart) {
const firstPart = container.querySelector('.query-example [data-qpart="' + qpart + '"]');
if (firstPart) scrollTarget = firstPart;
} else if (qparam) {
const group = container.querySelector('.query-param-group[data-qparam="' + qparam + '"]');
if (group) scrollTarget = group;
}
if (scrollTarget) {
const containerRect = queryExample.getBoundingClientRect();
const partRect = scrollTarget.getBoundingClientRect();
const partCenter = partRect.left - containerRect.left + queryExample.scrollLeft + (partRect.width / 2);
const scrollPos = partCenter - (containerRect.width / 2);
queryExample.scrollTo({ left: scrollPos, behavior: 'smooth' });
}
});
item.addEventListener('mouseleave', clearHighlights);
});
})();
</script>
explain what each part does explain what each part does
explain why a website would want to use query parameters explain why a website would want to use query parameters