From e0e371c84909954fa9342046911d876cfdc46ac7 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Sun, 28 Jul 2024 02:55:31 +1000 Subject: [PATCH 1/5] feat(#81): add up navigation to the directory renderer --- src/parser/parser.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/parser/parser.ts b/src/parser/parser.ts index a75ed59c..367dcd2e 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'; @@ -43,6 +43,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 +64,8 @@ export function renderDirectory(path: string): string { .join('\n'); return wrap( 'directory', - renderMarkdown(`${pathHeading(path)}\n\n`), + renderMarkdown( + `${pathHeading(path)}\n\n`, + ), ); } From 1f19f5add7c7e6560340e45e5bb0b34b00b9daef Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Sun, 28 Jul 2024 17:03:46 +1000 Subject: [PATCH 2/5] feat(#81): add up navigation to content renderers --- src/parser/parser.ts | 15 ++++++++++++--- static/style.css | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 367dcd2e..1e192ceb 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -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 (typeof linkPath !== 'undefined') { + link = `\n◂ ${ + pbasename(linkPath) || '/' + }`; + } + 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) => diff --git a/static/style.css b/static/style.css index 1b05c4d1..7b9def9f 100644 --- a/static/style.css +++ b/static/style.css @@ -71,6 +71,11 @@ a#parent-dir { opacity: 0; } a#parent-dir:hover { opacity: 1; } +a#header-up-link { + float: right; + margin-top: 1.1rem; + margin-left: 1.1rem; +} /* -------------------------------------------------------------------------- * TABLES ------------------------------------------------------------------- */ From 420640b77411846da33804da74a61c8fb4ff2288 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Mon, 29 Jul 2024 00:23:15 +1000 Subject: [PATCH 3/5] feat(#81): move navigation to top and inside
    for custom .css --- src/parser/parser.ts | 4 ++-- static/style.css | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 1e192ceb..3160ddbb 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -14,9 +14,9 @@ const pathHeading: Renderer = (path: string) => `# \`${path.replace(homedir(), ' function wrap(contentType: string, content: string, linkPath?: string): string { let link = ''; if (typeof linkPath !== 'undefined') { - link = `\n◂ ${ + link = `\n`; } return `
    ${link}\n${content}
    `; } diff --git a/static/style.css b/static/style.css index 7b9def9f..1b05c4d1 100644 --- a/static/style.css +++ b/static/style.css @@ -71,11 +71,6 @@ a#parent-dir { opacity: 0; } a#parent-dir:hover { opacity: 1; } -a#header-up-link { - float: right; - margin-top: 1.1rem; - margin-left: 1.1rem; -} /* -------------------------------------------------------------------------- * TABLES ------------------------------------------------------------------- */ From dd1e20575c85983fa78b910d527fd8c4c6fca701 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Mon, 29 Jul 2024 00:25:42 +1000 Subject: [PATCH 4/5] feat(#81): remove old up/back button --- src/routes/viewer.ts | 5 ++--- static/style.css | 10 ---------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/routes/viewer.ts b/src/routes/viewer.ts index 05ee4216..d9582401 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..32093baa 100644 --- a/static/style.css +++ b/static/style.css @@ -61,16 +61,6 @@ 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; } /* -------------------------------------------------------------------------- * TABLES ------------------------------------------------------------------- */ From 5a27356b1bcf723fb5def026388906113a8f7780 Mon Sep 17 00:00:00 2001 From: Jason Fairchild Date: Mon, 29 Jul 2024 09:57:34 +1000 Subject: [PATCH 5/5] feat(#81): minor fixes from review feedback --- src/parser/parser.ts | 4 ++-- static/style.css | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 3160ddbb..3fadbee3 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -13,8 +13,8 @@ const pathHeading: Renderer = (path: string) => `# \`${path.replace(homedir(), ' function wrap(contentType: string, content: string, linkPath?: string): string { let link = ''; - if (typeof linkPath !== 'undefined') { - link = `\n
    \n◂ ${ + if (linkPath) { + link = `\n`; } diff --git a/static/style.css b/static/style.css index 32093baa..c36e34bf 100644 --- a/static/style.css +++ b/static/style.css @@ -61,6 +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#top-nav-up:before { content: '◂'} /* -------------------------------------------------------------------------- * TABLES ------------------------------------------------------------------- */