From 9f6b0e1018f14488f6309025a251d44137c8c9ac Mon Sep 17 00:00:00 2001 From: Prospector <6166773+Prospector@users.noreply.github.com> Date: Wed, 11 Jan 2023 09:52:43 -0800 Subject: [PATCH] Add latest version URLs (Closes #830) (#901) --- pages/_type/_id/version.vue | 55 +++++++++++++++++++----------- pages/_type/_id/version/latest.vue | 10 ++++++ 2 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 pages/_type/_id/version/latest.vue diff --git a/pages/_type/_id/version.vue b/pages/_type/_id/version.vue index d8e92fc9..e64fe373 100644 --- a/pages/_type/_id/version.vue +++ b/pages/_type/_id/version.vue @@ -1072,29 +1072,46 @@ export default { this.isEditing = true } - this.version = this.versions.find( - (x) => x.id === this.$route.params.version - ) - - if (!this.version) + if (mode === 'latest') { + let versionList = this.versions + if (this.$route.query.loader) { + versionList = versionList.filter((x) => + x.loaders.includes(this.$route.query.loader) + ) + } + if (this.$route.query.version) { + versionList = versionList.filter((x) => + x.game_versions.includes(this.$route.query.version) + ) + } + this.version = versionList.reduce((a, b) => + a.date_published > b.date_published ? a : b + ) + } else { this.version = this.versions.find( - (x) => x.displayUrlEnding === this.$route.params.version + (x) => x.id === this.$route.params.version ) - // LEGACY- to support old duplicate version URLs - const dashIndex = this.$route.params.version.indexOf('-') - if (!this.version && dashIndex !== -1) { - const version = this.versions.find( - (x) => - x.displayUrlEnding === - this.$route.params.version.substring(0, dashIndex) - ) + if (!this.version) + this.version = this.versions.find( + (x) => x.displayUrlEnding === this.$route.params.version + ) - this.$nuxt.context.redirect( - 301, - `/${this.project.project_type}/${this.project.slug}/version/${version.version_number}` - ) - return + // LEGACY- to support old duplicate version URLs + const dashIndex = this.$route.params.version.indexOf('-') + if (!this.version && dashIndex !== -1) { + const version = this.versions.find( + (x) => + x.displayUrlEnding === + this.$route.params.version.substring(0, dashIndex) + ) + + this.$nuxt.context.redirect( + 301, + `/${this.project.project_type}/${this.project.slug}/version/${version.version_number}` + ) + return + } } if (!this.version) { diff --git a/pages/_type/_id/version/latest.vue b/pages/_type/_id/version/latest.vue new file mode 100644 index 00000000..0124eafa --- /dev/null +++ b/pages/_type/_id/version/latest.vue @@ -0,0 +1,10 @@ + + + +