Skip to content

Commit

Permalink
fix relative urls #105
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-rubio committed Jun 18, 2021
1 parent 59f91d0 commit 9d282d2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions site.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,30 +497,30 @@ export default class Site {
}

if (typeof url === "string") {
// Relative URL
if (url.startsWith("./") || url.startsWith("../")) {
url = posix.join(dirname(page.dest.path), url);
} else if (!url.startsWith("/")) {
throw new Exception(
`The url variable must start with "/", "./" or "../"`,
{ page, url },
);
}

if (url.endsWith("/")) {
dest.path = posix.join(url, "index");
dest.path = `${url}index`;
dest.ext = ".html";
} else {
dest.ext = extname(url);
dest.path = dest.ext ? url.slice(0, -dest.ext.length) : url;
}
}
} else if (!dest.ext) {
if (this.options.prettyUrls && posix.basename(dest.path) !== "index") {
dest.path = posix.join(dest.path, "index");
}
dest.ext = ".html";
}

// Relative URL
if (dest.path.startsWith("./") || dest.path.startsWith("../")) {
dest.path = posix.join(dirname(page.src.path), dest.path);
} else if (!dest.path.startsWith("/")) {
throw new Exception(
`The url variable must start with "/", "./" or "../"`,
{ page, url },
);
}

page.data.url =
(dest.ext === ".html" && posix.basename(dest.path) === "index")
? dest.path.slice(0, -5)
Expand Down

0 comments on commit 9d282d2

Please sign in to comment.