Skip to content

Commit

Permalink
Address review issue in copyResearchDocs.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
zner0L committed Feb 2, 2024
1 parent b45fd5d commit c7d85a8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions scripts/copyResearchDocs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { execa } from 'execa';
import { writeFileSync } from 'fs';
import { copyFile, cp, mkdir, readdir, rm, writeFile } from 'fs/promises';
import { join } from 'path';
import { adapters, type Tracker } from 'trackhar';
Expand Down Expand Up @@ -32,7 +31,8 @@ import { adapters, type Tracker } from 'trackhar';
]);

const trackerNames = adapters.reduce<Record<string, Tracker['name']>>((trackers, adapter) => {
if (!trackers[adapter.tracker.slug]) trackers[adapter.tracker.slug] = adapter.tracker.name;
if (!trackers[adapter.tracker.slug])
trackers[adapter.tracker.slug] = adapter.tracker.name || adapter.tracker.slug;
return trackers;
}, {});

Expand All @@ -46,15 +46,17 @@ import { adapters, type Tracker } from 'trackhar';
await rm('content/en/research', { recursive: true, force: true });
console.info('Copying fresh content…');
// Add index.md files if there are none because hugo wants those to create the pages.
(await readdir('trackhar_tmp/research-docs', { withFileTypes: true }))
.filter((dirent) => dirent.isDirectory())
.forEach((dir) => {
writeFileSync(
join('trackhar_tmp/research-docs', dir.name, 'index.md'),
`{\n"title":"${trackerNames[dir.name]}"\n}\n&nbsp;`,
{ flag: 'wx' }
);
});
await Promise.all(
(await readdir('trackhar_tmp/research-docs', { withFileTypes: true }))
.filter((dirent) => dirent.isDirectory())
.map((dir) =>
writeFile(
join('trackhar_tmp/research-docs', dir.name, 'index.md'),
`{\n"title":"${trackerNames[dir.name]}"\n}\n&nbsp;`,
{ flag: 'wx' }
)
)
);
await cp('trackhar_tmp/research-docs', 'content/en/research', { recursive: true });

await rm('trackhar_tmp', { recursive: true, force: true });
Expand Down

0 comments on commit c7d85a8

Please sign in to comment.