Skip to content

Commit b2941c4

Browse files
scan directory upward to find project dir
which should be parent of _extensions
1 parent 5d7d18a commit b2941c4

File tree

9 files changed

+113
-5
lines changed

9 files changed

+113
-5
lines changed

src/extension/extension.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from "../project/types.ts";
1818

1919
import {
20+
basename,
2021
dirname,
2122
isAbsolute,
2223
join,
@@ -158,7 +159,10 @@ export function projectExtensionPathResolver(
158159
return (href: string, projectOffset: string) => {
159160
const projectRelativeHref = relative(projectOffset, href);
160161

161-
if (projectRelativeHref.startsWith("_extensions/") || projectRelativeHref.startsWith("_extensions\\")) {
162+
if (
163+
projectRelativeHref.startsWith("_extensions/") ||
164+
projectRelativeHref.startsWith("_extensions\\")
165+
) {
162166
const projectTargetHref = projectRelativeHref.replace(
163167
/^_extensions/,
164168
`${libDir}/quarto-contrib/quarto-project`,
@@ -809,10 +813,18 @@ async function readExtension(
809813
);
810814
if (resolved.include.length > 0) {
811815
if (key === "brand") {
812-
(object.project as Record<string, unknown>)[key] = relative(
813-
join(extensionDir, "..", ".."),
814-
resolved.include[0],
815-
);
816+
let projectDir = extensionDir, last;
817+
do {
818+
last = basename(projectDir);
819+
projectDir = dirname(projectDir);
820+
} while (projectDir && last !== "_extensions");
821+
if (projectDir) {
822+
(object.project as Record<string, unknown>)[key] = relative(
823+
projectDir,
824+
resolved.include[0],
825+
);
826+
console.log("aslfjasf", projectDir, object.project);
827+
}
816828
} else {
817829
(object.project as Record<string, unknown>)[key] = resolved.include;
818830
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.quarto/
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
title: My-brand
2+
author: Gordon Woodhull
3+
version: 1.0.0
4+
quarto-required: ">=99.9.0"
5+
contributes:
6+
metadata:
7+
project:
8+
brand: mybrand.yml
67.8 KB
Loading
80.7 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
logo:
2+
images:
3+
sun:
4+
path: images/sun-face.png
5+
alt: sun face
6+
moon:
7+
path: images/moon-face.png
8+
alt: moon face
9+
medium:
10+
light: sun
11+
dark: moon
12+
color:
13+
background:
14+
light: "#def"
15+
dark: "#042"
16+
foreground:
17+
light: "#411"
18+
dark: "#ffe"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
project:
2+
type: website
3+
format:
4+
html:
5+
theme:
6+
light: brand
7+
dark: [brand, dark-fixups.scss]
8+
website:
9+
sidebar:
10+
style: "docked"
11+
search: true
12+
contents:
13+
- test.qmd
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*-- scss:rules --*/
2+
3+
nav.sidebar.sidebar-navigation:not(.rollup) {
4+
background-color: #282b30;
5+
}
6+
7+
nav.navbar {
8+
background-color: rgba(13, 251, 108, 0.14);
9+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: test brand extension
3+
format:
4+
html: default
5+
dashboard: default
6+
revealjs: default
7+
typst:
8+
output-ext: typ
9+
_quarto:
10+
tests:
11+
html:
12+
ensureFileRegexMatches:
13+
-
14+
- '<img src="site_libs(/|\\)quarto-contrib(/|\\)quarto-project(/|\\)my-org(/|\\)my-brand(/|\\)images(/|\\)sun-face\.png" alt="sun face" class=".*light-content.*">'
15+
- '<img src="site_libs(/|\\)quarto-contrib(/|\\)quarto-project(/|\\)my-org(/|\\)my-brand(/|\\)images(/|\\)moon-face\.png" alt="moon face" class=".*dark-content.*">'
16+
- []
17+
dashboard:
18+
ensureFileRegexMatches:
19+
-
20+
- '<img src="site_libs(/|\\)quarto-contrib(/|\\)quarto-project(/|\\)my-org(/|\\)my-brand(/|\\)images(/|\\)sun-face\.png" alt="sun face" class=".*light-content.*">'
21+
- '<img src="site_libs(/|\\)quarto-contrib(/|\\)quarto-project(/|\\)my-org(/|\\)my-brand(/|\\)images(/|\\)moon-face\.png" alt="moon face" class=".*dark-content.*">'
22+
- []
23+
revealjs:
24+
ensureFileRegexMatches:
25+
-
26+
- '<img src="site_libs(/|\\)quarto-contrib(/|\\)quarto-project(/|\\)my-org(/|\\)my-brand(/|\\)images(/|\\)sun-face\.png" alt="sun face".*>'
27+
-
28+
- 'moon-face'
29+
typst:
30+
ensureTypstFileRegexMatches:
31+
-
32+
- 'background: align\(left\+top, box\(inset: 0.75in, image\("_extensions(/|\\\\)my-org(/|\\\\)my-brand(/|\\\\)images(/|\\\\)sun-face.png", width: 1\.5in, alt: "sun face"\)\)'
33+
-
34+
- 'image\.*moon-face'
35+
---
36+
37+
# brand.yml extension
38+
39+
Here is some inline code `def foo(x): return x`{.python} and `y`{.python} and `z`{.python}.
40+
41+
42+
{{< lipsum 1 >}}
43+
44+
```{.python}
45+
# | echo: true
46+
print(1+2)
47+
```

0 commit comments

Comments
 (0)