Skip to content

Commit ceee5e3

Browse files
committed
store processed data in JSON for Lua access
1 parent 7a555bd commit ceee5e3

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

src/core/brand/brand.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,38 @@ export const defaultColorNames: BrandNamedThemeColor[] = [
3838
// "monospace",
3939
// ];
4040

41+
type ProcessedBrandData = {
42+
color: Record<string, string>;
43+
// typography: Record<string, ???>;
44+
// logo: Record<string, string>; // paths
45+
};
46+
4147
export class Brand {
4248
data: BrandJson;
49+
processedData: ProcessedBrandData;
4350

4451
constructor(readonly brand: BrandJson) {
4552
this.data = brand;
53+
this.processedData = this.processData(brand);
54+
}
55+
56+
processData(data: BrandJson): ProcessedBrandData {
57+
const color: Record<string, string> = {};
58+
for (const colorName of Object.keys(data.color?.with ?? {})) {
59+
color[colorName] = this.getColor(colorName);
60+
}
61+
for (const colorName of Object.keys(data.color ?? {})) {
62+
if (colorName === "with") {
63+
continue;
64+
}
65+
color[colorName] = this.getColor(colorName);
66+
}
67+
68+
return {
69+
color,
70+
// typography,
71+
// logo,
72+
};
4673
}
4774

4875
// semantics of name resolution for colors, logo and fonts are:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
color:
2+
with:
3+
red: "#ff0000"
4+
primary: red
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
project:
2+
type: website
3+
4+
website:
5+
title: "test-01"
6+
navbar:
7+
left:
8+
- href: index.qmd
9+
text: Home
10+
- about.qmd
11+
12+
format:
13+
html:
14+
css: styles.css
15+
toc: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "test-01"
3+
format: dashboard
4+
---
5+
6+
This is a Quarto website.
7+
8+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: "test-01"
3+
filters:
4+
- test_brand.lua
5+
---
6+
7+
This is a Quarto website.
8+
9+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local brand = require("modules/brand/brand")
2+
3+
function Pandoc(doc)
4+
assert(brand.get_color("primary") == "#FF0000")
5+
return doc
6+
end

0 commit comments

Comments
 (0)