1import * as mediaFiles from "#src/file-viewer/models/media-files.ts";
2import type { MediaFile } from "#src/file-viewer/models/media-files.ts";
3import "./lofi.css";
4export interface Input {
5 file: MediaFile;
6 hasCotyledonCookie: boolean;
7}
8export { meta } from "./clofi.marko";
9export { theme } from "../theme.ts";
10
11<const/{ file: dir, hasCotyledonCookie }=input>
12<const/{ path: fullPath, dirname, basename, kind }=dir>
13<const/isRoot=fullPath == "/">
14
15<div#lofi>
16 <define/ListItem|{ value: file }|>
17 <const/dir=file.kind === "directory">
18 <const/meta=(
19 dir
20 ? string.formatByteSize(file.size)
21 : (file.duration ?? 0) > 0
22 ? formatDuration(file.duration!)
23 : null
24 )>
25 <li class={ dir }>
26 <a href=`/file${escapeUri(file.path)}`>
27 <code>${formatDate(file.date)}</code>${" "}
28 <span>${file.basenameWithoutExt}</span>
29 <if=file.extension><span class="ext">${file.extension}</span></if>
30 <if=dir>/</if>
31 <if=meta><span class="meta">&nbsp;&nbsp;&nbsp;(${meta})</span></if>
32 </a>
33 </li>
34 </define>
35
36 <h1>
37 <if=isRoot>clo's files</if>
38 <else>${fullPath}</else>
39 </h1>
40
41 <if=isRoot>
42 <const/{ readme, sections }=sort.splitRootDirFiles(dir, hasCotyledonCookie)>
43 <if=readme>
44 <ul>
45 <ListItem=readme/>
46 </ul>
47 </if>
48 <for|{ key, files, titleColor }| of=sections>
49 <h2 style={ color: titleColor }>${key}</h2>
50 <ul>
51 <for|item| of=files>
52 <ListItem=item/>
53 </for>
54 </ul>
55 </for>
56 // <if=!hasCotyledonCookie>
57 // <br><br><br><br><br><br>
58 // <p style={ opacity: 0.3 }>
59 // would you like to
60 // <a
61 // href="/file/cotyledon"
62 // style={
63 // color: 'white',
64 // 'text-decoration': 'underline',
65 // }
66 // >dive deeper?</a>
67 // </p>
68 // </>
69 </if>
70 <else>
71 <ul>
72 <li>
73 <a href=`/file${escapeUri(path.posix.dirname(fullPath))}`>
74 [up one...]
75 </a>
76 </li>
77 <for|item| of=mediaFiles.getChildren(dir)>
78 ${" "}
79 <ListItem=item/>
80 ${" "}
81 </for>
82 </ul>
83 </else>
84</div>
85
86import * as path from "node:path";
87import {
88 escapeUri,
89 formatDuration,
90 formatDate,
91} from "#src/file-viewer/format.ts";
92import * as string from "@clo/lib/string";
93import * as sort from "#src/file-viewer/sort.ts";