defuss-shadcn / Website / Blog / archive-index
Archive IndexBLK
Links to content grouped by publication year or month - native disclosures with post counts, or the years side by side. Part of the Blog blocks.
On this page (6)
§Default
One native details per year; the shared name makes them exclusive - open 2025 and 2026 closes. Counts sit at the end of each row.
§Columns
data-variant='columns': the years side by side, each open - an archive page rather than a sidebar.
§Calendar
data-variant='calendar': every month a cell, shaded by how much was published (data-level 0-4 on the link) - a contribution graph for an archive. Each cell is a link; the label names month and count.
§Timeline
The archive on the Timeline component: one entry per year - the title carries a count Badge, the months are pill links with their counts (.mk-archive-index-months; aria-current fills the month you are reading), and the year closes with its most-read post (.mk-archive-index-pick).
§Tags
.mk-archive-index-tags: a tag cloud - data-weight 1-5 scales size and weight, the heaviest takes the primary colour. Counts in <sup>.
§CSS view file
/* -- Archive Index (website) ---------------------------------------- Links to content grouped by year and month. Each year is a native <details> disclosure (name= makes them exclusive), its months a list of links with post counts. columns: every year open, side by side. */@layer components { .mk-archive-index { display: flex; flex-direction: column; gap: 0.25rem; box-sizing: border-box; width: 100%; font-size: 0.875rem; } .mk-archive-index-title { margin: 0 0 0.5rem; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted-foreground); } .mk-archive-index-year { interpolate-size: allow-keywords; border-block-end: 1px solid var(--border); &::details-content { block-size: 0; overflow: clip; transition: block-size 200ms ease, content-visibility 200ms allow-discrete; } &[open]::details-content { block-size: auto; } & > summary { display: flex; align-items: center; gap: 0.5rem; padding-block: 0.625rem; font-weight: 600; cursor: pointer; list-style: none; &::-webkit-details-marker { display: none; } &::after { content: ""; width: 0.4375rem; height: 0.4375rem; margin-inline-start: 0.25rem; border-inline-end: 1.5px solid currentColor; border-block-end: 1.5px solid currentColor; rotate: -45deg; opacity: 0.6; transition: rotate 200ms ease; } &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius-sm); } } &[open] > summary::after { rotate: 45deg; } & ul { display: flex; flex-direction: column; margin: 0; padding: 0 0 0.5rem; list-style: none; } & li { display: flex; align-items: center; gap: 0.5rem; } & li a { flex: 1; padding: 0.3125rem 0.5rem; margin-inline-start: -0.5rem; border-radius: var(--radius-sm); color: var(--muted-foreground); text-decoration: none; &:hover { background: var(--accent); color: var(--accent-foreground); } &[aria-current] { color: var(--foreground); font-weight: 500; } &:focus-visible { outline: 2px solid var(--ring); outline-offset: 0; } } } /* the year's count sits after its label; a month's at the row end */ .mk-archive-index-count { margin-inline-start: auto; min-width: 1.5rem; padding: 0.0625rem 0.4375rem; border-radius: 999px; background: var(--muted); color: var(--muted-foreground); font-size: 0.75rem; font-weight: 500; font-variant-numeric: tabular-nums; text-align: center; } .mk-archive-index-year > summary .mk-archive-index-count { order: 1; margin-inline-start: auto; } .mk-archive-index-year > summary::after { order: 2; } /* columns: the years side by side, each list open */ .mk-archive-index[data-variant="columns"] { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 1rem 2rem; & .mk-archive-index-title { grid-column: 1 / -1; } & .mk-archive-index-year { border-block-end: 0; border-block-start: 2px solid var(--foreground); } } /* calendar: each year a 6 × 2 grid of months, shaded by how much was published (data-level 0-4 on the link, like a contribution graph) */ .mk-archive-index[data-variant="calendar"] { gap: 1rem; & .mk-archive-index-year { border: 0; } & .mk-archive-index-year > summary::after { display: none; } & .mk-archive-index-year > summary { cursor: default; pointer-events: none; padding-block: 0 0.375rem; } & .mk-archive-index-year ul { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.375rem; padding: 0; } & .mk-archive-index-year li { flex-direction: column; gap: 0.125rem; } & .mk-archive-index-year li a { --_level: 0%; display: grid; place-items: center; width: 100%; aspect-ratio: 1.4; margin: 0; padding: 0; border-radius: var(--radius-md); background: color-mix(in oklch, var(--primary) var(--_level), var(--muted)); color: var(--foreground); font-size: 0.75rem; font-weight: 500; &[data-level="1"] { --_level: 20%; } &[data-level="2"] { --_level: 40%; } &[data-level="3"] { --_level: 65%; color: var(--primary-foreground); } &[data-level="4"] { --_level: 90%; color: var(--primary-foreground); } &:hover { outline: 2px solid var(--ring); outline-offset: 1px; background: color-mix(in oklch, var(--primary) var(--_level), var(--muted)); } } & .mk-archive-index-year li .mk-archive-index-count { margin: 0; padding: 0; background: none; min-width: 0; font-size: 0.6875rem; } } /* a legend under the calendar */ .mk-archive-index-legend { display: flex; align-items: center; gap: 0.25rem; color: var(--muted-foreground); font-size: 0.6875rem; & i { width: 0.75rem; height: 0.75rem; border-radius: 3px; background: var(--muted); } & i:nth-of-type(2) { background: color-mix(in oklch, var(--primary) 20%, var(--muted)); } & i:nth-of-type(3) { background: color-mix(in oklch, var(--primary) 40%, var(--muted)); } & i:nth-of-type(4) { background: color-mix(in oklch, var(--primary) 65%, var(--muted)); } & i:nth-of-type(5) { background: color-mix(in oklch, var(--primary) 90%, var(--muted)); } } /* tags: a cloud - data-weight 1-5 scales a tag */ .mk-archive-index-tags { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.875rem; margin: 0; padding: 0; list-style: none; & a { color: var(--foreground); font-size: calc(0.75rem + (var(--_w, 1) - 1) * 0.25rem); font-weight: calc(400 + (var(--_w, 1) - 1) * 75); line-height: 1.3; text-decoration: none; &[data-weight="2"] { --_w: 2; } &[data-weight="3"] { --_w: 3; } &[data-weight="4"] { --_w: 4; } &[data-weight="5"] { --_w: 5; color: var(--primary); } &:hover { text-decoration: underline; text-underline-offset: 0.2em; } &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius-sm); } } & sup { color: var(--muted-foreground); font-size: 0.625rem; font-weight: 400; margin-inline-start: 0.125rem; } } /* month chips - pill links with their counts (inside a Timeline entry, a card, anywhere a compact month list fits) */ .mk-archive-index-months { display: flex; flex-wrap: wrap; gap: 0.375rem; margin: 0.5rem 0 0; padding: 0; list-style: none; & a { display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.25rem 0.375rem 0.25rem 0.75rem; border: 1px solid var(--border); border-radius: 999px; background: var(--background); color: var(--foreground); font-size: 0.8125rem; font-weight: 500; text-decoration: none; transition: background-color 120ms, border-color 120ms; &:hover { border-color: color-mix(in oklch, var(--foreground) 30%, var(--border)); background: var(--accent); } &[aria-current] { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); } &[aria-current] .mk-archive-index-count { background: color-mix(in oklch, var(--primary-foreground) 20%, transparent); color: inherit; } &:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; } } & .mk-archive-index-count { margin: 0; } } /* the year's highlight under the chips: "Most read: …" */ .mk-archive-index-pick { display: flex; align-items: baseline; gap: 0.375rem; margin-block-start: 0.5rem; color: var(--muted-foreground); font-size: 0.8125rem; & a { color: var(--foreground); font-weight: 500; text-decoration: none; } & a:hover { text-decoration: underline; text-underline-offset: 0.2em; } } /* -- Accessibility ------------------------------------------- */ @media (prefers-reduced-motion: reduce) { .mk-archive-index-year::details-content, .mk-archive-index-year > summary::after { transition: none; } .mk-archive-index-months a { transition: none; } } @media (prefers-contrast: more) { .mk-archive-index-year li a, .mk-archive-index-count { color: var(--foreground); } } @media (forced-colors: active) { .mk-archive-index-year li a { color: LinkText; } .mk-archive-index-count { border: 1px solid CanvasText; } }}Comments, ideas or improvements? Edit this page's source on GitHub