Yes you can get the list of all pages within a folder in different ways
Solution options
But this is not recommended because it performs a complete import of all the files in an eager fashion
This way you get a list of any file type and the advantage is that you do not perform the actual import as you you get a promise to perform the import on demand, so it is more efficient
- using the file system e.g. in node
await fs.readdir();
but any env should have similar functions such as deno fs.
Examples with references
const posts = import.meta.glob('../../../data/blog/**/*.{md,mdx}')//relative to this component file
const component_path = process.cwd()+'/src/pages/blog/'
const Post_path = Object.keys(posts).find((path)=>(resolve(component_path,path) == page_path))
https://github.com/MicroWebStacks/astro-big-doc/blob/45c2bafc85623ffab3c394609eb119e2693cd2ee/src/pages/blog/%5B...page%5D.astro#L27
async function parse_dir_recursive(dir) {
const subdirs = await fs.readdir(dir);
const files = await Promise.all(subdirs.map(async (subdir) => {
const res = resolve(dir, subdir);
return (await fs.stat(res)).isDirectory() ? parse_dir_recursive(res) : res;
}));
return files.reduce((a, f) => a.concat(f), []);
}
Node.js fs.readdir recursive directory search
https://github.com/MicroWebStacks/astro-big-doc/blob/45c2bafc85623ffab3c394609eb119e2693cd2ee/src/layout/nav_section.js#L11
Note: the linked example https://github.com/MicroWebStacks/astro-big-doc has a use case identical to the question asked, generating a navigation menu from a list of files and even recursively within a directory hierarchy