Skip to content

Commit 3ec9918

Browse files
authored
Merge pull request #11869 from quarto-dev/fix/post-categories-encoded
2 parents aaef33c + a1df803 commit 3ec9918

File tree

9 files changed

+59
-14
lines changed

9 files changed

+59
-14
lines changed

news/changelog-1.7.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ All changes included in 1.7:
1717

1818
- ([#11701](https://github.com/quarto-dev/quarto-cli/issues/11701)): Wrap HTML emitted by EJS templates in `{=html}` blocks to avoid memory blowup issues with Pandoc's parser.
1919

20+
## Blog projects
21+
22+
- ([#11745](https://github.com/quarto-dev/quarto-cli/issues/11745)): Fix categories links under post title in post with url encoded path (e.g. with space or other special characters).
23+
2024
## Book projects
2125

2226
- ([#11520](https://github.com/quarto-dev/quarto-cli/issues/11520)): Book's cover image now escapes lightbox treatment, which was incorrectly applied to it when `lightbox: true` was set in the book's configuration.

src/resources/formats/html/quarto.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ window.document.addEventListener("DOMContentLoaded", function (_event) {
238238
for (const listingPath of listingPaths) {
239239
const pathWithoutLeadingSlash = listingPath.listing.substring(1);
240240
for (const item of listingPath.items) {
241+
const encodedItem = encodeURI(item);
241242
if (
242-
item === currentPagePath ||
243-
item === currentPagePath + "index.html"
243+
encodedItem === currentPagePath ||
244+
encodedItem === currentPagePath + "index.html"
244245
) {
245246
// Resolve this path against the offset to be sure
246247
// we already are using the correct path to the listing
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "testing post with space"
3+
author: "Harlow Malloc"
4+
date: "2024-12-28"
5+
categories: [news, code, analysis]
6+
image: "image.jpg"
7+
---
8+
9+
This is a post folder name with space
10+
11+
```{r}
12+
1 + 1
13+
```
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "testing post with space"
3+
author: "Harlow Malloc"
4+
date: "2024-12-28"
5+
categories: [news, code, analysis]
6+
image: "image.jpg"
7+
---
8+
9+
This is a post folder name with space
10+
11+
```{r}
12+
1 + 1
13+
```
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "testing post with space"
3+
author: "Harlow Malloc"
4+
date: "2024-12-28"
5+
categories: [news, code, analysis]
6+
image: "image.jpg"
7+
---
8+
9+
This is a post folder name with space
10+
11+
```{r}
12+
1 + 1
13+
```

tests/integration/playwright/tests/blog-simple-blog.spec.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,41 @@ Object.entries(testPages).forEach(([postDir, pageName]) => {
2828
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeHidden();
2929
});
3030

31-
const checkCategoryLink = async (page: Page, category: string, pageName: string) => {
31+
const checkCategoryLink = async (page: Page, category: string, pageName: string, postTitle: string) => {
3232
await page.getByText(category, { exact: true }).click();
3333
await expect(page).toHaveURL(getUrl(`blog/simple-blog/_site/${pageName}#category=${encodeURIComponent(category)}`));
3434
await expect(page.locator(`div.category[data-category="${btoa(encodeURIComponent(category))}"]`)).toHaveClass(/active/);
35+
await expect(page.getByRole('link', { name: postTitle })).toBeVisible();
3536
};
3637

3738
test(`All Categories links are clickable ${postDir} pages`,
3839
async ({ page }) => {
3940
// Checking link is working
4041
await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/`);
41-
await checkCategoryLink(page, 'news', pageName);
42+
await checkCategoryLink(page, 'news', pageName, 'Welcome To My Blog');
4243
// Including for special characters
4344
await page.getByRole('link', { name: 'Welcome To My Blog' }).click();
44-
await checkCategoryLink(page, 'euros (€)', pageName);
45+
await checkCategoryLink(page, 'euros (€)', pageName, 'Welcome To My Blog');
4546
await page.getByRole('link', { name: 'Welcome To My Blog' }).click();
46-
await checkCategoryLink(page, '免疫', pageName);
47+
await checkCategoryLink(page, '免疫', pageName, 'Welcome To My Blog');
4748
await page.goto(`./blog/simple-blog/_site/${postDir}/post-with-code/`);
48-
await checkCategoryLink(page, "apos'trophe", pageName);
49+
await checkCategoryLink(page, "apos'trophe", pageName, 'Post With Code');
4950
// special check for when a page is not loaded from non root path
5051
await page.goto(`./blog/simple-blog/_site/${postDir}/welcome/#img-lst`);
51-
await checkCategoryLink(page, 'news', pageName);
52+
await checkCategoryLink(page, 'news', pageName, 'Welcome To My Blog');
53+
// special check for post with space in page name
54+
await page.goto(`./blog/simple-blog/_site/${postDir}/post with space/`);
55+
await checkCategoryLink(page, 'news', pageName, 'testing post with space');
5256
});
5357

5458
if (pageName !== 'table.html') {
5559
test(`Categories link on listing page works for ${pageName}`, async ({ page }) => {
5660
await page.goto(`./blog/simple-blog/_site/${pageName}`);
57-
await checkCategoryLink(page, 'apos\'trophe', pageName);
58-
await expect(page.getByRole('link', { name: 'Post With Code' })).toBeVisible();
61+
await checkCategoryLink(page, 'apos\'trophe', pageName, 'Post With Code');
5962
await page.goto(`./blog/simple-blog/_site/${pageName}`);
60-
await checkCategoryLink(page, 'euros (€)', pageName);
61-
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible();
63+
await checkCategoryLink(page, 'euros (€)', pageName, 'Welcome To My Blog');
6264
await page.goto(`./blog/simple-blog/_site/${pageName}`);
63-
await checkCategoryLink(page, '免疫', pageName);
64-
await expect(page.getByRole('link', { name: 'Welcome To My Blog' })).toBeVisible();
65+
await checkCategoryLink(page, '免疫', pageName, 'Welcome To My Blog');
6566
});
6667
}
6768
});

0 commit comments

Comments
 (0)