Replies: 9 comments 9 replies
-
|
I'm not really sure about this feature. I think it's good that Astro provides some opinion here so it's predictable and consistent with other projects. Astro also has specific directory names that you can't change today, e.g. |
Beta Was this translation helpful? Give feedback.
-
|
I would prefer to keep all source files that represent real UI pages in the "pages" directory for consistency across Astro projects. |
Beta Was this translation helpful? Give feedback.
-
|
Of course every team will have their preferences on what these directories should be called, but Astro does value providing strong and consist opinions on topics like this. For some context, when we landed on One thing that might be worth considering: instead of making |
Beta Was this translation helpful? Give feedback.
-
|
For future reference, there was a PR sent but was closed: withastro/astro#9503 |
Beta Was this translation helpful? Give feedback.
-
|
This is a useful feature if you want to dynamically change diff --git a/node_modules/astro/dist/core/build/css-asset-name.js b/node_modules/astro/dist/core/build/css-asset-name.js
index 35cea9d..2f9e8b3 100644
--- a/node_modules/astro/dist/core/build/css-asset-name.js
+++ b/node_modules/astro/dist/core/build/css-asset-name.js
@@ -21,8 +21,8 @@ function createNameHash(baseId, hashIds) {
return proposedName;
}
function createSlugger(settings) {
- const pagesDir = viteID(new URL("./pages", settings.config.srcDir));
- const indexPage = viteID(new URL("./pages/index", settings.config.srcDir));
+ const pagesDir = viteID(new URL(settings.config.pagesDir, settings.config.srcDir));
+ const indexPage = viteID(new URL(settings.config.pagesDir, settings.config.srcDir));
const map = /* @__PURE__ */ new Map();
const sep = "-";
return function(id, ctx) {
diff --git a/node_modules/astro/dist/core/config/schema.js b/node_modules/astro/dist/core/config/schema.js
index e0cd109..ca94bdd 100644
--- a/node_modules/astro/dist/core/config/schema.js
+++ b/node_modules/astro/dist/core/config/schema.js
@@ -9,6 +9,7 @@ const ASTRO_CONFIG_DEFAULTS = {
srcDir: "./src",
publicDir: "./public",
outDir: "./dist",
+ pagesDir: './pages',
cacheDir: "./node_modules/.astro",
base: "/",
trailingSlash: "ignore",
@@ -55,6 +56,7 @@ const AstroConfigSchema = z.object({
srcDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(val)),
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
+ pagesDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.pagesDir).transform((val) => new URL(val)),
cacheDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => new URL(val)),
site: z.string().url().optional(),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
@@ -342,6 +344,7 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
root: z.string().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
+ pagesDir: z.string().default(ASTRO_CONFIG_DEFAULTS.pagesDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
cacheDir: z.string().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
diff --git a/node_modules/astro/dist/core/util.js b/node_modules/astro/dist/core/util.js
index 6d5ac94..a6d03de 100644
--- a/node_modules/astro/dist/core/util.js
+++ b/node_modules/astro/dist/core/util.js
@@ -64,7 +64,7 @@ function unwrapId(id) {
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
}
function resolvePages(config) {
- return new URL("./pages", config.srcDir);
+ return new URL(config.pagesDir, config.srcDir);
}
function isInPagesDir(file, config) {
const pagesDir = resolvePages(config); |
Beta Was this translation helpful? Give feedback.
-
|
I would like to advocate for this feature too. There is a frontend architecture methodology called Feature-Sliced Design (which I'm the maintainer of) and it has a concept of layers (folders) with standardized names. One of these names is Frameworks like Next.js, Remix, SvelteKit, and Nuxt.js also run up against this conflict, but there are ways to reconfigure the page directory to something like I think Astro's guidelines on project structure are very nice to have, but they should be opt-out-able, when you have a more comprehensive architectural solution to put in their place. |
Beta Was this translation helpful? Give feedback.
-
|
I'm in favor of |
Beta Was this translation helpful? Give feedback.
-
|
I think that this is a pretty reasonable thing to request. I don't like having opinions on how I should organize my code forced upon me. For example, I would like to have this structure to my code: but I can't and that's frustrating. Having |
Beta Was this translation helpful? Give feedback.
-
|
I am developing a framework where a Fastify API with an Astro admin panel will have plugins. Those plugins can already add routes to the fastify API by adding a routes directory that behave just as the fastify api does with filesystem discovery. I want my plugins to be able to do the same with a 'pages' folder that gets pages added to the astro admin without needing to modify the core of the framework in order to add pages. There are concerns here to manage but in adding additional filepaths for discovering pages I am accepting responsibility for those concerns and would like to manage them in the way I see fit. I think that the ability to create additional paths for pages to be discovered from is a feature that astro should have. Maybe changing the default path is not an option, but adding more paths definitely so. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Currently Astro Pages are
src/pagesdirectory and there's no way to change it. It would be nice to be able to change it with apagesDirconfig option.Summary
Let's get a
pagesDiroption.Background & Motivation
I'm using Astro as a backend as well in a project, where it makes less sense to have it named
pagesand more sense to call themrouteson backend. I'm basically getting file based routing for creating endpoints without any frontend code. It just works and makes more sense, creates less clutter.Goals
Beta Was this translation helpful? Give feedback.
All reactions