Skip to content

Commit

Permalink
feat(81): Add up navigation to the directory renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweekism committed Jul 28, 2024
1 parent 140ad19 commit d24df1b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -43,6 +43,13 @@ const dirListItem = (item: Dirent, path: string) =>
pjoin(path, item.name),
)}">${item.name}</a></li>`;

function dirUpItem (path: string): string {
if (pbasename(path) == "") {
return ""; // Show nothing when already at root directory
}
return `<li class="dir-list-directory"><a href="${pathToURL(pdirname(path))}">.. (${pbasename(pdirname(path)) || "/"})</a></li>`;
}

export function renderDirectory(path: string): string {
const list = globSync('*', {
cwd: path,
Expand All @@ -57,6 +64,6 @@ export function renderDirectory(path: string): string {
.join('\n');
return wrap(
'directory',
renderMarkdown(`${pathHeading(path)}\n\n<ul class="dir-list">\n${list}\n</ul>`),
renderMarkdown(`${pathHeading(path)}\n\n<ul class="dir-list">\n${dirUpItem(path)}\n${list}\n</ul>`),
);
}

0 comments on commit d24df1b

Please sign in to comment.