quarto-dev / quarto-dev/quarto-cli

Wrong category link when post is contained in multiple listings

Open
#14,493 1 comment 0 reactions 1 assignee View on GitHub

@mcanouil is already working on this.

Since May 6, 2026.

bug listings
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

I have:
  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI
  • formatted my issue following the Bug Reports guide
Bug description

Category links go to the wrong location when there are multiple listings.

We have this issue on https://topos.institute

Minimal reproduction: https://github.com/ToposInstitute/quarto-category-link-bug-repro

Steps to reproduce
git clone https://github.com/ToposInstitute/quarto-category-link-bug-repro.git
cd quarto-category-link-bug-repro
quarto preview
  • http://localhost:5142/
  • Go to "Post one"
  • Click on the "Alpha" category
Actual behavior

Goes to http://localhost:5142/index.html#category=alpha which does not filter by category

Expected behavior

Goes to http://localhost:5142/blog/index.html#category=alpha

LLM diagnosis:

Root cause

src/resources/formats/html/quarto.js defines findNearestParentListing:

const findNearestParentListing = (href, listingHrefs) => {
  if (!href || !listingHrefs) return undefined;
  const relativeParts = href.substring(1).split("/");
  while (relativeParts.length > 0) {
    const path = relativeParts.join("/");           // "blog/post-one/", "blog/post-one", "blog", ""
    for (const listingHref of listingHrefs) {
      if (listingHref.startsWith(path)) return listingHref; // listingHref is "/blog/index.html"
    }
    relativeParts.pop();
  }
  return undefined;
};

listingHrefs entries always begin with / (e.g. /blog/index.html,
/index.html); path is built without a leading slash. So
"/blog/index.html".startsWith("blog/post-one/") is false, and so are all
later iterations until path === "", which matches every listing. The
function therefore returns listingHrefs[0] — whatever happens to be first.

In this repro /index.html ends up first in listings.json, so all post
categories link to the home page.

Suggested fix

Compare against a leading slash, or use a "longest-directory-prefix" match:

const findNearestParentListing = (href, listingHrefs) => {
  if (!href || !listingHrefs?.length) return undefined;
  const postDir = href.replace(/[^/]+$/, "");        // "/blog/post-one/"
  let best, bestLen = -1;
  for (const listingHref of listingHrefs) {
    const listingDir = listingHref.replace(/[^/]+$/, ""); // "/blog/"
    if (postDir.startsWith(listingDir) && listingDir.length > bestLen) {
      best = listingHref;
      bestLen = listingDir.length;
    }
  }
  return best;
};
Your environment

NixOS
Quarto 1.10.3 pre-release

Quarto check output
Quarto 1.10.3
[✓] Checking environment information...
      Quarto cache location: /home/kaspar/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.8.3: OK
      Dart Sass version 1.87.0: OK
      Deno version 2.4.5: OK
      Typst version 0.14.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.10.3
      Path: /nix/store/0nyh651yyjjd03l8mhdj1csrj4c7jnd4-quarto-1.10.3/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chrome Headless Shell: (not installed)
      VeraPDF: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /nix/store/ig6nbiwhs9zp54vzaj2ry00pzcs88lbx-texlive-combined-2025/bin
      Version: undefined

[✓] Checking Chrome Headless....................OK
      Chrome:  (not detected)

[✓] Checking basic markdown render....OK

[✓] Checking R installation...........OK
      Version: 4.5.3
      Path: /nix/store/fcw23ybidpqhmpb9vy0mw1056kwrshj3-R-4.5.3/lib/R
      LibPaths:
        - /nix/store/3lmrlsa5n045v7zjkd6qlpx8qs01xgb8-r-boot-1.3-32/library
        - /nix/store/9fnys5mz7pm1yjria0qm69ynhdsssgcf-r-class-7.3-23/library
        - /nix/store/ifdar5sqaviz7c3shv2shg6j3lrkgrg6-r-MASS-7.3-65/library
        - /nix/store/3i00292cpb9ii5hmx1vgfg9mdvbiaxbd-r-cluster-2.1.8.2/library
        - /nix/store/bd7hciv46ap68k27c50hd2cs4q0f1xfg-r-codetools-0.2-20/library
        - /nix/store/wffg47yipql9c0igjlk4rs7p825rakf2-r-foreign-0.8-91/library
        - /nix/store/xp2gnmw3wx3w1qk45rfl77wddf12xx67-r-KernSmooth-2.23-26/library
        - /nix/store/cn6jgqgv5ggmhizfqamfm8zcjqxgysl5-r-lattice-0.22-9/library
        - /nix/store/za9mrhpsa17dwm0dnwaar5cv6rlka9g4-r-Matrix-1.7-4/library
        - /nix/store/pwy1wvgqzmywg8ld4336408krx35i6wh-r-mgcv-1.9-4/library
        - /nix/store/1yv2vki8d00x8syfi4lcinpavzismf41-r-nlme-3.1-168/library
        - /nix/store/r7ch4bc034mbkb2d7kqx27x2x2y10dz4-r-nnet-7.3-20/library
        - /nix/store/08px77qk2hza1f2kj9brkf2b3q4fmram-r-rpart-4.1.24/library
        - /nix/store/dkvqs2y78s13mry6778x6mbx9w6bbivc-r-spatial-7.3-18/library
        - /nix/store/sc04dzp7b9dqyfh0gb40vcx3mhfqi9zr-r-survival-3.8-6/library
        - /nix/store/jqpi0xcfigrrw70wgfyz9q85ig98nn1h-r-bookdown-0.46/library
        - /nix/store/wmd5yqrcwjcablfhhhy4s4jkzmng3r7y-r-htmltools-0.5.9/library
        - /nix/store/nar7qidilb16lgw5dx2ilx8w5vdmng22-r-base64enc-0.1-6/library
        - /nix/store/hpkrh5vkjcznqy1cgmw17aa17z2clnip-r-digest-0.6.39/library
        - /nix/store/9ah58ycg9klsxh8f2c75jfiwaqns3pg5-r-fastmap-1.2.0/library
        - /nix/store/6k0g8hkkvin20g4ifzc0v62qrbfhs5dq-r-rlang-1.1.7/library
        - /nix/store/63snv1kygk1n84b4q1y5bgb6h3n0757l-r-jquerylib-0.1.4/library
        - /nix/store/lw55lljf2yzdrw2bzm7h1l6031xw4v5f-r-knitr-1.51/library
        - /nix/store/py73zc3bhci0afbajwn9wddxdsw6c975-r-evaluate-1.0.5/library
        - /nix/store/b1hrij2ssy0bikkn3jjplq2xggs2xj1s-r-highr-0.12/library
        - /nix/store/pgj2m4347brfrv2aklm3897vjrx0avmb-r-xfun-0.56/library
        - /nix/store/5z1kiyw7b5krdhkppf80454lhgl6953c-r-yaml-2.3.12/library
        - /nix/store/zrri0mljgjf4m8064cq4nshlnk7b8vlc-r-rmarkdown-2.30/library
        - /nix/store/4xv8ahw58mg02nv182vg0924zgmqmfms-r-bslib-0.10.0/library
        - /nix/store/yl4jc63g2d2abbf4frl784h67acf03dv-r-cachem-1.1.0/library
        - /nix/store/ighk6ypmk1rgi5540fl9bgw2s444ijrl-r-jsonlite-2.0.0/library
        - /nix/store/54n22r9665dki1qk9f6yn4lv591z3gd8-r-lifecycle-1.0.5/library
        - /nix/store/40p35hd1sfynkx5acg6x2pv4di1cfppx-r-cli-3.6.5/library
        - /nix/store/fxiss7f7wr6pkn4m3yzna0qlsb6k6lsf-r-memoise-2.0.1/library
        - /nix/store/r8ry9i1mwgf0xmk8cwlidkwb4sn2nnyh-r-mime-0.13/library
        - /nix/store/6gvdhyalg9cyc4mad03s9lzfc7c58z3g-r-sass-0.4.10/library
        - /nix/store/kb04xwdvvvpnnc13rj18krgnrybs772y-r-R6-2.6.1/library
        - /nix/store/vb60bz0ssgw6f06cibkrhqxm3w534pwy-r-fs-1.6.7/library
        - /nix/store/yssnj4hbq6n67ilvxwbjhn43rxs05rq8-r-rappdirs-0.3.4/library
        - /nix/store/50sxj6qgizi9mfyjw1377jkxll1nhb5w-r-fontawesome-0.5.3/library
        - /nix/store/pgbc5ma8ypxjrrfp6qbs5g1f26zsgh8h-r-tinytex-0.58/library
        - /nix/store/lcw1173jmx3ds1hpn9142vgj03bdxmpk-r-magick-2.9.1/library
        - /nix/store/1dmnf83fac2bxcl4yzdsbzzx6vlbgwj5-r-Rcpp-1.1.1/library
        - /nix/store/xg2mywggfia22dr4rjbmq0xfqx3af9p8-r-curl-7.0.0/library
        - /nix/store/q11kwpq4b5g8wdy0rb88lkr9988q9fx2-r-magrittr-2.0.4/library
        - /nix/store/gb21i275mcbhlcbzz85bqh0p46czy064-r-pdftools-3.7.0/library
        - /nix/store/wh8bbrw59gm8pf5176y1zlkzr1cfm9fg-r-qpdf-1.4.1/library
        - /nix/store/s0qzs0iijj7dxsza1wlbk37ac02s01wk-r-askpass-1.2.1/library
        - /nix/store/2zxgp9lf02aqn3i0vd94lik8pvy8si8k-r-sys-3.4.3/library
        - /nix/store/qv645xhyf7lxnzxqvsqsy68vfbxab609-r-here-1.0.2/library
        - /nix/store/2hlxqi5vv0ljid65d2a20fn7wsyamhmp-r-rprojroot-2.1.1/library
        - /nix/store/8knbg28xgsqcwkc0zqxmvv4ry9nl7jzk-r-JuliaCall-0.17.6/library
        - /nix/store/7d487gcbmh3g0cxhllbbr8j6va1s7kpj-r-rjson-0.2.23/library
        - /nix/store/fcw23ybidpqhmpb9vy0mw1056kwrshj3-R-4.5.3/lib/R/library
      knitr: 1.51
      rmarkdown: 2.30

[✓] Checking Knitr engine render......OK

[✓] Checking Python 3 installation....OK
      Version: 3.13.12
      Path: /run/current-system/sw/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking Julia installation...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.