Merge pull request 'Feat/wiki' (#40) from feat/wiki into main
Deploy Next.js via Docker / deploy (push) Successful in 1m2s
Deploy Next.js via Docker / deploy (push) Successful in 1m2s
Reviewed-on: Schanbro/PsalmTafel#40
This commit was merged in pull request #40.
This commit is contained in:
commit
5afdae2b20
3 files changed
+74
-14
No files matched your search
@@ -0,0 +1,17 @@
|
|||||||
|
import Article from "@/components/wiki/Article";
|
||||||
|
import { getAllWikiPages } from "@/lib/wiki";
|
||||||
|
|
||||||
|
export default async function WikiIndexPage() {
|
||||||
|
const allPages = await getAllWikiPages();
|
||||||
|
return (
|
||||||
|
<Article title="Wiki">
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{allPages.map(({ title, path }) => (
|
||||||
|
<a key={path} href={`/wiki/${path}`} className="hover:underline">
|
||||||
|
{title}
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Article>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Projekt Starten
|
title: Test Page
|
||||||
updatedAt: "2026-08-04"
|
updatedAt: "2026-08-04"
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+56
-13
@@ -11,6 +11,11 @@ export type WikiArticle = {
|
|||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type WikiPage = {
|
||||||
|
title: string;
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
||||||
const wikiDirectory = path.join(process.cwd(), "data/wiki/pages");
|
const wikiDirectory = path.join(process.cwd(), "data/wiki/pages");
|
||||||
|
|
||||||
export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | null> {
|
export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | null> {
|
||||||
@@ -32,23 +37,34 @@ export async function getWikiPageBySlug(slug: string): Promise<WikiArticle | nul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllTsFiles(dirPath: string): string[] {
|
/**
|
||||||
|
* Liest rekursiv alle Dateien aus einem Verzeichnis aus.
|
||||||
|
* @param dirPath - Der Startordner
|
||||||
|
* @param extension - Optionale Dateiendung zur Filterung (z. B. ".ts" oder "ts")
|
||||||
|
* @returns Array mit den Dateipfaden
|
||||||
|
*/
|
||||||
|
export function getAllFiles(dirPath: string, extension?: string): string[] {
|
||||||
|
if (!fs.existsSync(dirPath)) return [];
|
||||||
|
|
||||||
let results: string[] = [];
|
let results: string[] = [];
|
||||||
|
|
||||||
if (!fs.existsSync(dirPath)) return results;
|
|
||||||
|
|
||||||
const list = fs.readdirSync(dirPath);
|
// optionales führendes Dot sicherstellen (z. B. aus "ts" wird ".ts")
|
||||||
|
const targetExt = extension && !extension.startsWith('.')
|
||||||
|
? `.${extension}`
|
||||||
|
: extension;
|
||||||
|
|
||||||
list.forEach((file) => {
|
// withFileTypes: true spart zusätzliche fs.statSync Aufrufe
|
||||||
const filePath = path.join(dirPath, file);
|
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
||||||
const stat = fs.statSync(filePath);
|
|
||||||
|
|
||||||
if (stat && stat.isDirectory()) {
|
for (const entry of entries) {
|
||||||
results = results.concat(getAllTsFiles(filePath));
|
const fullPath = path.join(dirPath, entry.name);
|
||||||
} else if (filePath.endsWith('.ts') && !filePath.endsWith('.d.ts')) {
|
|
||||||
results.push(filePath);
|
if (entry.isDirectory()) {
|
||||||
|
results = results.concat(getAllFiles(fullPath, targetExt));
|
||||||
|
} else if (!targetExt || entry.name.endsWith(targetExt)) {
|
||||||
|
results.push(fullPath);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@@ -149,7 +165,7 @@ export function filterMethods(
|
|||||||
export async function getAllApis(): Promise<ApiRoute[]> {
|
export async function getAllApis(): Promise<ApiRoute[]> {
|
||||||
try {
|
try {
|
||||||
const apiBasePath = path.join(process.cwd(), "app/api");
|
const apiBasePath = path.join(process.cwd(), "app/api");
|
||||||
const allTsFiles = getAllTsFiles(apiBasePath);
|
const allTsFiles = getAllFiles(apiBasePath, ".ts");
|
||||||
const routes: ApiRoute[] = [];
|
const routes: ApiRoute[] = [];
|
||||||
|
|
||||||
allTsFiles.forEach((filePath) => {
|
allTsFiles.forEach((filePath) => {
|
||||||
@@ -182,4 +198,31 @@ export async function getAllApis(): Promise<ApiRoute[]> {
|
|||||||
console.error("Fehler beim Auslesen der API-Dateien:", error);
|
console.error("Fehler beim Auslesen der API-Dateien:", error);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllWikiPages(): Promise<WikiPage[]> {
|
||||||
|
try {
|
||||||
|
const pagesBasePath = path.join(process.cwd(), "data/wiki/pages");
|
||||||
|
const allPaths = getAllFiles(pagesBasePath, ".mdx");
|
||||||
|
const allPages: WikiPage[] = [];
|
||||||
|
|
||||||
|
for (const filePath of allPaths) {
|
||||||
|
// extract filename of the path (e. g. "test" at "data/wiki/pages/test.mdx")
|
||||||
|
const slug = path.parse(filePath).name;
|
||||||
|
|
||||||
|
const wikiPage = await getWikiPageBySlug(slug);
|
||||||
|
|
||||||
|
if (wikiPage) {
|
||||||
|
allPages.push({
|
||||||
|
path: slug,
|
||||||
|
title: wikiPage.title,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(allPages);
|
||||||
|
return allPages;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Fehler beim Auslesen der Wiki-Seiten:", error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user