Skip to content

Commit df96aab

Browse files
authored
Merge pull request #11234 from quarto-dev/feature/11192
Allow `brand:` in document metadata
2 parents 54bbd97 + 1c5104b commit df96aab

File tree

9 files changed

+127
-30
lines changed

9 files changed

+127
-30
lines changed

src/project/project-shared.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { refSchema } from "../core/lib/yaml-schema/common.ts";
5050
import { Brand as BrandJson } from "../resources/types/schema-types.ts";
5151
import { Brand } from "../core/brand/brand.ts";
5252
import { warnOnce } from "../core/log.ts";
53+
import { assert } from "testing/asserts";
5354

5455
export function projectExcludeDirs(context: ProjectContext): string[] {
5556
const outputDir = projectOutputDir(context);
@@ -556,25 +557,28 @@ export async function projectResolveBrand(
556557
if (fileInformation.brand) {
557558
return fileInformation.brand;
558559
}
559-
if (typeof metadata.brand !== "string") {
560-
warnOnce(
561-
`Brand metadata must be a filename, but is of type ${typeof metadata
562-
.brand} in file ${fileName}. Will ignore brand information`,
563-
);
564-
return project.resolveBrand();
565-
}
566-
let brandPath: string = "";
567-
if (brandPath.startsWith("/")) {
568-
brandPath = join(project.dir, metadata.brand);
560+
if (typeof metadata.brand === "string") {
561+
let brandPath: string = "";
562+
if (brandPath.startsWith("/")) {
563+
brandPath = join(project.dir, metadata.brand);
564+
} else {
565+
brandPath = join(dirname(fileName), metadata.brand);
566+
}
567+
const brand = await readAndValidateYamlFromFile(
568+
brandPath,
569+
refSchema("brand", "Format-independent brand configuration."),
570+
"Brand validation failed for " + brandPath + ".",
571+
) as BrandJson;
572+
fileInformation.brand = new Brand(brand, dirname(brandPath), project.dir);
573+
return fileInformation.brand;
569574
} else {
570-
brandPath = join(dirname(fileName), metadata.brand);
575+
assert(typeof metadata.brand === "object");
576+
fileInformation.brand = new Brand(
577+
metadata.brand as BrandJson,
578+
dirname(fileName),
579+
project.dir,
580+
);
581+
return fileInformation.brand;
571582
}
572-
const brand = await readAndValidateYamlFromFile(
573-
brandPath,
574-
refSchema("brand", "Format-independent brand configuration."),
575-
"Brand validation failed for " + brandPath + ".",
576-
) as BrandJson;
577-
fileInformation.brand = new Brand(brand, dirname(brandPath), project.dir);
578-
return fileInformation.brand;
579583
}
580584
}

src/resources/editor/tools/vs-code.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16628,6 +16628,19 @@ var require_yaml_intelligence_resources = __commonJS({
1662816628
schema: "path",
1662916629
description: "Use the specified file as a style reference in producing a docx, \npptx, or odt file.\n"
1663016630
},
16631+
{
16632+
name: "brand",
16633+
schema: {
16634+
anyOf: [
16635+
"string",
16636+
"boolean",
16637+
{
16638+
ref: "brand"
16639+
}
16640+
]
16641+
},
16642+
description: "Branding information to use for this document. If a string, the path to a brand file.\nIf false, don't use branding on this document. If an object, an inline brand\ndefinition.\n"
16643+
},
1663116644
{
1663216645
name: "theme",
1663316646
tags: {
@@ -22618,7 +22631,7 @@ var require_yaml_intelligence_resources = __commonJS({
2261822631
"The page layout to use for this document (<code>article</code>,\n<code>full</code>, or <code>custom</code>)",
2261922632
{
2262022633
short: "Target page width for output (used to compute columns widths for\n<code>layout</code> divs)",
22621-
long: "Target page width for output (used to compute columns widths for\n<code>layout</code> divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt."
22634+
long: "Target body page width for output (used to compute columns widths for\n<code>layout</code> divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt (8.5 inches with 1 inch for\neach margins)."
2262222635
},
2262322636
{
2262422637
short: "Properties of the grid system used to layout Quarto HTML pages.",
@@ -24118,12 +24131,12 @@ var require_yaml_intelligence_resources = __commonJS({
2411824131
mermaid: "%%"
2411924132
},
2412024133
"handlers/mermaid/schema.yml": {
24121-
_internalId: 192600,
24134+
_internalId: 193258,
2412224135
type: "object",
2412324136
description: "be an object",
2412424137
properties: {
2412524138
"mermaid-format": {
24126-
_internalId: 192592,
24139+
_internalId: 193250,
2412724140
type: "enum",
2412824141
enum: [
2412924142
"png",
@@ -24139,7 +24152,7 @@ var require_yaml_intelligence_resources = __commonJS({
2413924152
exhaustiveCompletions: true
2414024153
},
2414124154
theme: {
24142-
_internalId: 192599,
24155+
_internalId: 193257,
2414324156
type: "anyOf",
2414424157
anyOf: [
2414524158
{

src/resources/editor/tools/yaml/web-worker.js

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/resources/editor/tools/yaml/yaml-intelligence-resources.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9600,6 +9600,19 @@
96009600
"schema": "path",
96019601
"description": "Use the specified file as a style reference in producing a docx, \npptx, or odt file.\n"
96029602
},
9603+
{
9604+
"name": "brand",
9605+
"schema": {
9606+
"anyOf": [
9607+
"string",
9608+
"boolean",
9609+
{
9610+
"ref": "brand"
9611+
}
9612+
]
9613+
},
9614+
"description": "Branding information to use for this document. If a string, the path to a brand file.\nIf false, don't use branding on this document. If an object, an inline brand\ndefinition.\n"
9615+
},
96039616
{
96049617
"name": "theme",
96059618
"tags": {
@@ -15590,7 +15603,7 @@
1559015603
"The page layout to use for this document (<code>article</code>,\n<code>full</code>, or <code>custom</code>)",
1559115604
{
1559215605
"short": "Target page width for output (used to compute columns widths for\n<code>layout</code> divs)",
15593-
"long": "Target page width for output (used to compute columns widths for\n<code>layout</code> divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt."
15606+
"long": "Target body page width for output (used to compute columns widths for\n<code>layout</code> divs). Defaults to 6.5 inches, which corresponds to\ndefault letter page settings in docx and odt (8.5 inches with 1 inch for\neach margins)."
1559415607
},
1559515608
{
1559615609
"short": "Properties of the grid system used to layout Quarto HTML pages.",
@@ -17090,12 +17103,12 @@
1709017103
"mermaid": "%%"
1709117104
},
1709217105
"handlers/mermaid/schema.yml": {
17093-
"_internalId": 192600,
17106+
"_internalId": 193258,
1709417107
"type": "object",
1709517108
"description": "be an object",
1709617109
"properties": {
1709717110
"mermaid-format": {
17098-
"_internalId": 192592,
17111+
"_internalId": 193250,
1709917112
"type": "enum",
1710017113
"enum": [
1710117114
"png",
@@ -17111,7 +17124,7 @@
1711117124
"exhaustiveCompletions": true
1711217125
},
1711317126
"theme": {
17114-
"_internalId": 192599,
17127+
"_internalId": 193257,
1711517128
"type": "anyOf",
1711617129
"anyOf": [
1711717130
{

src/resources/schema/document-options.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
Use the specified file as a style reference in producing a docx,
77
pptx, or odt file.
88
9+
- name: brand
10+
schema:
11+
anyOf:
12+
- string # a file path
13+
- boolean # if false, don't use branding on this document
14+
- ref: brand # an inline brand object definition
15+
description: |
16+
Branding information to use for this document. If a string, the path to a brand file.
17+
If false, don't use branding on this document. If an object, an inline brand
18+
definition.
19+
920
- name: theme
1021
tags:
1122
formats: [$html-doc, revealjs, beamer, dashboard]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
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: "feature-11192"
6+
navbar:
7+
left:
8+
- href: index.qmd
9+
text: Home
10+
11+
format:
12+
html:
13+
css: styles.css
14+
toc: true
15+
16+
17+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "feature-11192"
3+
brand:
4+
color:
5+
palette:
6+
white: '#eeddcc'
7+
black: '#112233'
8+
primary: red
9+
background: black
10+
foreground: white
11+
format: html
12+
_quarto:
13+
tests:
14+
html:
15+
ensureFileRegexMatches:
16+
- ['<p>#eeddcc</p>']
17+
- []
18+
---
19+
20+
{{< brand color white >}}
21+
22+
This is a Quarto website.
23+
24+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* css styles */

0 commit comments

Comments
 (0)