mirror of
https://github.com/modrinth/code.git
synced 2026-08-26 09:34:50 +00:00
update tags page + sort project types consistently (#7044)
This commit is contained in:
@@ -6,6 +6,7 @@ export * from './file-extensions'
|
||||
export * from './game-modes'
|
||||
export * from './loaders'
|
||||
export * from './notices'
|
||||
export * from './project-types'
|
||||
export * from './savable'
|
||||
export * from './search'
|
||||
export * from './server-content-installing'
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
export const PROJECT_TYPE_ORDER = [
|
||||
'mod',
|
||||
'resourcepack',
|
||||
'datapack',
|
||||
'shader',
|
||||
'modpack',
|
||||
'plugin',
|
||||
'server',
|
||||
'collection',
|
||||
] as const
|
||||
|
||||
export type OrderedProjectType = (typeof PROJECT_TYPE_ORDER)[number]
|
||||
|
||||
const PROJECT_TYPE_SORT_ALIASES: Record<string, string> = {
|
||||
minecraft_java_server: 'server',
|
||||
shaderpack: 'shader',
|
||||
}
|
||||
|
||||
export function getProjectTypeSortIndex(type: string): number {
|
||||
const normalized = PROJECT_TYPE_SORT_ALIASES[type] ?? type
|
||||
const index = (PROJECT_TYPE_ORDER as readonly string[]).indexOf(normalized)
|
||||
return index === -1 ? PROJECT_TYPE_ORDER.length : index
|
||||
}
|
||||
|
||||
export function compareProjectTypes(a: string, b: string): number {
|
||||
return getProjectTypeSortIndex(a) - getProjectTypeSortIndex(b)
|
||||
}
|
||||
|
||||
export function sortProjectTypes<T extends string>(types: Iterable<T>): T[] {
|
||||
return [...types].sort(compareProjectTypes)
|
||||
}
|
||||
@@ -93,10 +93,10 @@ export type ProjectType =
|
||||
|
||||
const ALL_PROJECT_TYPES: ProjectType[] = [
|
||||
'mod',
|
||||
'modpack',
|
||||
'resourcepack',
|
||||
'shader',
|
||||
'datapack',
|
||||
'shader',
|
||||
'modpack',
|
||||
'plugin',
|
||||
'server',
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user