diff --git a/news/changelog-1.5.md b/news/changelog-1.5.md index de2d57b28b..bd2173bbea 100644 --- a/news/changelog-1.5.md +++ b/news/changelog-1.5.md @@ -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 diff --git a/src/project/types/website/website-navigation.ts b/src/project/types/website/website-navigation.ts index 788434a95f..6a85276a6c 100644 --- a/src/project/types/website/website-navigation.ts +++ b/src/project/types/website/website-navigation.ts @@ -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); @@ -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); diff --git a/src/project/types/website/website-shared.ts b/src/project/types/website/website-shared.ts index b84a43213a..921ca9fa63 100644 --- a/src/project/types/website/website-shared.ts +++ b/src/project/types/website/website-shared.ts @@ -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) { diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/.gitignore b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/.gitignore new file mode 100644 index 0000000000..97ba89253e --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/.gitignore @@ -0,0 +1,2 @@ +/.quarto/ +_site \ No newline at end of file diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/_quarto.yml b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/_quarto.yml new file mode 100644 index 0000000000..eb735c365e --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/_quarto.yml @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/about.qmd b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/about.qmd new file mode 100644 index 0000000000..46ca80202d --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/about.qmd @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/index.qmd b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/index.qmd new file mode 100644 index 0000000000..86d5c8fb9c --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-external-links/index.qmd @@ -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 \ No newline at end of file diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/.gitignore b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/.gitignore new file mode 100644 index 0000000000..97ba89253e --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/.gitignore @@ -0,0 +1,2 @@ +/.quarto/ +_site \ No newline at end of file diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/_quarto.yml b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/_quarto.yml new file mode 100644 index 0000000000..dbbc3c6ca3 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/_quarto.yml @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/index.qmd b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/index.qmd new file mode 100644 index 0000000000..1452235c24 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title-no-navbar/index.qmd @@ -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 . diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title/.gitignore b/tests/docs/smoke-all/website/sidebar/sidebar-title/.gitignore new file mode 100644 index 0000000000..97ba89253e --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title/.gitignore @@ -0,0 +1,2 @@ +/.quarto/ +_site \ No newline at end of file diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title/_quarto.yml b/tests/docs/smoke-all/website/sidebar/sidebar-title/_quarto.yml new file mode 100644 index 0000000000..103ebbdfa6 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title/_quarto.yml @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title/about.qmd b/tests/docs/smoke-all/website/sidebar/sidebar-title/about.qmd new file mode 100644 index 0000000000..67f64e5161 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title/about.qmd @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/sidebar-title/index.qmd b/tests/docs/smoke-all/website/sidebar/sidebar-title/index.qmd new file mode 100644 index 0000000000..86d7a0c463 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/sidebar-title/index.qmd @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/single-id/.gitignore b/tests/docs/smoke-all/website/sidebar/single-id/.gitignore new file mode 100644 index 0000000000..97ba89253e --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/single-id/.gitignore @@ -0,0 +1,2 @@ +/.quarto/ +_site \ No newline at end of file diff --git a/tests/docs/smoke-all/website/sidebar/single-id/_quarto.yml b/tests/docs/smoke-all/website/sidebar/single-id/_quarto.yml new file mode 100644 index 0000000000..d338fb7ee6 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/single-id/_quarto.yml @@ -0,0 +1,11 @@ +project: + type: website + +website: + title: "Test-sidebar" + sidebar: + - contents: + - reference.qmd + id: reference + +format: html diff --git a/tests/docs/smoke-all/website/sidebar/single-id/index.qmd b/tests/docs/smoke-all/website/sidebar/single-id/index.qmd new file mode 100644 index 0000000000..5fd5037080 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/single-id/index.qmd @@ -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 diff --git a/tests/docs/smoke-all/website/sidebar/single-id/reference.qmd b/tests/docs/smoke-all/website/sidebar/single-id/reference.qmd new file mode 100644 index 0000000000..c509de0f35 --- /dev/null +++ b/tests/docs/smoke-all/website/sidebar/single-id/reference.qmd @@ -0,0 +1,11 @@ +--- +title: reference +_quarto: + tests: + html: + ensureHtmlElements: + - ['nav#quarto-sidebar'] + - [] +--- + +I am the reference page and I should have a sidebar \ No newline at end of file diff --git a/tests/docs/smoke-all/website/.gitignore b/tests/docs/smoke-all/website/simple/.gitignore similarity index 100% rename from tests/docs/smoke-all/website/.gitignore rename to tests/docs/smoke-all/website/simple/.gitignore diff --git a/tests/docs/smoke-all/website/_quarto.yml b/tests/docs/smoke-all/website/simple/_quarto.yml similarity index 100% rename from tests/docs/smoke-all/website/_quarto.yml rename to tests/docs/smoke-all/website/simple/_quarto.yml diff --git a/tests/docs/smoke-all/website/about.qmd b/tests/docs/smoke-all/website/simple/about.qmd similarity index 100% rename from tests/docs/smoke-all/website/about.qmd rename to tests/docs/smoke-all/website/simple/about.qmd diff --git a/tests/docs/smoke-all/website/index.qmd b/tests/docs/smoke-all/website/simple/index.qmd similarity index 100% rename from tests/docs/smoke-all/website/index.qmd rename to tests/docs/smoke-all/website/simple/index.qmd diff --git a/tests/docs/smoke-all/website/styles.css b/tests/docs/smoke-all/website/simple/styles.css similarity index 100% rename from tests/docs/smoke-all/website/styles.css rename to tests/docs/smoke-all/website/simple/styles.css