Files
software-station/frontend/src/routes/docs/[...slug]/+page.ts
Sudo-Ivan d8748bba77
All checks were successful
CI / build (push) Successful in 1m8s
renovate / renovate (push) Successful in 1m42s
Update asset caching and documentation features
- Updated the API server to support asset caching with a new flag for enabling/disabling caching.
- Implemented asset caching logic in the DownloadProxyHandler to store and retrieve assets efficiently.
- Added tests for asset caching functionality, ensuring proper behavior for cache hits and misses.
- Introduced new documentation files for software, including multi-language support.
- Enhanced the SoftwareCard component to display documentation links for software with available docs.
- Updated the Software model to include a flag indicating the presence of documentation.
- Improved the user interface for documentation navigation and search functionality.
2025-12-27 19:08:36 -06:00

53 lines
1.2 KiB
TypeScript

import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
import { get } from 'svelte/store';
import { locale } from 'svelte-i18n';
export const load = async ({ params, depends }) => {
const { slug } = params;
depends('app:locale');
const currentLocale = (browser ? localStorage.getItem('locale') : null) || get(locale) || 'en';
const cleanSlug = slug.endsWith('/') ? slug.slice(0, -1) : slug;
const modules = import.meta.glob('../../../lib/docs/**/*.{svx,md}');
let match: (() => Promise<any>) | undefined;
const localeSpecificPaths = [
`../../../lib/docs/${cleanSlug}.${currentLocale}.svx`,
`../../../lib/docs/${cleanSlug}.${currentLocale}.md`,
];
for (const path of localeSpecificPaths) {
if (modules[path]) {
match = modules[path];
break;
}
}
if (!match) {
match = modules[`../../../lib/docs/${cleanSlug}.svx`];
if (!match) {
match = modules[`../../../lib/docs/${cleanSlug}.md`];
}
}
if (!match) {
throw error(404, 'Documentation not found');
}
try {
const doc = (await match()) as any;
return {
content: doc.default,
metadata: doc.metadata,
};
} catch (e) {
console.error('Error loading doc:', e);
throw error(500, 'Error loading documentation content');
}
};