Skip to content

Commit

Permalink
rename postFile to filename and extract collectionFromFolder function
Browse files Browse the repository at this point in the history
  • Loading branch information
juandjara committed Oct 5, 2023
1 parent 1939207 commit 1065e31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/lib/pathUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { ProjectCollection } from "./projects.server"

export function getDirname(path: string) {
return path.split('/').slice(0, -1).join('/')
}
Expand All @@ -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(/\/$/, '')
}
6 changes: 3 additions & 3 deletions app/routes/p/$project/$cid/$pid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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: '',
Expand All @@ -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)
])
Expand Down

0 comments on commit 1065e31

Please sign in to comment.