feat: implement management folder architecture, hover-only tool sliders, grain transform animation, and prominent upload studio
This commit is contained in:
@@ -4,6 +4,7 @@ import { SiteConfig, PageConfig, ToolItem, AppItem, CategoryItem } from '@/types
|
||||
import { getEndpointById } from '../catalog/loader';
|
||||
|
||||
const CONTENT_DIR = path.join(process.cwd(), 'content');
|
||||
const MANAGEMENT_DIR = path.join(process.cwd(), 'management');
|
||||
|
||||
// In-memory cache for speed and resilience
|
||||
let siteConfigCache: SiteConfig | null = null;
|
||||
@@ -35,19 +36,46 @@ export function getSiteConfig(): SiteConfig {
|
||||
|
||||
export function getPageConfig(slug: string): PageConfig | null {
|
||||
const normSlug = slug === '' || slug === '/' ? 'home' : slug.replace(/^\/+|\/+$/g, '');
|
||||
if (pagesCache.has(normSlug)) return pagesCache.get(normSlug)!;
|
||||
|
||||
const filePath = path.join(CONTENT_DIR, 'pages', `${normSlug}.json`);
|
||||
const page = readJsonFile<PageConfig>(filePath);
|
||||
if (page) {
|
||||
pagesCache.set(normSlug, page);
|
||||
// 1. Prioritize management/pages/[name]/page.config.json
|
||||
const mgmtPageFile = path.join(MANAGEMENT_DIR, 'pages', normSlug, 'page.config.json');
|
||||
if (fs.existsSync(mgmtPageFile)) {
|
||||
const page = readJsonFile<PageConfig>(mgmtPageFile);
|
||||
if (page) return page;
|
||||
}
|
||||
return page;
|
||||
|
||||
// 2. Fallback to content/pages/[name].json
|
||||
const filePath = path.join(CONTENT_DIR, 'pages', `${normSlug}.json`);
|
||||
return readJsonFile<PageConfig>(filePath);
|
||||
}
|
||||
|
||||
export function getAllTools(): ToolItem[] {
|
||||
if (toolsCache.size > 0) return Array.from(toolsCache.values());
|
||||
// 1. Prioritize management/pages/tools/[slug]/tool.config.json
|
||||
const mgmtToolsDir = path.join(MANAGEMENT_DIR, 'pages', 'tools');
|
||||
if (fs.existsSync(mgmtToolsDir)) {
|
||||
const slugs = fs.readdirSync(mgmtToolsDir);
|
||||
const tools: ToolItem[] = [];
|
||||
for (const slug of slugs) {
|
||||
const configPath = path.join(mgmtToolsDir, slug, 'tool.config.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const tool = readJsonFile<any>(configPath);
|
||||
if (tool && tool.status === 'published') {
|
||||
// Normalize media paths so before/after point to live management media
|
||||
if (tool.media?.before && tool.content?.examples?.[0]) {
|
||||
tool.content.examples[0].before = tool.media.before;
|
||||
}
|
||||
if (tool.media?.after && tool.content?.examples?.[0]) {
|
||||
tool.content.examples[0].after = tool.media.after;
|
||||
}
|
||||
tools.push(tool);
|
||||
toolsCache.set(tool.slug, tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tools.length > 0) return tools;
|
||||
}
|
||||
|
||||
// 2. Fallback to content/collections/tools
|
||||
const toolsDir = path.join(CONTENT_DIR, 'collections', 'tools');
|
||||
if (fs.existsSync(toolsDir)) {
|
||||
const files = fs.readdirSync(toolsDir).filter((f) => f.endsWith('.json'));
|
||||
@@ -75,8 +103,25 @@ export function getToolById(id: string): ToolItem | null {
|
||||
}
|
||||
|
||||
export function getAllApps(): AppItem[] {
|
||||
if (appsCache.size > 0) return Array.from(appsCache.values());
|
||||
// 1. Prioritize management/apps/[slug]/app.config.json
|
||||
const mgmtAppsDir = path.join(MANAGEMENT_DIR, 'apps');
|
||||
if (fs.existsSync(mgmtAppsDir)) {
|
||||
const slugs = fs.readdirSync(mgmtAppsDir);
|
||||
const apps: AppItem[] = [];
|
||||
for (const slug of slugs) {
|
||||
const configPath = path.join(mgmtAppsDir, slug, 'app.config.json');
|
||||
if (fs.existsSync(configPath)) {
|
||||
const app = readJsonFile<AppItem>(configPath);
|
||||
if (app && app.status === 'published') {
|
||||
apps.push(app);
|
||||
appsCache.set(app.slug, app);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apps.length > 0) return apps;
|
||||
}
|
||||
|
||||
// 2. Fallback to content/collections/apps
|
||||
const appsDir = path.join(CONTENT_DIR, 'collections', 'apps');
|
||||
if (fs.existsSync(appsDir)) {
|
||||
const files = fs.readdirSync(appsDir).filter((f) => f.endsWith('.json'));
|
||||
|
||||
Reference in New Issue
Block a user