Skip to content

Commit

Permalink
changed default behavior for pretty urls
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Oct 10, 2023
1 parent 0e0efa1 commit 0a3bf0c
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 10 deletions.
1 change: 1 addition & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Removed `Entry.setContent()`
- Replace `fn-date` with `Temporal` polyfill to convert dates.
- Removed message to upgrade Lume.
- Pretty URLs option doesn't affect to the `/404.html` page by default.

## `search` Plugin

Expand Down
3 changes: 2 additions & 1 deletion core/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ function getDefaultUrl(
return url + page.src.ext;
}

if (prettyUrls) {
// Pretty URLs affects to all pages but 404
if (prettyUrls && url !== "/404") {
if (posix.basename(url) === "index") {
return posix.join(posix.dirname(url), "/");
}
Expand Down
59 changes: 57 additions & 2 deletions tests/__snapshots__/feed.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ snapshot[`RSS plugin 1`] = `
],
src: [
"/",
"/404.md",
"/_data.yml",
"/favicon.png",
"/page5.yaml",
Expand Down Expand Up @@ -122,9 +123,9 @@ snapshot[`RSS plugin 2`] = `[]`;
snapshot[`RSS plugin 3`] = `
[
{
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","description":"","items":[{"id":"https://example.com/pages/new-name/page7/","url":"https://example.com/pages/new-name/page7/","content_html":"Content of Page 7","date_published":"Sun, 02 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page6/","url":"https://example.com/pages/page6/","title":"Page 6","content_html":"<p>Content of Page 6</p>\\\\n","date_published":"Sat, 01 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page4/","url":"https://example.com/pages/page4/","title":"Page 4","content_html":"Content of Page 4 in Overrided site name, from the file /pages/2021-01-02-18-32_page4.page.ts","date_published":"Sat, 02 Jan 2021 18:32:00 GMT"},{"id":"https://example.com/overrided-page2/","url":"https://example.com/overrided-page2/","title":"Page 2","content_html":"Content of Page 2","date_published":"Sun, 21 Jun 2020 00:00:00 GMT"}]}',
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","description":"","items":[{"id":"https://example.com/pages/new-name/page7/","url":"https://example.com/pages/new-name/page7/","content_html":"Content of Page 7","date_published":"Sun, 02 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page6/","url":"https://example.com/pages/page6/","title":"Page 6","content_html":"<p>Content of Page 6</p>\\\\n","date_published":"Sat, 01 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page4/","url":"https://example.com/pages/page4/","title":"Page 4","content_html":"Content of Page 4 in Overrided site name, from the file /pages/2021-01-02-18-32_page4.page.ts","date_published":"Sat, 02 Jan 2021 18:32:00 GMT"},{"id":"https://example.com/overrided-page2/","url":"https://example.com/overrided-page2/","title":"Page 2","content_html":"Content of Page 2","date_published":"Sun, 21 Jun 2020 00:00:00 GMT"},{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"Page 5","content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
data: {
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","description":"","items":[{"id":"https://example.com/pages/new-name/page7/","url":"https://example.com/pages/new-name/page7/","content_html":"Content of Page 7","date_published":"Sun, 02 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page6/","url":"https://example.com/pages/page6/","title":"Page 6","content_html":"<p>Content of Page 6</p>\\\\n","date_published":"Sat, 01 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page4/","url":"https://example.com/pages/page4/","title":"Page 4","content_html":"Content of Page 4 in Overrided site name, from the file /pages/2021-01-02-18-32_page4.page.ts","date_published":"Sat, 02 Jan 2021 18:32:00 GMT"},{"id":"https://example.com/overrided-page2/","url":"https://example.com/overrided-page2/","title":"Page 2","content_html":"Content of Page 2","date_published":"Sun, 21 Jun 2020 00:00:00 GMT"}]}',
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","description":"","items":[{"id":"https://example.com/pages/new-name/page7/","url":"https://example.com/pages/new-name/page7/","content_html":"Content of Page 7","date_published":"Sun, 02 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page6/","url":"https://example.com/pages/page6/","title":"Page 6","content_html":"<p>Content of Page 6</p>\\\\n","date_published":"Sat, 01 Jan 2022 00:00:00 GMT"},{"id":"https://example.com/pages/page4/","url":"https://example.com/pages/page4/","title":"Page 4","content_html":"Content of Page 4 in Overrided site name, from the file /pages/2021-01-02-18-32_page4.page.ts","date_published":"Sat, 02 Jan 2021 18:32:00 GMT"},{"id":"https://example.com/overrided-page2/","url":"https://example.com/overrided-page2/","title":"Page 2","content_html":"Content of Page 2","date_published":"Sun, 21 Jun 2020 00:00:00 GMT"},{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"Page 5","content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
page: [
"src",
"data",
Expand Down Expand Up @@ -185,6 +186,14 @@ snapshot[`RSS plugin 3`] = `
<content:encoded><![CDATA[Content of Page 2]]></content:encoded>
<pubDate>Sun, 21 Jun 2020 00:00:00 GMT</pubDate>
</item>
<item>
<title>Page 5</title>
<link>https://example.com/page5/</link>
<guid isPermaLink="false">https://example.com/page5/</guid>
<description/>
<content:encoded><![CDATA[Content of Page 5]]></content:encoded>
<pubDate>Thu, 21 Jun 1979 23:45:00 GMT</pubDate>
</item>
</channel>
</rss>',
data: {
Expand Down Expand Up @@ -233,6 +242,14 @@ snapshot[`RSS plugin 3`] = `
<content:encoded><![CDATA[Content of Page 2]]></content:encoded>
<pubDate>Sun, 21 Jun 2020 00:00:00 GMT</pubDate>
</item>
<item>
<title>Page 5</title>
<link>https://example.com/page5/</link>
<guid isPermaLink="false">https://example.com/page5/</guid>
<description/>
<content:encoded><![CDATA[Content of Page 5]]></content:encoded>
<pubDate>Thu, 21 Jun 1979 23:45:00 GMT</pubDate>
</item>
</channel>
</rss>',
page: [
Expand All @@ -251,6 +268,44 @@ snapshot[`RSS plugin 3`] = `
},
{
content: "<!DOCTYPE html>
<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
data: {
children: "<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
content: "This page is exported to \`/404.html\`, not \`/404/index.html\`
",
date: [],
imagick: "Array(1)",
mergedKeys: [
"tags",
"metas",
"imagick",
],
metas: [
"title",
"description",
],
page: [
"src",
"data",
],
paginate: "paginate",
search: [],
site: "Default site name",
tags: "Array(0)",
url: "/404.html",
},
src: {
asset: false,
ext: ".md",
path: "/404",
remote: undefined,
slug: "404",
},
},
{
content: "<!DOCTYPE html>
Content of Page 5",
data: {
children: "Content of Page 5",
Expand Down
39 changes: 39 additions & 0 deletions tests/__snapshots__/loaders.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ snapshot[`Load the pages of a site 1`] = `
],
src: [
"/",
"/404.md",
"/_data.yml",
"/favicon.png",
"/page5.yaml",
Expand Down Expand Up @@ -141,6 +142,44 @@ snapshot[`Load the pages of a site 2`] = `

snapshot[`Load the pages of a site 3`] = `
[
{
content: "<!DOCTYPE html>
<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
data: {
children: "<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
content: "This page is exported to \`/404.html\`, not \`/404/index.html\`
",
date: [],
imagick: "Array(1)",
mergedKeys: [
"tags",
"metas",
"imagick",
],
metas: [
"title",
"description",
],
page: [
"src",
"data",
],
paginate: "paginate",
search: [],
site: "Default site name",
tags: "Array(1)",
url: "/404.html",
},
src: {
asset: false,
ext: ".md",
path: "/404",
remote: undefined,
slug: "404",
},
},
{
content: "Uint8Array(1503)",
data: {
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/search.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ snapshot[`Sort by two fields, second is DESC 1`] = `[Function: anonymous]`;

snapshot[`Test the file searcher 1`] = `
[
"/404.html",
"/favicon.png",
"/overrided-page2/index.html",
"/page5/index.html",
Expand Down
47 changes: 47 additions & 0 deletions tests/__snapshots__/sitemap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ snapshot[`Sitemap plugin 1`] = `
],
src: [
"/",
"/404.md",
"/_data.yml",
"/favicon.png",
"/page5.yaml",
Expand Down Expand Up @@ -152,6 +153,10 @@ Sitemap: https://example.com/sitemap.xml",
<loc>https://example.com/overrided-page2/</loc>
<lastmod>2020-06-21T00:00:00.000Z</lastmod>
</url>
<url>
<loc>https://example.com/page5/</loc>
<lastmod>1979-06-21T23:45:00.000Z</lastmod>
</url>
<url>
<loc>https://example.com/pages/new-name/page7/</loc>
<lastmod>2022-01-02T00:00:00.000Z</lastmod>
Expand All @@ -172,6 +177,10 @@ Sitemap: https://example.com/sitemap.xml",
<loc>https://example.com/overrided-page2/</loc>
<lastmod>2020-06-21T00:00:00.000Z</lastmod>
</url>
<url>
<loc>https://example.com/page5/</loc>
<lastmod>1979-06-21T23:45:00.000Z</lastmod>
</url>
<url>
<loc>https://example.com/pages/new-name/page7/</loc>
<lastmod>2022-01-02T00:00:00.000Z</lastmod>
Expand Down Expand Up @@ -201,6 +210,44 @@ Sitemap: https://example.com/sitemap.xml",
},
{
content: "<!DOCTYPE html>
<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
data: {
children: "<p>This page is exported to <code>/404.html</code>, not <code>/404/index.html</code></p>
",
content: "This page is exported to \`/404.html\`, not \`/404/index.html\`
",
date: [],
imagick: "Array(1)",
mergedKeys: [
"tags",
"metas",
"imagick",
],
metas: [
"title",
"description",
],
page: [
"src",
"data",
],
paginate: "paginate",
search: [],
site: "Default site name",
tags: "Array(0)",
url: "/404.html",
},
src: {
asset: false,
ext: ".md",
path: "/404",
remote: undefined,
slug: "404",
},
},
{
content: "<!DOCTYPE html>
Content of Page 5",
data: {
children: "Content of Page 5",
Expand Down
1 change: 1 addition & 0 deletions tests/assets/normal/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This page is exported to `/404.html`, not `/404/index.html`
3 changes: 0 additions & 3 deletions tests/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ Deno.test("RSS plugin", async (t) => {
const site = getSite({
src: "normal",
location: new URL("https://example.com/"),
server: {
page404: "/page5/",
},
});

site.use(
Expand Down
2 changes: 1 addition & 1 deletion tests/loaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Deno.test("ignored draft pages on dev=false", async () => {

await build(site);

assertStrictEquals(site.pages.length, 6);
assertStrictEquals(site.pages.length, 7);
});

Deno.test("textLoader with frontmatter containing just a comment", async () => {
Expand Down
3 changes: 0 additions & 3 deletions tests/sitemap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ Deno.test("Sitemap plugin", async (t) => {
const site = getSite({
src: "normal",
location: new URL("https://example.com/"),
server: {
page404: "/page5/",
},
});

site.use(sitemap());
Expand Down

0 comments on commit 0a3bf0c

Please sign in to comment.