Skip to content

Commit

Permalink
Merge pull request #48 from techfg/fix/rename-basepath-option
Browse files Browse the repository at this point in the history
fix: `basePath` option name should align with Astro `base` option name (#46)
  • Loading branch information
vernak2539 authored May 16, 2024
2 parents 84f97c6 + 4cccc40 commit 00ac6e6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function astroRehypeRelativeMarkdownLinks(opts = {}) {

// Debugging
debug("--------------------------------------");
debug("BasePath : %s", options.basePath);
debug("Base path : %s", options.base);
debug("ContentDir : %s", contentDir);
debug("CollectionPathMode : %s", collectionPathMode);
debug("TrailingSlashMode : %s", trailingSlashMode);
Expand Down
4 changes: 2 additions & 2 deletions src/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ describe("astroRehypeRelativeMarkdownLinks", () => {
await runValidationTest(context, { contentPath: "src" }));
});

describe("config option - basePath", () => {
describe("config option - base", () => {
test("should prefix base to output on file paths that exist", async () => {
const input = '<a href="./fixtures/test.md">foo</a>';
const { value: actual } = await rehype()
.use(testSetupRehype)
.use(astroRehypeRelativeMarkdownLinks, {
contentPath: "src",
basePath: "/testBase",
base: "/testBase",
})
.process(input);

Expand Down
8 changes: 4 additions & 4 deletions src/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ export const OptionsSchema = z.object({
.union([z.literal("subdirectory"), z.literal("root")])
.default("subdirectory"),
/**
* @name basePath
* @name base
* @reference https://docs.astro.build/en/reference/configuration-reference/#base
* @description
* The base path to deploy to. Astro will use this path as the root for your pages and assets both in development and in production build.
*
* @example
* In the example below, `astro dev` will start your server at `/docs`.
*
*
* ```js
* {
* base: '/docs'
* }
* ```
*/
basePath: z.string().optional(),
base: z.string().optional(),
/**
* @name trailingSlash
* @default `ignore`
Expand Down
14 changes: 7 additions & 7 deletions src/options.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ describe("validateOptions", () => {
});
});

describe("basePath", () => {
test("should have expected basePath default", () => {
expectsValidOption({}, "basePath", defaultOptions.basePath);
describe("base", () => {
test("should have expected base default", () => {
expectsValidOption({}, "base", defaultOptions.base);
});

test("should be basePath value specified when provided", () => {
expectsValidOption({ basePath: "foobar" }, "basePath", "foobar");
test("should be base value specified when provided", () => {
expectsValidOption({ base: "foobar" }, "base", "foobar");
});

test("should fail when baesPath not a string", () => {
expectsZodError({ basePath: {} }, "invalid_type");
test("should fail when base not a string", () => {
expectsZodError({ base: {} }, "invalid_type");
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ export const splitPathFromQueryAndFragment = (url) => {
/** @type {import('./utils.d.ts').NormaliseAstroOutputPath} */
export const normaliseAstroOutputPath = (initialPath, options = {}) => {
const buildPath = () => {
if (!options.basePath) {
if (!options.base) {
return initialPath;
}

if (options.basePath.startsWith(URL_PATH_SEPARATOR)) {
return path.join(options.basePath, initialPath);
if (options.base.startsWith(URL_PATH_SEPARATOR)) {
return path.join(options.base, initialPath);
}

return URL_PATH_SEPARATOR + path.join(options.basePath, initialPath);
return URL_PATH_SEPARATOR + path.join(options.base, initialPath);
};

if (!initialPath) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,31 +206,31 @@ describe("normaliseAstroOutputPath", () => {
describe("prefix base to path", () => {
test("base with no slashes", () => {
const actual = normaliseAstroOutputPath("/foo-testing-test", {
basePath: "base",
base: "base",
});

assert.equal(actual, "/base/foo-testing-test");
});

test("base with slash at start", () => {
const actual = normaliseAstroOutputPath("/foo-testing-test", {
basePath: "/base",
base: "/base",
});

assert.equal(actual, "/base/foo-testing-test");
});

test("base with slash at end", () => {
const actual = normaliseAstroOutputPath("/foo-testing-test", {
basePath: "base/",
base: "base/",
});

assert.equal(actual, "/base/foo-testing-test");
});

test("base with slash at start and end", () => {
const actual = normaliseAstroOutputPath("/foo-testing-test", {
basePath: "/base/",
base: "/base/",
});

assert.equal(actual, "/base/foo-testing-test");
Expand Down

0 comments on commit 00ac6e6

Please sign in to comment.