diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 8738fe9a799..042a99dea9f 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -104,6 +104,7 @@ All changes included in 1.6: - ([#10567](https://github.com/quarto-dev/quarto-cli/issues/10567)): Generate breadcrumbs correctly for documents using a level-1 heading as the title. - ([#10616](https://github.com/quarto-dev/quarto-cli/issues/10268)): Add a `z-index` setting to the 'back to top' button to ensure it is always visible. - ([#10864](https://github.com/quarto-dev/quarto-cli/issues/10864)): Support detection of `og:image:alt` attribute from auto-discovered images. +- ([#9905](https://github.com/quarto-dev/quarto-cli/issues/9905)): Setting `search: false` in `navbar` config for `website` in `_quarto.yml` correctly opt-out sidebar. ### Quarto Blog diff --git a/src/project/types/website/website-navigation.ts b/src/project/types/website/website-navigation.ts index 26574ac823a..614c1cf4fdb 100644 --- a/src/project/types/website/website-navigation.ts +++ b/src/project/types/website/website-navigation.ts @@ -1232,7 +1232,9 @@ async function navbarEjsData( const searchOpts = await searchOptions(project); const data: Navbar = { ...navbar, - search: searchOpts && searchOpts.location === "navbar" + search: navbar.search !== undefined + ? navbar.search + : searchOpts && searchOpts.location === "navbar" ? searchOpts.type : false, background: navbar.background || "primary", diff --git a/tests/docs/search/issue-9905/.gitignore b/tests/docs/search/issue-9905/.gitignore new file mode 100644 index 00000000000..a01d10b4016 --- /dev/null +++ b/tests/docs/search/issue-9905/.gitignore @@ -0,0 +1,2 @@ +.quarto/ +_site/ \ No newline at end of file diff --git a/tests/docs/search/issue-9905/navbar/.gitignore b/tests/docs/search/issue-9905/navbar/.gitignore new file mode 100644 index 00000000000..075b2542afb --- /dev/null +++ b/tests/docs/search/issue-9905/navbar/.gitignore @@ -0,0 +1 @@ +/.quarto/ diff --git a/tests/docs/search/issue-9905/navbar/_quarto.yml b/tests/docs/search/issue-9905/navbar/_quarto.yml new file mode 100644 index 00000000000..f53f806e0ed --- /dev/null +++ b/tests/docs/search/issue-9905/navbar/_quarto.yml @@ -0,0 +1,14 @@ +project: + type: website + +website: + title: "search opt out" + search: + location: sidebar + navbar: + search: false + left: + - href: index.qmd + text: Home + +format: html diff --git a/tests/docs/search/issue-9905/navbar/index.qmd b/tests/docs/search/issue-9905/navbar/index.qmd new file mode 100644 index 00000000000..c4aabb1e3ab --- /dev/null +++ b/tests/docs/search/issue-9905/navbar/index.qmd @@ -0,0 +1,7 @@ +--- +title: "search opt out" +--- + +This is a Quarto website. + +To learn more about Quarto websites visit . diff --git a/tests/docs/search/issue-9905/sidebar/.gitignore b/tests/docs/search/issue-9905/sidebar/.gitignore new file mode 100644 index 00000000000..075b2542afb --- /dev/null +++ b/tests/docs/search/issue-9905/sidebar/.gitignore @@ -0,0 +1 @@ +/.quarto/ diff --git a/tests/docs/search/issue-9905/sidebar/_quarto.yml b/tests/docs/search/issue-9905/sidebar/_quarto.yml new file mode 100644 index 00000000000..8ea475f3122 --- /dev/null +++ b/tests/docs/search/issue-9905/sidebar/_quarto.yml @@ -0,0 +1,15 @@ +project: + type: website + +website: + title: "search opt out" + search: + location: sidebar + sidebar: + search: false + contents: + - section: "Basics" + contents: + - index.qmd + +format: html diff --git a/tests/docs/search/issue-9905/sidebar/index.qmd b/tests/docs/search/issue-9905/sidebar/index.qmd new file mode 100644 index 00000000000..c4aabb1e3ab --- /dev/null +++ b/tests/docs/search/issue-9905/sidebar/index.qmd @@ -0,0 +1,7 @@ +--- +title: "search opt out" +--- + +This is a Quarto website. + +To learn more about Quarto websites visit . diff --git a/tests/smoke/extensions/install.test.ts b/tests/smoke/extensions/install.test.ts index 692b60296f2..62e0d88a1b8 100644 --- a/tests/smoke/extensions/install.test.ts +++ b/tests/smoke/extensions/install.test.ts @@ -98,7 +98,7 @@ for (const extUrl of extUrls) { Deno.removeSync("_extensions", { recursive: true }); return Promise.resolve(); }, - santize: { + sanitize: { resources: false, }, }, diff --git a/tests/smoke/site/site.ts b/tests/smoke/site/site.ts index ae812270d15..45f0d9f007c 100644 --- a/tests/smoke/site/site.ts +++ b/tests/smoke/site/site.ts @@ -5,7 +5,7 @@ */ import { existsSync } from "../../../src/deno_ral/fs.ts"; import { dirname } from "../../../src/deno_ral/path.ts"; -import { testQuartoCmd, Verify } from "../../test.ts"; +import { testQuartoCmd, Verify, TestContext, mergeTestContexts } from "../../test.ts"; import { projectOutputForInput } from "../../utils.ts"; import { ensureHtmlElements, noErrorsOrWarnings } from "../../verify.ts"; @@ -14,6 +14,7 @@ export const testSite = ( renderTarget: string, includeSelectors: string[], excludeSelectors: string[], + additionalContext?: TestContext, ...verify: Verify[] ) => { const output = projectOutputForInput(input); @@ -24,18 +25,20 @@ export const testSite = ( excludeSelectors, ); + const baseContext: TestContext = { + teardown: async () => { + const siteDir = dirname(output.outputPath); + if (existsSync(siteDir)) { + await Deno.remove(siteDir, { recursive: true }); + } + }, + }; + // Run the command testQuartoCmd( "render", [renderTarget], [noErrorsOrWarnings, verifySel, ...verify], - { - teardown: async () => { - const siteDir = dirname(output.outputPath); - if (existsSync(siteDir)) { - await Deno.remove(siteDir, { recursive: true }); - } - }, - }, + mergeTestContexts(baseContext, additionalContext), ); }; diff --git a/tests/smoke/website/search.test.ts b/tests/smoke/website/search.test.ts new file mode 100644 index 00000000000..87f861b63d4 --- /dev/null +++ b/tests/smoke/website/search.test.ts @@ -0,0 +1,12 @@ +/* +* drafts.test.ts +* +* Copyright (C) 2020-2022 Posit Software, PBC +* +*/ +import { docs } from "../../utils.ts"; +import { testSite } from "../site/site.ts"; + +await testSite(docs("search/issue-9905/navbar/index.qmd"), docs("search/issue-9905/navbar"), [], ["div#quarto-search"]) +await testSite(docs("search/issue-9905/sidebar/index.qmd"), docs("search/issue-9905/sidebar"), [], ["div.sidebar-search"]); + diff --git a/tests/test.ts b/tests/test.ts index e7eadbbed8f..676eaa62fcd 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -50,7 +50,7 @@ export interface TestContext { cwd?: () => string; // Control of underlying sanitizer - santize?: { resources?: boolean; ops?: boolean; exit?: boolean }; + sanitize?: { resources?: boolean; ops?: boolean; exit?: boolean }; // control if test is ran or skipped ignore?: boolean; @@ -59,6 +59,46 @@ export interface TestContext { env?: Record; } +// Allow to merge test contexts in Tests helpers +export function mergeTestContexts(baseContext: TestContext, additionalContext?: TestContext): TestContext { + if (!additionalContext) { + return baseContext; + } + + return { + // override name if provided + name: additionalContext.name || baseContext.name, + // combine prereq conditions + prereq: async () => { + const baseResult = !baseContext.prereq || await baseContext.prereq(); + const additionalResult = !additionalContext.prereq || await additionalContext.prereq(); + return baseResult && additionalResult; + }, + // run teardowns in reverse order + teardown: async () => { + if (baseContext.teardown) await baseContext.teardown(); + if (additionalContext.teardown) await additionalContext.teardown(); + }, + // run setups in order + setup: async () => { + if (additionalContext.setup) await additionalContext.setup(); + if (baseContext.setup) await baseContext.setup(); + }, + // override cwd if provided + cwd: additionalContext.cwd || baseContext.cwd, + // merge sanitize options + sanitize: { + resources: additionalContext.sanitize?.resources ?? baseContext.sanitize?.resources, + ops: additionalContext.sanitize?.ops ?? baseContext.sanitize?.ops, + exit: additionalContext.sanitize?.exit ?? baseContext.sanitize?.exit, + }, + // override ignore if provided + ignore: additionalContext.ignore ?? baseContext.ignore, + // merge env with additional context taking precedence + env: { ...baseContext.env, ...additionalContext.env }, + }; +} + export function testQuartoCmd( cmd: string, args: string[], @@ -125,9 +165,9 @@ export function test(test: TestDescriptor) { ? `[${test.type}] > ${test.name} (${test.context.name})` : `[${test.type}] > ${test.name}`; - const sanitizeResources = test.context.santize?.resources; - const sanitizeOps = test.context.santize?.ops; - const sanitizeExit = test.context.santize?.exit; + const sanitizeResources = test.context.sanitize?.resources; + const sanitizeOps = test.context.sanitize?.ops; + const sanitizeExit = test.context.sanitize?.exit; const ignore = test.context.ignore; const userSession = !runningInCI(); diff --git a/tests/utils.ts b/tests/utils.ts index 7155f6195ea..5fc579ff0a8 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -189,4 +189,4 @@ export function fileLoader(...path: string[]) { // On Windows, `quarto.cmd` needs to be explicit in `execProcess()` export function quartoDevCmd(): string { return Deno.build.os === "windows" ? "quarto.cmd" : "quarto"; -} +} \ No newline at end of file