Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kantord committed Jul 22, 2024
1 parent d5f536d commit 33cb07e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
38 changes: 2 additions & 36 deletions apps/librelingo-web/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
import type { Metadata } from 'next'
import CourseCard from './CourseCard';
import courseConfig from "@/courses/config.json"
import path from 'path';
import fs from 'fs';
import { Course, listAllCourses } from '@/data/course';


export type Language = {
code: string
name: string
}

export type Course = {
source: Language
target: Language
repositoryURL: string
url: string
inProduction: boolean
}

export const metadata: Metadata = {
title: 'LibreLingo',
description: 'LibreLingo is an open source language-learning platform',
}

export default async function Home() {

const courseData: Course[] = await Promise.all(courseConfig.filter(item => item.deploy).map(async (item) => {
const jsonFilePath = path.join(process.cwd(), 'src', 'courses', item.paths.jsonFolder, 'courseData.json');
const fileContent = await fs.promises.readFile(jsonFilePath, 'utf-8');
const courseMetadata = JSON.parse(fileContent);

return {
repositoryURL: item.repositoryURL,
url: item.url,
inProduction: item.inProduction,
source: {
code: courseMetadata.uiLanguage,
name: item.source,
},
target: {
code: courseMetadata.languageCode,
name: courseMetadata.languageName,
},
};
}));

const courseData = await listAllCourses()

return (
<>
Expand Down
51 changes: 51 additions & 0 deletions apps/librelingo-web/src/data/course.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import path from 'path';
import courseConfig from "@/courses/config.json"
import fs from 'fs'

export type Language = {
code: string
name: string
}

export type Course = {
jsonPath: string
source: Language
target: Language
repositoryURL: string
url: string
inProduction: boolean
}

async function getCourseMetadataByJsonPath(jsonPath: string)
{
const jsonFilePath = path.join(process.cwd(), 'src', 'courses', jsonPath, 'courseData.json');
const fileContent = await fs.promises.readFile(jsonFilePath, 'utf-8');
return JSON.parse(fileContent);
}


export async function listAllCourses(): Promise<Course[]> {
return Promise.all(courseConfig.filter(item => item.deploy).map(async (item) => {
const jsonPath = item.paths.jsonFolder
const courseMetadata = await getCourseMetadataByJsonPath(jsonPath)

return {
jsonPath,
repositoryURL: item.repositoryURL,
url: item.url,
inProduction: item.inProduction,
source: {
code: courseMetadata.uiLanguage,
name: item.source,
},
target: {
code: courseMetadata.languageCode,
name: courseMetadata.languageName,
},
};
}));
}

//export async function getCourseDetailsByJsonPath(jsonPath: string): Promise<CourseDetails> {
//
//}

0 comments on commit 33cb07e

Please sign in to comment.