Skip to content

Commit

Permalink
Fix issue with getting tutorials (#483)
Browse files Browse the repository at this point in the history
* fix issue with getting tutorials

* add to entry fn
  • Loading branch information
torztomasz authored Aug 28, 2023
1 parent 650bdba commit c17096b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/backend/src/core/TutorialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import fs from 'fs'

export class TutorialService {
getTutorials(): HomeTutorialEntry[] {
const files = fs.readdirSync('src/content/tutorials')
try {
const files = fs.readdirSync('src/content/tutorials')
return files.map((filename) => this.toTutorialEntry(filename))
} catch {
return []
}
}

return files.map((filename) => {
const filenameWithoutExt = filename.replace('.md', '')
return {
title: filenameWithoutExt.replaceAll('-', ' '),
imageUrl: `/images/${filenameWithoutExt}.jpg`,
slug: filenameWithoutExt.toLowerCase(),
}
})
private toTutorialEntry(filename: string): HomeTutorialEntry {
const filenameWithoutExt = filename.replace('.md', '')
return {
title: filenameWithoutExt.replaceAll('-', ' '),
imageUrl: `/images/${filenameWithoutExt}.jpg`,
slug: filenameWithoutExt.toLowerCase(),
}
}
}

0 comments on commit c17096b

Please sign in to comment.