diff --git a/src/parser/parser.ts b/src/parser/parser.ts index a75ed59c..3fadbee3 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -1,6 +1,6 @@ import { Dirent } from 'fs'; import { homedir } from 'os'; -import { join as pjoin } from 'path'; +import { join as pjoin, dirname as pdirname, basename as pbasename } from 'path'; import { pathToURL } from '../utils/path.js'; import config from './config.js'; import renderNotebook from './ipynb.js'; @@ -10,8 +10,16 @@ import { globSync } from 'glob'; export type Renderer = (content: string) => string; const pathHeading: Renderer = (path: string) => `# \`${path.replace(homedir(), '~')}\``; -const wrap = (contentType: string, content: string) => - `
${content}
`; + +function wrap(contentType: string, content: string, linkPath?: string): string { + let link = ''; + if (linkPath) { + link = `\n
\n ${ + pbasename(linkPath) || '/' + }\n
`; + } + return `
${link}\n${content}
`; +} function textRenderer( fileEnding: string | undefined, @@ -32,10 +40,11 @@ export function renderTextFile(content: string, path: string): string { return wrap( 'txt', renderMarkdown(`${pathHeading(path!)}\n\n\`\`\`${fileEnding}\n${content}\n\`\`\``), + pdirname(path), ); } const { render, contentType } = renderInformation; - return wrap(contentType, render(content)); + return wrap(contentType, render(content), pdirname(path)); } const dirListItem = (item: Dirent, path: string) => @@ -43,6 +52,13 @@ const dirListItem = (item: Dirent, path: string) => pjoin(path, item.name), )}">${item.name}`; +function dirUpItem(path: string): string { + if (pbasename(path) == '') { + return ''; // Show nothing when already at root directory + } + return `
  • .. (${pbasename(pdirname(path)) || '/'})
  • `; +} + export function renderDirectory(path: string): string { const list = globSync('*', { cwd: path, @@ -57,6 +73,8 @@ export function renderDirectory(path: string): string { .join('\n'); return wrap( 'directory', - renderMarkdown(`${pathHeading(path)}\n\n`), + renderMarkdown( + `${pathHeading(path)}\n\n`, + ), ); } diff --git a/src/routes/viewer.ts b/src/routes/viewer.ts index 89a38f2f..efbab9f0 100644 --- a/src/routes/viewer.ts +++ b/src/routes/viewer.ts @@ -1,12 +1,12 @@ import { lstatSync, readFileSync } from 'fs'; -import { dirname as pdirname, join as pjoin } from 'path'; +import { join as pjoin } from 'path'; import { homedir } from 'os'; import { Request, Response, Router } from 'express'; import { messageClientsAt } from '../app.js'; import config from '../parser/config.js'; -import { absPath, pathToURL, pcomponents, pmime, preferredPath } from '../utils/path.js'; +import { absPath, pcomponents, pmime, preferredPath } from '../utils/path.js'; import { renderDirectory, renderTextFile } from '../parser/parser.js'; export const router = Router(); @@ -76,7 +76,6 @@ router.get(/.*/, async (req: Request, res: Response) => { ${config.styles ? `` : ''} -
    ${body}
    diff --git a/static/style.css b/static/style.css index 1b05c4d1..c36e34bf 100644 --- a/static/style.css +++ b/static/style.css @@ -61,16 +61,7 @@ h3:hover a.header-anchor, h4:hover a.header-anchor, h5:hover a.header-anchor, h6:hover a.header-anchor { opacity: 1; } -a#parent-dir { - position: fixed; - height: 3rem; width: 3rem; - line-height: 3rem; text-align: center; - background-color: #333; - border-radius: 9999px; - left: 2rem; top: 2rem; - opacity: 0; -} -a#parent-dir:hover { opacity: 1; } +a#top-nav-up:before { content: '◂'} /* -------------------------------------------------------------------------- * TABLES ------------------------------------------------------------------- */