Skip to content

Commit 43f69c2

Browse files
committed
fixed super annoying .DS_Store error that I just dealt with for years
1 parent f036f17 commit 43f69c2

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

data/lesson.js

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function getLessons() {
6161
for (let dirFilename of dir) {
6262
const dirStats = await fs.lstat(path.join(lessonsPath, dirFilename));
6363

64-
if (dirStats.isFile()) {
64+
if (!dirStats.isDirectory()) {
6565
continue;
6666
}
6767

@@ -129,6 +129,10 @@ export async function getLesson(targetDir, targetFile) {
129129

130130
for (let i = 0; i < dir.length; i++) {
131131
const dirPath = dir[i];
132+
const dirStats = await fs.lstat(path.join(lessonsPath, dirPath));
133+
if (!dirStats.isDirectory()) {
134+
continue;
135+
}
132136
if (dirPath.endsWith(targetDir)) {
133137
const lessonDir = (
134138
await fs.readdir(path.join(lessonsPath, dirPath))
@@ -157,15 +161,22 @@ export async function getLesson(targetDir, targetFile) {
157161
nextSlug = `${targetDir}/${next.replace(/\.md$/, "")}`;
158162
} else if (dir[i + 1]) {
159163
// has next in next section
160-
const nextDir = (
161-
await fs.readdir(path.join(lessonsPath, dir[i + 1]))
162-
).filter((str) => str.endsWith(".md"));
163-
const nextDirSlug = slugify(dir[i + 1]).slug;
164-
const nextLessonSlug = slugify(nextDir[0]).slug.replace(
165-
/\.md$/,
166-
""
164+
const nextDirStats = await fs.lstat(
165+
path.join(lessonsPath, dir[i + 1])
167166
);
168-
nextSlug = `${nextDirSlug}/${nextLessonSlug}`;
167+
if (!nextDirStats.isDirectory()) {
168+
nextSlug = null;
169+
} else {
170+
const nextDir = (
171+
await fs.readdir(path.join(lessonsPath, dir[i + 1]))
172+
).filter((str) => str.endsWith(".md"));
173+
const nextDirSlug = slugify(dir[i + 1]).slug;
174+
const nextLessonSlug = slugify(nextDir[0]).slug.replace(
175+
/\.md$/,
176+
""
177+
);
178+
nextSlug = `${nextDirSlug}/${nextLessonSlug}`;
179+
}
169180
} else {
170181
// last section
171182
nextSlug = null;
@@ -178,14 +189,21 @@ export async function getLesson(targetDir, targetFile) {
178189
prevSlug = `${targetDir}/${prev.replace(/\.md$/, "")}`;
179190
} else if (dir[i - 1]) {
180191
// has prev in prev section
181-
const prevDir = (
182-
await fs.readdir(path.join(lessonsPath, dir[i - 1]))
183-
).filter((str) => str.endsWith(".md"));
184-
const prevDirSlug = slugify(dir[i - 1]).slug;
185-
const prevLessonSlug = slugify(
186-
prevDir[prevDir.length - 1]
187-
).slug.replace(/\.md$/, "");
188-
prevSlug = `${prevDirSlug}/${prevLessonSlug}`;
192+
const prevDirStats = await fs.lstat(
193+
path.join(lessonsPath, dir[i - 1])
194+
);
195+
if (!prevDirStats.isDirectory()) {
196+
prevSlug = null;
197+
} else {
198+
const prevDir = (
199+
await fs.readdir(path.join(lessonsPath, dir[i - 1]))
200+
).filter((str) => str.endsWith(".md"));
201+
const prevDirSlug = slugify(dir[i - 1]).slug;
202+
const prevLessonSlug = slugify(
203+
prevDir[prevDir.length - 1]
204+
).slug.replace(/\.md$/, "");
205+
prevSlug = `${prevDirSlug}/${prevLessonSlug}`;
206+
}
189207
} else {
190208
// first section
191209
prevSlug = null;

0 commit comments

Comments
 (0)