diff --git a/app/lib/pathUtils.ts b/app/lib/pathUtils.ts index 988f33a..dd6781d 100644 --- a/app/lib/pathUtils.ts +++ b/app/lib/pathUtils.ts @@ -1,3 +1,5 @@ +import type { ProjectCollection } from "./projects.server" + export function getDirname(path: string) { return path.split('/').slice(0, -1).join('/') } @@ -15,3 +17,7 @@ export function getExtension(path: string) { const match = path.match(/\.(\w+)$/) return match ? match[1] : null } + +export function folderFromCollection(collection: ProjectCollection) { + return collection.route.replace(/^\//, '').replace(/\/$/, '') +} diff --git a/app/routes/p/$project/$cid/$pid.tsx b/app/routes/p/$project/$cid/$pid.tsx index 5f1b1bf..4c12f76 100644 --- a/app/routes/p/$project/$cid/$pid.tsx +++ b/app/routes/p/$project/$cid/$pid.tsx @@ -32,7 +32,7 @@ export const meta: MetaFunction = ({ data }) => { export const loader: LoaderFunction = async ({ params, request }) => { const { token } = await requireUserSession(request) const collectionId = params.cid - const postFile = params.pid + const filename = params.pid const project = await getProject(Number(params.project)) const config = await getProjectConfig(token, project) const collection = config.collections.find((c) => c.id === collectionId) @@ -42,7 +42,7 @@ export const loader: LoaderFunction = async ({ params, request }) => { } const folder = collection.route.replace(/^\//, '').replace(/\/$/, '') - const isNew = postFile === 'new' + const isNew = filename === 'new' const blankFile = { sha: '', @@ -55,7 +55,7 @@ export const loader: LoaderFunction = async ({ params, request }) => { isNew ? Promise.resolve(blankFile) : getFileContent(token, { repo: project.repo, branch: project.branch, - file: `${folder}/${postFile}` + file: `${folder}/${filename}` }), getRepoDetails(token, project.repo) ])