replace "summary.md" to "readme.md"

This commit is contained in:
monoid 2023-02-15 00:02:58 +09:00
parent 5e518a2ad3
commit 84fb327256
8 changed files with 19 additions and 10 deletions

View File

@ -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",

View File

@ -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,
}); });
@ -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);