Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Shouldn't frontmatter.title override extracted H1? #710

Closed
Huxpro opened this issue Mar 5, 2024 · 4 comments
Closed

[Bug]: Shouldn't frontmatter.title override extracted H1? #710

Huxpro opened this issue Mar 5, 2024 · 4 comments
Labels
🐞 bug Something isn't working

Comments

@Huxpro
Copy link

Huxpro commented Mar 5, 2024

Version

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Max
    Memory: 176.88 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 122.0.6261.94
    Safari: 17.0

Details

According to https://rspress.dev/api/config/config-frontmatter.html#front-matter-config:

By default, the page's h1 heading will be used as the title of the HTML document. But if you want to use a different title, you can use Front Matter to specify the title of the page.

I assumed this meant the frontmatter.title, when given, should always be chosen over h1 heading, but the h1 heading would be chosen in the sidebar.

By inspecting the source code, it seems like this is the reason:

// plugin-auto-nav-sidebar 

export async function extractH1Title(...) {
  ...
  const match = content.match(h1RegExp);
  
  if (!match) {
    // only fallback to frontmatter.title when h1 is not found
    const { frontmatter } = loadFrontMatter(content, filePath, rootDir);
    return frontmatter.title || fileNameWithoutExt;
  } else {
    return match[1] || fileNameWithoutExt;
  }
}

See:

if (!match) {
const { frontmatter } = loadFrontMatter(content, filePath, rootDir);
return frontmatter.title || fileNameWithoutExt;
} else {
return match[1] || fileNameWithoutExt;
}

Shall we change this?

Reproduce link

https://applink.larksuite.com/client/message/link/open?token=AmRKLqSagAAFZedZ1TCAAAY%3D

Reproduce Steps

For instance, when given:

---
title: <canvas>
---

# `<canvas>`

I will have

`<canvas>`

rather than

<canvas>

rendered in the sidebar.

@Huxpro Huxpro added the 🐞 bug Something isn't working label Mar 5, 2024
@sanyuan0704
Copy link
Collaborator

Thanks for the detailed feedback. Now the pr #711 has corrected the priority of frontmatter.title.

Example:

---
title: <canvas>
---

# `<canvas>`

image

@Huxpro
Copy link
Author

Huxpro commented Mar 6, 2024

@sanyuan0704 Thanks for the fix!

As a follow-up, can we also have Rspress natively support code-formatted h1 rendered in sidenav as monospaced fonts?

@sanyuan0704
Copy link
Collaborator

sanyuan0704 commented Mar 7, 2024

image

Currently the code-formatted h1 rendered in sidenav has supported monospaced fonts

@Huxpro
Copy link
Author

Huxpro commented Mar 8, 2024

@sanyuan0704 BEAUTIFUL! thanks for the work ;)

@Huxpro Huxpro closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants