mirror of
https://github.com/directus/directus.git
synced 2026-01-28 10:08:03 -05:00
* Allow link type modules * Add docs module * Allow buttons to render as <a> * Update button readme * Use link buttons in module sidebar when needed
32 lines
713 B
TypeScript
32 lines
713 B
TypeScript
import { i18n } from '@/lang/';
|
|
import { ModuleDefineParam, ModuleContext, ModuleConfig } from './types';
|
|
|
|
export function defineModule(
|
|
config: ModuleDefineParam | ((context: ModuleContext) => ModuleConfig)
|
|
): ModuleConfig {
|
|
let options: ModuleConfig;
|
|
|
|
if (typeof config === 'function') {
|
|
const context: ModuleContext = { i18n };
|
|
options = config(context);
|
|
} else {
|
|
options = config;
|
|
}
|
|
|
|
if (options.routes !== undefined) {
|
|
options.routes = options.routes.map((route) => {
|
|
if (route.path) {
|
|
route.path = `/:project/${options.id}${route.path}`;
|
|
}
|
|
|
|
if (route.redirect) {
|
|
route.redirect = `/:project/${options.id}${route.redirect}`;
|
|
}
|
|
|
|
return route;
|
|
});
|
|
}
|
|
|
|
return options;
|
|
}
|