Compare commits
3 Commits
d96b78a7e5
...
c53ca6440c
Author | SHA1 | Date | |
---|---|---|---|
c53ca6440c | |||
84fb327256 | |||
5e518a2ad3 |
@ -37,12 +37,18 @@ interface DirListProps {
|
|||||||
}
|
}
|
||||||
const natsortCompare = natsort();
|
const natsortCompare = natsort();
|
||||||
|
|
||||||
|
function toSorted<T>(arr: T[], compareFn: (a:T,b:T) => number): T[]{
|
||||||
|
const ret = Array.from(arr);
|
||||||
|
ret.sort(compareFn);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
export function DirList(props: DirListProps) {
|
export function DirList(props: DirListProps) {
|
||||||
const data = props;
|
const data = props;
|
||||||
const [files, setFiles] = useState(
|
const [files, setFiles] = useState(
|
||||||
data.files.toSorted(
|
toSorted(data.files,(
|
||||||
(a,b)=> natsortCompare(a.name,b.name)
|
(a,b)=> natsortCompare(a.name,b.name)
|
||||||
)
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -179,7 +179,6 @@ export default function DirLists(props: PageProps<DirOrFileProps>) {
|
|||||||
cover = searchFiles(data.files, (f) => isImageFile(f.name));
|
cover = searchFiles(data.files, (f) => isImageFile(f.name));
|
||||||
index = searchFiles(data.files, (f) => f.name === "index.html");
|
index = searchFiles(data.files, (f) => f.name === "index.html");
|
||||||
const contentFilenameCandidate = [
|
const contentFilenameCandidate = [
|
||||||
"SUMMARY.md",
|
|
||||||
"README.md",
|
"README.md",
|
||||||
"readme.md",
|
"readme.md",
|
||||||
"README.txt",
|
"README.txt",
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Head } from "$fresh/runtime.ts";
|
import { Head, asset } from "$fresh/runtime.ts";
|
||||||
import { HandlerContext, Handlers, PageProps, Status } from "$fresh/server.ts";
|
import { HandlerContext, Handlers, PageProps, Status } from "$fresh/server.ts";
|
||||||
import DocSearch from "../../islands/DocSearch.tsx";
|
import DocSearch from "../../islands/DocSearch.tsx";
|
||||||
import { Doc } from "../../src/collect.ts";
|
import { Doc } from "../../src/collect.ts";
|
||||||
@ -24,6 +24,7 @@ export default function Docs(props: PageProps<{ docs: Doc[] }>) {
|
|||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Simple file server - Doc</title>
|
<title>Simple file server - Doc</title>
|
||||||
|
<link rel="stylesheet" href={asset("/base.css")} />
|
||||||
</Head>
|
</Head>
|
||||||
<div class="p-4 mx-auto max-w-screen-md">
|
<div class="p-4 mx-auto max-w-screen-md">
|
||||||
<DocSearch docs={docs}></DocSearch>
|
<DocSearch docs={docs}></DocSearch>
|
||||||
|
@ -24,6 +24,13 @@ export interface DocCollectorOptions {
|
|||||||
dropContent?: boolean;
|
dropContent?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDESCFile(filename: string): boolean {
|
||||||
|
const filenameUpperCase = filename.toUpperCase();
|
||||||
|
return (filenameUpperCase === "README.MD" ||
|
||||||
|
filenameUpperCase === "DESCRIPTION.MD")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export class DocCollector {
|
export class DocCollector {
|
||||||
private doc_map: Map<string, Doc>;
|
private doc_map: Map<string, Doc>;
|
||||||
private options: DocCollectorOptions;
|
private options: DocCollectorOptions;
|
||||||
@ -59,12 +66,15 @@ export class DocCollector {
|
|||||||
fileList.push(entry);
|
fileList.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileList.some((entry) => entry.name === "SUMMARY.md")) {
|
const entryName = fileList.find(x => {
|
||||||
const { content, metadata } = await readMarkdownDoc(
|
return isDESCFile(x.name) && x.isFile
|
||||||
join(path, "SUMMARY.md"),
|
}
|
||||||
);
|
);
|
||||||
|
if (entryName) {
|
||||||
|
const readmePath = join(path, entryName.name);
|
||||||
|
const { content, metadata } = await readMarkdownDoc(readmePath);
|
||||||
this.setDoc({
|
this.setDoc({
|
||||||
path: join(path, "SUMMARY.md"),
|
path: readmePath,
|
||||||
content: content,
|
content: content,
|
||||||
attributes: metadata,
|
attributes: metadata,
|
||||||
});
|
});
|
||||||
@ -123,9 +133,9 @@ export class DocCollector {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
async watchDir(path: string, {
|
async watchDir(path: string, {
|
||||||
onRemove = (_path: string) => {},
|
onRemove = (_path: string) => { },
|
||||||
onAdd = (_doc: Doc) => {},
|
onAdd = (_doc: Doc) => { },
|
||||||
onChange = (_doc: Doc) => {},
|
onChange = (_doc: Doc) => { },
|
||||||
abort = undefined,
|
abort = undefined,
|
||||||
}: {
|
}: {
|
||||||
onRemove?: (path: string) => void | Promise<void>;
|
onRemove?: (path: string) => void | Promise<void>;
|
||||||
@ -152,7 +162,7 @@ export class DocCollector {
|
|||||||
for (const path of event.paths) {
|
for (const path of event.paths) {
|
||||||
const relpath = relative(Deno.cwd(), path);
|
const relpath = relative(Deno.cwd(), path);
|
||||||
const filename = basename(relpath);
|
const filename = basename(relpath);
|
||||||
if (filename === "SUMMARY.md") {
|
if (isDESCFile(filename)) {
|
||||||
if (event.kind === "remove") {
|
if (event.kind === "remove") {
|
||||||
this.doc_map.delete(relpath);
|
this.doc_map.delete(relpath);
|
||||||
await onRemove(relpath);
|
await onRemove(relpath);
|
||||||
|
Loading…
Reference in New Issue
Block a user