diff --git a/src/routes/viewer.ts b/src/routes/viewer.ts index 351ae394..b841689f 100644 --- a/src/routes/viewer.ts +++ b/src/routes/viewer.ts @@ -1,11 +1,11 @@ import { lstatSync, readFileSync } from 'fs'; -import { dirname as pdirname, basename as pbasename, join as pjoin } from 'path'; +import { dirname as pdirname, join as pjoin } from 'path'; import { Request, Response, Router } from 'express'; import { messageClientsAt } from '../app'; import config from '../parser/config'; -import { pathToURL, pcomponents, pmime } from '../utils/path'; +import { pathToURL, pcomponents, pmime, getParentName } from '../utils/path'; import { renderDirectory, renderTextFile } from '../parser/parser'; export const router = Router(); @@ -22,14 +22,6 @@ const pageTitle = (path: string) => { } else return pjoin(...comps.slice(-2)); }; -const dirParent = (path: string) => { - let parent = pbasename(pdirname(path)); - if (!parent) { - parent = '/ (root)'; - } - return parent; -}; - router.get(/.*/, async (req: Request, res: Response) => { const path = res.locals.filepath; @@ -75,7 +67,7 @@ router.get(/.*/, async (req: Request, res: Response) => { ${config.styles} - +
${body}
diff --git a/src/utils/path.ts b/src/utils/path.ts index 27cecb0b..eedd84c4 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -29,3 +29,11 @@ export const urlToPath = (url: string) => { export const pathToURL = (path: string, route: string = 'viewer') => `/${route}${encodeURIComponent(path).replaceAll('%2F', '/')}`; + +export const getParentName = (path: string) => { + let parentName = pbasename(pdirname(path)); + if (!parentName) { + parentName = '/ (root)'; + } + return parentName; +};