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

Correctly detect a global sidebar and not a specific page sidebar #9966

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ All changes included in 1.5:
- ([#8977](https://github.com/quarto-dev/quarto-cli/issues/8977)): Don't decorate about links within external link icons.
- ([#8986](https://github.com/quarto-dev/quarto-cli/issues/8986)): Search: only build subfuse index when it's safe to do so.
- ([#9356](https://github.com/quarto-dev/quarto-cli/issues/9356)): Don't process column classes for figures inside the About divs.
- ([#9741](https://github.com/quarto-dev/quarto-cli/issues/9741)): Sidebar is correctly shown globally when title is used in the `sidebar` configuration.
- ([#9781](https://github.com/quarto-dev/quarto-cli/issues/9781)): Correctly hide elements from click event in collapsed margin sidebar.

## Book
Expand Down
10 changes: 5 additions & 5 deletions src/project/types/website/website-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ export async function websiteNavigationExtras(
const href = target?.outputHref || inputFileHref(inputRelative);
const sidebar = sidebarForHref(href, format);

// if the sidebar has a title and no id generate the id
if (sidebar && sidebar.title && !sidebar.id) {
sidebar.id = asHtmlId(sidebar.title);
}

// Forward the draft mode, if present
const draftMode = projectDraftMode(project);

Expand Down Expand Up @@ -1003,11 +1008,6 @@ async function sidebarsEjsData(project: ProjectContext, sidebars: Sidebar[]) {
async function sidebarEjsData(project: ProjectContext, sidebar: Sidebar) {
sidebar = ld.cloneDeep(sidebar);

// if the sidebar has a title and no id generate the id
if (sidebar.title && !sidebar.id) {
sidebar.id = asHtmlId(sidebar.title);
}

// ensure title and search are present
sidebar.title = sidebarTitle(sidebar, project) as string | undefined;
sidebar.logo = resolveLogo(sidebar.logo);
Expand Down
9 changes: 5 additions & 4 deletions src/project/types/website/website-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,21 @@ export const navigation: Navigation = {
};

export function sidebarForHref(href: string, format: Format) {
const sidebars = ld.cloneDeep(navigation.sidebars) as Sidebar[];
// if there is a single sidebar then it applies to all hrefs
// (unless it has an id, in which restrict it)
if (
navigation.sidebars.length === 1 && navigation.sidebars[0].id === undefined
sidebars.length === 1 && sidebars[0].id === undefined
) {
return navigation.sidebars[0];
return sidebars[0];
} else {
const explicitSidebar = navigation.sidebars.find((sidebar) => {
const explicitSidebar = sidebars.find((sidebar) => {
return sidebar.id === format.metadata[kSiteSidebar];
});
if (explicitSidebar) {
return explicitSidebar;
} else {
const containingSidebar = navigation.sidebars.find((sidebar) => {
const containingSidebar = sidebars.find((sidebar) => {
return containsHref(href, sidebar.contents);
});
if (containingSidebar) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
_site
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project:
type: website

website:
title: "Test"
page-navigation: true

navbar:
left:
- text: "External working"
href: "https://quarto.org"
target: "_blank"

sidebar:
- title: "Dropdown"
contents:
- text: "External working"
href: "https://quarto.org"
target: "_blank"

format:
html: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "About page"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'nav.navbar li.nav-item a.nav-link span.menu-text'
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
- []
---

This is an about page that should also have a sidebar
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Sidebar-title"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'nav.navbar li.nav-item a.nav-link span.menu-text'
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
- []

---

This test is based on issue https://github.com/quarto-dev/quarto-cli/issues/9242
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
_site
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project:
type: website

website:
title: "Test"
page-navigation: true

sidebar:
- title: "Dropdown"
contents:
- text: "External working"
href: "https://quarto.org"
target: "_blank"
- index.qmd

format:
html: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: "Sidebar-title"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'nav#quarto-sidebar div.sidebar-title'
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
- 'nav#quarto-sidebar li.sidebar-item a.sidebar-link span.menu-text'
- []

---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
2 changes: 2 additions & 0 deletions tests/docs/smoke-all/website/sidebar/sidebar-title/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
_site
21 changes: 21 additions & 0 deletions tests/docs/smoke-all/website/sidebar/sidebar-title/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
project:
type: website

website:
title: "Test"

navbar:
left:
- href: index.qmd
text: Home

sidebar:
title: "Contents"
contents:
- section: About
contents:
- href: about.qmd
text: About

format:
html: default
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/website/sidebar/sidebar-title/about.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "About page"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'nav.navbar li.nav-item a.nav-link'
- 'nav#quarto-sidebar li.sidebar-item a.sidebar-link span.menu-text'
- 'nav#quarto-sidebar li.sidebar-item ul.sidebar-section'
- []
---

This is an about page that should also have a sidebar
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/website/sidebar/sidebar-title/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Sidebar-title"
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'nav.navbar li.nav-item a.nav-link'
- 'nav#quarto-sidebar li.sidebar-item a.sidebar-link span.menu-text'
- 'nav#quarto-sidebar li.sidebar-item ul.sidebar-section'
- []
---

This test covers https://github.com/quarto-dev/quarto-cli/discussions/8869
2 changes: 2 additions & 0 deletions tests/docs/smoke-all/website/sidebar/single-id/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
_site
11 changes: 11 additions & 0 deletions tests/docs/smoke-all/website/sidebar/single-id/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
project:
type: website

website:
title: "Test-sidebar"
sidebar:
- contents:
- reference.qmd
id: reference

format: html
11 changes: 11 additions & 0 deletions tests/docs/smoke-all/website/sidebar/single-id/index.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: "Test-sidebar"
_quarto:
tests:
html:
ensureHtmlElements:
- []
- ['nav#quarto-sidebar']
---

I am the index page and I should have no sidebar
11 changes: 11 additions & 0 deletions tests/docs/smoke-all/website/sidebar/single-id/reference.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: reference
_quarto:
tests:
html:
ensureHtmlElements:
- ['nav#quarto-sidebar']
- []
---

I am the reference page and I should have a sidebar