Skip to content

Commit ea11de5

Browse files
brand extension
fixes #12559 this extension builds on the metadata extension, providing a sample brand.yml to do this, we need to look at the project's project.brand and not just brand
1 parent 2724ff4 commit ea11de5

File tree

10 files changed

+97
-7
lines changed

10 files changed

+97
-7
lines changed

news/changelog-1.8.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ All changes included in 1.8:
9595

9696
- ([#12965](https://github.com/quarto-dev/quarto-cli/issues/12965)): Prevent automatic opening of new editor sessions when creating projects in Posit Workbench context. The `--open` flag is now ignored in this environment to avoid issues with Workbench session management.
9797

98+
## Extensions
99+
100+
- ([#12559](https://github.com/quarto-dev/quarto-cli/issues/12559)): New extension type: `brand` for distributing [brand.yml](https://posit-dev.github.io/brand-yml/) configurations with associated assets.
101+
98102
## Engines
99103

100104
- ([#13171](https://github.com/quarto-dev/quarto-cli/pull/13171/)): Provide execution information to all engines uniformly via QUARTO_EXECUTE_INFO environment variable. It points to a file on disk containing a JSON object describing the execution environment for code cells to use.

src/command/create/artifacts/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const kExtensionTypes: Array<string | ExtensionType> = [
4141
{ name: "journal format", value: "journal", openfiles: ["template.qmd"] },
4242
{ name: "custom format", value: "format", openfiles: ["template.qmd"] },
4343
{ name: "metadata", value: "metadata", openfiles: [] },
44+
{ name: "brand", value: "brand", openfiles: [] },
4445
];
4546

4647
const kExtensionSubtypes: Record<string, string[]> = {

src/extension/extension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ async function readExtension(
791791
const metadata = contributes?.metadata as Record<string, unknown> | undefined;
792792

793793
// resolve metadata/project pre- and post-render scripts to their full path
794-
for (const key of ["pre-render", "post-render"]) {
794+
for (const key of ["pre-render", "post-render", "brand"]) {
795795
for (const object of [metadata, project]) {
796796
if (!object?.project || typeof object.project !== "object") {
797797
continue;
@@ -808,8 +808,14 @@ async function readExtension(
808808
[],
809809
);
810810
if (resolved.include.length > 0) {
811-
(object.project as Record<string, unknown>)[key] = resolved
812-
.include;
811+
if (key === "brand") {
812+
(object.project as Record<string, unknown>)[key] = relative(
813+
join(extensionDir, "..", ".."),
814+
resolved.include[0],
815+
);
816+
} else {
817+
(object.project as Record<string, unknown>)[key] = resolved.include;
818+
}
813819
}
814820
}
815821
}

src/project/project-shared.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,14 @@ export async function projectResolveBrand(
560560
let fileNames = ["_brand.yml", "_brand.yaml"].map((file) =>
561561
join(project.dir, file)
562562
);
563-
const brand = project?.config?.brand as boolean | string | {
564-
light?: string;
565-
dark?: string;
566-
};
563+
const brand = (project?.config?.brand ??
564+
project?.config?.project.brand) as
565+
| boolean
566+
| string
567+
| {
568+
light?: string;
569+
dark?: string;
570+
};
567571
if (brand === false) {
568572
project.brandCache.brand = undefined;
569573
return project.brandCache.brand;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.html
2+
*.pdf
3+
*_files/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# <%= title %> Extension For Quarto
2+
3+
_TODO_: Add a short description of your extension.
4+
5+
## Installing
6+
7+
_TODO_: Replace the `<github-organization>` with your GitHub organization.
8+
9+
```bash
10+
quarto add <github-organization>/<%= filesafename %>
11+
```
12+
13+
This will install the extension under the `_extensions` subdirectory.
14+
If you're using version control, you will want to check in this directory.
15+
16+
## Using
17+
18+
This extension installs a [brand.yml](https://posit-dev.github.io/brand-yml/) configuration for _your organization name_.
19+
20+
## Example
21+
22+
Here is the source code for a minimal example: [example.qmd](example.qmd).
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: <%= title %>
2+
author: <%= author %>
3+
version: <%= version %>
4+
quarto-required: ">=<%= quartoversion %>"
5+
contributes:
6+
metadata:
7+
project:
8+
brand: brand.yml
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# minimal brand.yml enabling dark mode
2+
# replace with your brand colors, logos, and typography!
3+
color:
4+
background:
5+
light: "#fff"
6+
dark: "#000"
7+
foreground:
8+
light: "#000"
9+
dark: "#fff"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: your brand extension
3+
---
4+
5+
# brand.yml extension
6+
7+
Here is some inline code: `def foo(x): return x`{.python} and `y`{.python} and `z`{.python}.
8+
9+
Here is [a link](https://example.com).
10+
11+
Here is a code block:
12+
13+
```{.r}
14+
# | echo: true
15+
fibonacci <- function(n) {
16+
if (n <= 0) {
17+
return(NULL)
18+
} else if (n == 1) {
19+
return(0)
20+
} else if (n == 2) {
21+
return(1)
22+
} else {
23+
return(fibonacci(n - 1) + fibonacci(n - 2))
24+
}
25+
}
26+
```

src/resources/schema/project.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
maybeArrayOf:
3333
schema: path
3434
description: "Additional file resources to be copied to output directory"
35+
brand:
36+
schema:
37+
ref: brand-path-bool-light-dark
38+
description: |
39+
Branding information to use for this document. If a string, the path to a brand file.
40+
If false, don't use branding on this document. If an object, an inline brand
41+
definition, or an object with light and dark brand paths or definitions.
3542
preview:
3643
description: Options for `quarto preview`
3744
schema:

0 commit comments

Comments
 (0)