Skip to content

Commit aa4ca0d

Browse files
authored
Merge pull request #9595 from mcanouil/fix/issue9524
2 parents c001669 + f44dbd1 commit aa4ca0d

File tree

9 files changed

+84
-4
lines changed

9 files changed

+84
-4
lines changed

news/changelog-1.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ All changes included in 1.5:
6363
- ([#8977](https://github.com/quarto-dev/quarto-cli/issues/8977)): Don't decorate about links within external link icons.
6464
- ([#8986](https://github.com/quarto-dev/quarto-cli/issues/8986)): Search: only build subfuse index when it's safe to do so.
6565
- ([#9356](https://github.com/quarto-dev/quarto-cli/issues/9356)): Don't process column classes for figures inside the About divs.
66+
- ([#9524](https://github.com/quarto-dev/quarto-cli/issues/9524)): Fix canonical URL generation for website pages.
6667
- ([#9781](https://github.com/quarto-dev/quarto-cli/issues/9781)): Correctly hide elements from click event in collapsed margin sidebar.
6768
- Sidebar navigation item now correctly supports `rel` attribute.
6869
- `target` attribute for sidebar navigation items is now correctly inserted with HTML escapes.

src/quarto-core/attribution/document.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,18 @@ export function synthesizeCitationUrl(
447447
offset?: string,
448448
) {
449449
const siteMeta = metadata[kWebsite] as Metadata | undefined;
450-
const baseUrl = siteMeta?.[kSiteUrl] as string;
450+
let baseUrl = siteMeta?.[kSiteUrl] as string;
451451

452452
if (baseUrl && outputFile && offset) {
453+
baseUrl = baseUrl.replace(/\/$/, "");
453454
const rootDir = normalizePath(join(dirname(input), offset));
454455
if (outputFile === "index.html") {
455-
return `${baseUrl}/${
456-
pathWithForwardSlashes(relative(rootDir, dirname(input)))
457-
}`;
456+
const part = pathWithForwardSlashes(relative(rootDir, dirname(input)));
457+
if (part.length === 0) {
458+
return `${baseUrl}/`;
459+
} else {
460+
return `${baseUrl}/${part}/`;
461+
}
458462
} else {
459463
const relativePath = relative(
460464
rootDir,
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+
site-url: https://index.html.com/
6+
title: "Quarto 9524"
7+
navbar:
8+
left:
9+
- href: index.qmd
10+
text: Home
11+
- about/index.qmd
12+
- about/test/something.qmd
13+
- root-page.index.qmd
14+
15+
format:
16+
html:
17+
canonical-url: true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Untitled"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['link[rel="canonical"][href="https://index.html.com/about/file.html"]']
8+
- []
9+
---
10+
11+
A non `index` file at the root of a subdirectory.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "About"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['link[rel="canonical"][href="https://index.html.com/about/"]']
8+
- []
9+
---
10+
11+
About this site
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: "Untitled"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['link[rel="canonical"][href="https://index.html.com/about/test/something.html"]']
8+
- []
9+
---
10+
11+
Another file inside a nested directory.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Quarto 9524"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['link[rel="canonical"][href="https://index.html.com/"]']
8+
- []
9+
---
10+
11+
This is a Quarto website.
12+
13+
To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: root page
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ['link[rel="canonical"][href="https://index.html.com/root-page.index.html"]']
8+
- []
9+
---
10+
11+
Root page with "index." pattern.

0 commit comments

Comments
 (0)