-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🗂 Support url slugs with multiple path segments #489
Changes from all commits
3700c61
8714cd4
f52e345
83a9310
8da5b4c
f8cd1ae
c2d115a
2cb7e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@myst-theme/common': patch | ||
'@myst-theme/article': patch | ||
'@myst-theme/site': patch | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Support url slugs with multiple path segments |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,14 +47,15 @@ export const meta: V2_MetaFunction<typeof loader> = ({ data, matches, location } | |
export const links: LinksFunction = () => [KatexCSS]; | ||
|
||
export const loader: LoaderFunction = async ({ params, request }) => { | ||
const [first, second] = new URL(request.url).pathname.slice(1).split('/'); | ||
const projectName = second ? first : undefined; | ||
const slug = second || first; | ||
const [first, ...rest] = new URL(request.url).pathname.slice(1).split('/'); | ||
const config = await getConfig(); | ||
const project = getProject(config, projectName ?? slug); | ||
const project = getProject(config, first); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I learned about some strangeness in the However, for this PR, I tried as best as I could to keep parity with the old functionality. |
||
const projectName = project?.slug === first ? first : undefined; | ||
const slugParts = projectName ? rest : [first, ...rest]; | ||
const slug = slugParts.length ? slugParts.join('.') : undefined; | ||
const flat = isFlatSite(config); | ||
const page = await getPage(request, { | ||
project: flat ? projectName : projectName ?? slug, | ||
project: flat ? projectName : (projectName ?? slug), | ||
slug: flat ? slug : projectName ? slug : undefined, | ||
redirect: process.env.MODE === 'static' ? false : true, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few small changes in here that allow
index
pages to be accessible at the folder-path url.For example, the file
folder1/folder2/index.md
is available at/folder1/folder2
(and/folder1/folder2/index
redirects back to/folder1/folder2
).