chore: optimize reference gallery, add typography plugin, fix SEO and map animations
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 37s
Build & Deploy / 🧪 QA (push) Failing after 1m31s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 4s
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 37s
Build & Deploy / 🧪 QA (push) Failing after 1m31s
Build & Deploy / 🏗️ Build (push) Has been skipped
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 4s
This commit is contained in:
52
lib/references.ts
Normal file
52
lib/references.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
|
||||
export interface ReferenceFrontmatter {
|
||||
title: string;
|
||||
client: string;
|
||||
date: string;
|
||||
dateString?: string;
|
||||
featuredImage?: string | null;
|
||||
location: string;
|
||||
}
|
||||
|
||||
export interface ReferenceData {
|
||||
slug: string;
|
||||
frontmatter: ReferenceFrontmatter;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export async function getReferenceBySlug(slug: string, locale: string): Promise<ReferenceData | null> {
|
||||
const localeDir = path.join(process.cwd(), 'content', locale, 'referenzen');
|
||||
const filePath = path.join(localeDir, `${slug}.mdx`);
|
||||
|
||||
if (!fs.existsSync(filePath)) return null;
|
||||
|
||||
const source = fs.readFileSync(filePath, 'utf8');
|
||||
const { content, data } = matter(source);
|
||||
|
||||
return {
|
||||
slug,
|
||||
frontmatter: data as ReferenceFrontmatter,
|
||||
content,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getAllReferences(locale: string): Promise<ReferenceData[]> {
|
||||
const localeDir = path.join(process.cwd(), 'content', locale, 'referenzen');
|
||||
if (!fs.existsSync(localeDir)) return [];
|
||||
|
||||
const files = fs.readdirSync(localeDir).filter(f => f.endsWith('.mdx'));
|
||||
|
||||
const references = await Promise.all(
|
||||
files.map(async f => {
|
||||
const slug = f.replace('.mdx', '');
|
||||
return await getReferenceBySlug(slug, locale);
|
||||
})
|
||||
);
|
||||
|
||||
return references
|
||||
.filter((p): p is ReferenceData => p !== null)
|
||||
.sort((a, b) => new Date(b.frontmatter.date).getTime() - new Date(a.frontmatter.date).getTime());
|
||||
}
|
||||
Reference in New Issue
Block a user