diff --git a/routes/dir/[...path].tsx b/routes/dir/[...path].tsx index aa55b55..080d2a2 100644 --- a/routes/dir/[...path].tsx +++ b/routes/dir/[...path].tsx @@ -179,7 +179,6 @@ export default function DirLists(props: PageProps) { cover = searchFiles(data.files, (f) => isImageFile(f.name)); index = searchFiles(data.files, (f) => f.name === "index.html"); const contentFilenameCandidate = [ - "SUMMARY.md", "README.md", "readme.md", "README.txt", diff --git a/src/collect.ts b/src/collect.ts index 3bc42be..b60413f 100644 --- a/src/collect.ts +++ b/src/collect.ts @@ -24,6 +24,13 @@ export interface DocCollectorOptions { dropContent?: boolean; } +function isDESCFile(filename: string): boolean { + const filenameUpperCase = filename.toUpperCase(); + return (filenameUpperCase === "README.MD" || + filenameUpperCase === "DESCRIPTION.MD") +} + + export class DocCollector { private doc_map: Map; private options: DocCollectorOptions; @@ -59,12 +66,15 @@ export class DocCollector { fileList.push(entry); } - if (fileList.some((entry) => entry.name === "SUMMARY.md")) { - const { content, metadata } = await readMarkdownDoc( - join(path, "SUMMARY.md"), - ); + const entryName = fileList.find(x => { + return isDESCFile(x.name) && x.isFile + } + ); + if (entryName) { + const readmePath = join(path, entryName.name); + const { content, metadata } = await readMarkdownDoc(readmePath); this.setDoc({ - path: join(path, "SUMMARY.md"), + path: readmePath, content: content, attributes: metadata, }); @@ -123,9 +133,9 @@ export class DocCollector { }; } async watchDir(path: string, { - onRemove = (_path: string) => {}, - onAdd = (_doc: Doc) => {}, - onChange = (_doc: Doc) => {}, + onRemove = (_path: string) => { }, + onAdd = (_doc: Doc) => { }, + onChange = (_doc: Doc) => { }, abort = undefined, }: { onRemove?: (path: string) => void | Promise; @@ -152,7 +162,7 @@ export class DocCollector { for (const path of event.paths) { const relpath = relative(Deno.cwd(), path); const filename = basename(relpath); - if (filename === "SUMMARY.md") { + if (isDESCFile(filename)) { if (event.kind === "remove") { this.doc_map.delete(relpath); await onRemove(relpath); diff --git a/test_data/d/SUMMARY.md b/test_data/d/README.md similarity index 100% rename from test_data/d/SUMMARY.md rename to test_data/d/README.md diff --git a/test_data/e/SUMMARY.md b/test_data/e/README.md similarity index 100% rename from test_data/e/SUMMARY.md rename to test_data/e/README.md diff --git a/test_data/f/SUMMARY.md b/test_data/f/README.md similarity index 100% rename from test_data/f/SUMMARY.md rename to test_data/f/README.md diff --git a/test_data/h#1/SUMMARY.md b/test_data/h#1/README.md similarity index 100% rename from test_data/h#1/SUMMARY.md rename to test_data/h#1/README.md diff --git a/test_data/sample/README.md b/test_data/sample/readme.md similarity index 100% rename from test_data/sample/README.md rename to test_data/sample/readme.md diff --git a/test_data/한글/SUMMARY.md b/test_data/한글/README.md similarity index 100% rename from test_data/한글/SUMMARY.md rename to test_data/한글/README.md