Skip to content

Commit

Permalink
Export GLOB_PAGES utility for building glob patterns (#21)
Browse files Browse the repository at this point in the history
* Add GLOB_PAGES constant

- Add constant GLOB_PAGES, a glob string for Astro pages
- Export GLOB_PAGES
- Improve glob check

* Update exports

* Add changeset

* lint
  • Loading branch information
BryceRussell authored Mar 1, 2024
1 parent 1adc442 commit a4e57f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-avocados-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-pages": patch
---

Export `GLOB_PAGES` constant ("\*\*.{astro,ts,js}") for building glob patterns
4 changes: 2 additions & 2 deletions package/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AstroIntegration } from "astro";
import type { IntegrationOption, Option, Prettify } from "./types";
import addPageDir from "./utils/add-page-dir";
import { GLOB_PAGES, addPageDir } from "./utils/add-page-dir";

export default function (
...options: (string | Prettify<Option>)[]
Expand Down Expand Up @@ -40,4 +40,4 @@ export default function (
};
}

export { addPageDir };
export { addPageDir, GLOB_PAGES };
12 changes: 8 additions & 4 deletions package/utils/add-page-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AstroError } from "astro/errors";
import fg from "fast-glob";
import type { IntegrationOption } from "../types";

export const GLOB_PAGES = "**.{astro,ts,js}";

function stringToDir(
option: IntegrationOption,
key: "dir" | "cwd",
Expand Down Expand Up @@ -46,11 +48,11 @@ function stringToDir(
return path;
}

export default function addPageDir(options: IntegrationOption) {
export function addPageDir(options: IntegrationOption) {
let {
dir,
cwd,
glob,
glob = GLOB_PAGES,
pattern: transformer,
log,
config,
Expand All @@ -65,8 +67,8 @@ export default function addPageDir(options: IntegrationOption) {
dir = stringToDir(options, "dir", cwd, dir);

// Handle glob default including empty array case
if (!glob || (Array.isArray(glob) && !glob.length)) {
glob = "**.{astro,ts,js}";
if (Array.isArray(glob) && glob.length <= 0) {
glob = GLOB_PAGES;
}

// Glob filepaths of pages from dir
Expand Down Expand Up @@ -141,3 +143,5 @@ export default function addPageDir(options: IntegrationOption) {
injectPages,
};
}

export default addPageDir;

0 comments on commit a4e57f7

Please sign in to comment.