[Draft] Markdown Route Generation Proposal #21
jonathantneal
started this conversation in
Proposal
Replies: 1 comment 2 replies
-
I disagree with putting logic in Markdown by means of having a magic header that contains a JS section that contains logic. I think that the current separation of logic in frontmatter and content in content is clearer. I agree that the magicness of My counterproposal: add sections to frontmatter
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Markdown Route Generation Proposal
Astro should allow authors to express dynamic routes in Markdown files.
Example (
src/pages/post/[id].md
):Background
Astro supports file-based routing to generate URLs from paths in the pages directory, and it also supports dynamic routing to generate multiple URLs from a single file whose path includes named segments.
Currently, a dynamic routing file must export a
getStaticPaths()
function to generate URLs.Example (
src/pages/post/[id].astro
):Problem
Several things break down in the
src/pages/post/[id].astro
example:console.log
insidegetStaticPaths
will log'function', 'undefined', 'undefined'
. Thegql
variable will be available whilepass
andparams
will not.console.log
that is top-level will log'function', 'string', 'object'
. Theghl
,pass
, andparams
variable will all be available.getStaticPaths
, the author returnsparams
, which are not URL params, but are actually named segments from the path.params
clashes with any future server-generated URLs that use actualparams
.getStaticPaths
intends to mirror NextJS but also returnsprops
, which is not intuitive ofgetStaticPaths
and does not mirror NextJS.[id].json.astro
, but Astro will only produce HTML.In summary: Astro provides authors a convenient file-based endpoint to setup dynamic routing logic, but everything required of authors afterward is confusing and limiting.
Goals
Non-Goals
Proposal
Astro should provide authors a way to create dynamic routes that is cohesive with file-based routing, established URL patterns, and Javascript itself.
This is possible when authors express dynamic routing in Markdown files.
### Request
params
andprops
:match
andprops
:src/pages/post/[id].astro
(usingAstro.request.params
).Astro.request.groups
).Pros:
import
statements needed for requests vs responses.src/pages/post/[id].astro
are resolved.Cons:
Prior Art:
Open Questions
pagination()
orrss()
?Alternatives
Astro could allow authors to express dynamic routes in JavaScript files.
Pros:
Cons:
import
statements needed for requests vs responses.Questions:
Beta Was this translation helpful? Give feedback.
All reactions