Skip to content

Conversation

@mcanouil
Copy link
Collaborator

@mcanouil mcanouil commented Mar 14, 2025

Enhance the listing templates by conditionally adding a target attribute to links.
This allows for better control over link behaviour, enabling users to open links in new tabs if specified.

---
title: "12276"
listing:
  contents:
    - path: posts/post-with-code/index.qmd
      target: _blank
    - path: posts/welcome/index.qmd
  sort: "date desc"
  type: default
  categories: true
  sort-ui: false
  filter-ui: false
page-layout: full
title-block-banner: true
---
Screen.Recording.2025-03-14.at.21.43.08.mov

Originally discussed in:

@mcanouil mcanouil self-assigned this Mar 14, 2025
@mcanouil mcanouil marked this pull request as draft March 14, 2025 21:26
@cscheid cscheid added this to the v1.8 milestone Apr 2, 2025
@mcanouil mcanouil added the needs-discussion Issues that require a team-wide discussion before proceeding further label Aug 19, 2025
@cscheid cscheid modified the milestones: v1.8, v1.9 Aug 20, 2025
@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Jan 15, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mcanouil mcanouil removed the needs-discussion Issues that require a team-wide discussion before proceeding further label Jan 15, 2026
@mcanouil mcanouil marked this pull request as ready for review January 15, 2026 09:56
Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition.

If I see the value of the feature, I am wondering if this is best field name. target is a bit broad when you don't know about the usage.
And it opens also question for other link attribute. For example, with target="_blank" you usually want to add rel="noopener noreferrer" for security.

It fiels a bit weird to have such fields that controls listing links rededring at top level.

But that is just first impression here. I am thinking about better organization or naming.

For example, what if need to allow aria-label addition for those link ? if it should be controlled by user, it would be another field ?

I wonder if we should have something closer to manuscript code-links
https://quarto.org/docs/manuscripts/components.html#code-links

listing-link:
  target: "_blank"
  rel: "noopener noreferrer"
  aria-label: "Opens in new window"

This would allow adding schema maybe.

Also, doc related: this is kind of a special metadata field that needs to go into the list of known ones
https://quarto.org/docs/websites/website-listings.html#listing-fields

I think it is good to always have doc in mind which each PR.

This is the kind of PR that seems simple to fix, but requires some thinking for best long term behavior.

Regarding code review, you need to be thorough. I believe if you add a field to template you need to update that part too

// Fields
const fields = listing.fields;
// Image properties
const imageAlign = listing['image-align'] || 'left';
const imageHeight = listing['image-height'];
// Fields that don't have a known place to be displayed in this template
const otherFields = fields.filter(field => {
return !["title", "image", "image-alt", "date", "author", "subtitle", "description", "reading-time", "categories"].includes(field);
});

Otherwise the field will end up in a metadata-value div, which I don't think we want here right ?

Anyhow, open to discussion.

@mcanouil
Copy link
Collaborator Author

mcanouil commented Jan 15, 2026

You're right that target should be added to the undisplayable fields list (not in the template side) to prevent it from appearing when using pure metadata-sourced listings or custom templates.
I'm fixing it, but I believe it should be in:

@mcanouil
Copy link
Collaborator Author

mcanouil commented Jan 15, 2026

Also, doc related: this is kind of a special metadata field that needs to go into the list of known ones
https://quarto.org/docs/websites/website-listings.html#listing-fields

I think it is good to always have doc in mind which each PR.

This PR is one year old and as you pointed needs a bit of discussion to generalise it (also why I initially added the label).


Few notes:

  • The "noopener" ("noreferrer" does not seem to be used) is also missing for Manuscript code-links (repo, devcontainer, binder).
  • If an interface for "links" is created it could be used more thoroughly in the codebase. This would require a bit more work but seems worth it to have consistency.

@mcanouil mcanouil added the needs-discussion Issues that require a team-wide discussion before proceeding further label Jan 15, 2026
@cderv
Copy link
Collaborator

cderv commented Jan 15, 2026

If an interface for "links" is created it could be used more thoroughly in the codebase. This would require a bit more work but seems worth it to have consistency.

Yes, that is why sometimes a feature that seems nice and easy to do can lead to more design question, and more thoughts needed. Generally why contributed feature PR takes time to review and think about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-discussion Issues that require a team-wide discussion before proceeding further

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants