mirror of
https://github.com/BeamMP/BeamMP-Website.git
synced 2026-11-28 16:54:27 +00:00
BeamMP now runs community events with combined leaderboards, and the site had nowhere to show them. This adds an Events page listing each event and an event page with live standings, a driver search, the servers taking part and the event rules. Standings come from the API's public events routes, so no key is ever in the browser. The page keeps the last good results on screen if a refresh fails and says the connection was lost rather than going blank. Events with an uploaded banner show it behind the card and the page header, with an overlay so the text stays readable; events without one look as plain cards. The helpers the two pages share live beside them in views/events rather than in lib, since nothing else uses them. The Events link sits before Servers in the desktop and mobile menus. All of the new text is translated into the seven site languages using literal keys, so the locale checks can see every one. The translations are machine written and want a native speaker's review. src/lib/config.js is included because the pages need the API address from it: it is the one place that reads the window.__ENV__ the container writes at start, with the real services as the defaults.
213 lines
5.3 KiB
JavaScript
213 lines
5.3 KiB
JavaScript
import { loadLocaleMessages, setI18nLanguage, SUPPORT_LOCALES } from '@/i18n'
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
import NotFound from '@/views/NotFound.vue'
|
|
import { RouterView } from 'vue-router'
|
|
|
|
// Base routes without locale prefix
|
|
const baseRoutes = [
|
|
{
|
|
path: '',
|
|
name: 'Home',
|
|
component: () => import('@/views/Home.vue'),
|
|
meta: {
|
|
title: 'Home - BeamMP',
|
|
description: 'Welcome to BeamMP',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'about',
|
|
name: 'About',
|
|
component: () => import('@/views/About.vue'),
|
|
meta: {
|
|
title: 'About - BeamMP',
|
|
description: 'Learn more about BeamMP',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'communities',
|
|
name: 'Communities',
|
|
component: () => import('@/views/Communities.vue'),
|
|
meta: {
|
|
title: 'Communities - BeamMP',
|
|
description: 'Discover thriving BeamMP communities and find your group',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'servers',
|
|
name: 'Servers',
|
|
component: () => import('@/views/Servers.vue'),
|
|
meta: {
|
|
title: 'Servers - BeamMP',
|
|
description: 'Browse active BeamMP servers',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'stats',
|
|
name: 'Statistics',
|
|
component: () => import('@/views/Statistics.vue'),
|
|
meta: {
|
|
title: 'Statistics - BeamMP',
|
|
description: 'View BeamMP network statistics',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'partners',
|
|
name: 'Partners',
|
|
component: () => import('@/views/Partners.vue'),
|
|
meta: {
|
|
title: 'Partners - BeamMP',
|
|
description: 'Explore trusted hosting partners for BeamMP servers',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
|
|
{
|
|
path: 'events',
|
|
name: 'Events',
|
|
component: () => import('@/views/events/EventList.vue'),
|
|
meta: {
|
|
title: 'Events - BeamMP',
|
|
description: 'Live standings for BeamMP events',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'events/:eventId',
|
|
name: 'EventDetail',
|
|
component: () => import('@/views/events/EventDetail.vue'),
|
|
meta: {
|
|
title: 'Event standings - BeamMP',
|
|
description: 'Live standings for a BeamMP event',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
|
|
{
|
|
path: 'privacy',
|
|
name: 'Privacy',
|
|
component: () => import('@/views/Privacy.vue'),
|
|
meta: {
|
|
title: 'Privacy Policy - BeamMP',
|
|
description: 'Read our privacy policy',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
{
|
|
path: 'terms',
|
|
name: 'Terms',
|
|
component: () => import('@/views/Terms.vue'),
|
|
meta: {
|
|
title: 'Terms of Service - BeamMP',
|
|
description: 'Read our terms of service',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
|
|
// Redirect route for old keymaster
|
|
{
|
|
path: 'keymaster',
|
|
redirect: (to) => {
|
|
window.location.replace('https://keymaster.beammp.com/')
|
|
return `/${to.params.locale || 'en'}`
|
|
},
|
|
},
|
|
{
|
|
path: 'k/dashboard',
|
|
redirect: (to) => {
|
|
window.location.replace('https://keymaster.beammp.com/')
|
|
return `/${to.params.locale || 'en'}`
|
|
},
|
|
},
|
|
]
|
|
|
|
const routes = [
|
|
{
|
|
path: `/:locale(${SUPPORT_LOCALES.join('|')})`,
|
|
component: RouterView,
|
|
beforeEnter: (to) => {
|
|
console.log('Entering locale route:', to.params.locale)
|
|
// Validate locale
|
|
if (!SUPPORT_LOCALES.includes(to.params.locale)) {
|
|
return false
|
|
}
|
|
},
|
|
children: baseRoutes,
|
|
},
|
|
{
|
|
path: '/',
|
|
redirect: () => {
|
|
const locale = localStorage.getItem('lang') || 'en'
|
|
return `/${locale}`
|
|
},
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
name: 'NotFound',
|
|
component: NotFound,
|
|
meta: {
|
|
title: 'Page Not Found - BeamMP',
|
|
description: 'The page you are looking for does not exist',
|
|
requiresAuth: false,
|
|
},
|
|
},
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
})
|
|
|
|
// Global navigation guard for meta data and locale
|
|
router.beforeEach(async (to, from, next) => {
|
|
// The language is the first part of the address. The not-found route matches
|
|
// anything, so it has no `locale` param even for /en/nope: read the language
|
|
// from the path itself, or /en/nope would look like it has none and be sent
|
|
// to /en/en/nope, then /en/en/en/nope, and never finish.
|
|
const firstSegment = to.path.split('/')[1]
|
|
const pathLocale = SUPPORT_LOCALES.includes(firstSegment) ? firstSegment : null
|
|
|
|
// If the path has no locale prefix (e.g. /servers), redirect to /<lang>/servers
|
|
if (!to.params.locale && !pathLocale && to.path !== '/') {
|
|
const locale = localStorage.getItem('lang') || 'en'
|
|
return next(`/${locale}${to.path}`)
|
|
}
|
|
|
|
const paramsLocale = to.params.locale || pathLocale || 'en'
|
|
const i18n = window.i18n
|
|
|
|
// Ensure i18n is available
|
|
if (!i18n) {
|
|
next()
|
|
return
|
|
}
|
|
|
|
// load locale messages
|
|
if (!i18n.global.availableLocales.includes(paramsLocale)) {
|
|
await loadLocaleMessages(i18n, paramsLocale)
|
|
}
|
|
|
|
// set i18n language
|
|
setI18nLanguage(i18n, paramsLocale)
|
|
|
|
// Store current locale in localStorage
|
|
localStorage.setItem('lang', paramsLocale)
|
|
|
|
// Set page title
|
|
document.title = to.meta.title || 'BeamMP'
|
|
|
|
// Set meta description
|
|
const metaDescription = document.querySelector('meta[name="description"]')
|
|
if (metaDescription) {
|
|
metaDescription.setAttribute('content', to.meta.description || '')
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|