Skip to content

Commit 7d24d71

Browse files
authored
Merge pull request #9741 from quarto-dev/website/sidebar-global
2 parents 024b610 + 411451c commit 7d24d71

File tree

23 files changed

+184
-9
lines changed

23 files changed

+184
-9
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ All changes included in 1.5:
6161
- ([#8977](https://github.com/quarto-dev/quarto-cli/issues/8977)): Don't decorate about links within external link icons.
6262
- ([#8986](https://github.com/quarto-dev/quarto-cli/issues/8986)): Search: only build subfuse index when it's safe to do so.
6363
- ([#9356](https://github.com/quarto-dev/quarto-cli/issues/9356)): Don't process column classes for figures inside the About divs.
64+
- ([#9741](https://github.com/quarto-dev/quarto-cli/issues/9741)): Sidebar is correctly shown globally when title is used in the `sidebar` configuration.
6465
- ([#9781](https://github.com/quarto-dev/quarto-cli/issues/9781)): Correctly hide elements from click event in collapsed margin sidebar.
6566

6667
## Book

src/project/types/website/website-navigation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ export async function websiteNavigationExtras(
288288
const href = target?.outputHref || inputFileHref(inputRelative);
289289
const sidebar = sidebarForHref(href, format);
290290

291+
// if the sidebar has a title and no id generate the id
292+
if (sidebar && sidebar.title && !sidebar.id) {
293+
sidebar.id = asHtmlId(sidebar.title);
294+
}
295+
291296
// Forward the draft mode, if present
292297
const draftMode = projectDraftMode(project);
293298

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

1006-
// if the sidebar has a title and no id generate the id
1007-
if (sidebar.title && !sidebar.id) {
1008-
sidebar.id = asHtmlId(sidebar.title);
1009-
}
1010-
10111011
// ensure title and search are present
10121012
sidebar.title = sidebarTitle(sidebar, project) as string | undefined;
10131013
sidebar.logo = resolveLogo(sidebar.logo);

src/project/types/website/website-shared.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,21 @@ export const navigation: Navigation = {
342342
};
343343

344344
export function sidebarForHref(href: string, format: Format) {
345+
const sidebars = ld.cloneDeep(navigation.sidebars) as Sidebar[];
345346
// if there is a single sidebar then it applies to all hrefs
346347
// (unless it has an id, in which restrict it)
347348
if (
348-
navigation.sidebars.length === 1 && navigation.sidebars[0].id === undefined
349+
sidebars.length === 1 && sidebars[0].id === undefined
349350
) {
350-
return navigation.sidebars[0];
351+
return sidebars[0];
351352
} else {
352-
const explicitSidebar = navigation.sidebars.find((sidebar) => {
353+
const explicitSidebar = sidebars.find((sidebar) => {
353354
return sidebar.id === format.metadata[kSiteSidebar];
354355
});
355356
if (explicitSidebar) {
356357
return explicitSidebar;
357358
} else {
358-
const containingSidebar = navigation.sidebars.find((sidebar) => {
359+
const containingSidebar = sidebars.find((sidebar) => {
359360
return containsHref(href, sidebar.contents);
360361
});
361362
if (containingSidebar) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
_site
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "Test"
6+
page-navigation: true
7+
8+
navbar:
9+
left:
10+
- text: "External working"
11+
href: "https://quarto.org"
12+
target: "_blank"
13+
14+
sidebar:
15+
- title: "Dropdown"
16+
contents:
17+
- text: "External working"
18+
href: "https://quarto.org"
19+
target: "_blank"
20+
21+
format:
22+
html: default
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "About page"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- 'nav.navbar li.nav-item a.nav-link span.menu-text'
9+
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
10+
- []
11+
---
12+
13+
This is an about page that should also have a sidebar
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "Sidebar-title"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- 'nav.navbar li.nav-item a.nav-link span.menu-text'
9+
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
10+
- []
11+
12+
---
13+
14+
This test is based on issue https://github.com/quarto-dev/quarto-cli/issues/9242
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
_site
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "Test"
6+
page-navigation: true
7+
8+
sidebar:
9+
- title: "Dropdown"
10+
contents:
11+
- text: "External working"
12+
href: "https://quarto.org"
13+
target: "_blank"
14+
- index.qmd
15+
16+
format:
17+
html: default
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: "Sidebar-title"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- 'nav#quarto-sidebar div.sidebar-title'
9+
- 'nav#quarto-sidebar li.sidebar-item a[href*="quarto.org"].sidebar-link'
10+
- 'nav#quarto-sidebar li.sidebar-item a.sidebar-link span.menu-text'
11+
- []
12+
13+
---
14+
15+
This is a Quarto website.
16+
17+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.

0 commit comments

Comments
 (0)