Cache homepage projects in tags (#1336)
* Cache homepage projects in tags * Update app page
This commit is contained in:
parent
ae4f3759c2
commit
04b85630b9
8
.github/workflows/frontend-pages.yml
vendored
8
.github/workflows/frontend-pages.yml
vendored
@ -18,3 +18,11 @@ jobs:
|
|||||||
project: 'frontend'
|
project: 'frontend'
|
||||||
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||||
commitHash: ${{ steps.push-changes.outputs.commit-hash }}
|
commitHash: ${{ steps.push-changes.outputs.commit-hash }}
|
||||||
|
- name: Purge cache
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
curl -X \
|
||||||
|
-H "Authorization: ${{ secrets.CF_API_TOKEN }}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data '{"hosts": ["modrinth.com", "www.modrinth.com"]}' \
|
||||||
|
https://api.cloudflare.com/client/v4/zones/e39df17b9c4ef44cbce2646346ee6d33/purge_cache
|
||||||
|
|||||||
@ -122,6 +122,9 @@ export default defineNuxtConfig({
|
|||||||
gameVersions?: any[];
|
gameVersions?: any[];
|
||||||
donationPlatforms?: any[];
|
donationPlatforms?: any[];
|
||||||
reportTypes?: any[];
|
reportTypes?: any[];
|
||||||
|
homePageProjects?: any[];
|
||||||
|
homePageSearch?: any[];
|
||||||
|
homePageNotifs?: any[];
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -153,21 +156,34 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const [categories, loaders, gameVersions, donationPlatforms, reportTypes] = await Promise.all(
|
const [
|
||||||
[
|
categories,
|
||||||
|
loaders,
|
||||||
|
gameVersions,
|
||||||
|
donationPlatforms,
|
||||||
|
reportTypes,
|
||||||
|
homePageProjects,
|
||||||
|
homePageSearch,
|
||||||
|
homePageNotifs,
|
||||||
|
] = await Promise.all([
|
||||||
$fetch(`${API_URL}tag/category`, headers),
|
$fetch(`${API_URL}tag/category`, headers),
|
||||||
$fetch(`${API_URL}tag/loader`, headers),
|
$fetch(`${API_URL}tag/loader`, headers),
|
||||||
$fetch(`${API_URL}tag/game_version`, headers),
|
$fetch(`${API_URL}tag/game_version`, headers),
|
||||||
$fetch(`${API_URL}tag/donation_platform`, headers),
|
$fetch(`${API_URL}tag/donation_platform`, headers),
|
||||||
$fetch(`${API_URL}tag/report_type`, headers),
|
$fetch(`${API_URL}tag/report_type`, headers),
|
||||||
],
|
$fetch(`${API_URL}projects_random?count=60`, headers),
|
||||||
);
|
$fetch(`${API_URL}search?limit=3&query=leave&index=relevance`, headers),
|
||||||
|
$fetch(`${API_URL}search?limit=3&query=&index=updated`, headers),
|
||||||
|
]);
|
||||||
|
|
||||||
state.categories = categories;
|
state.categories = categories;
|
||||||
state.loaders = loaders;
|
state.loaders = loaders;
|
||||||
state.gameVersions = gameVersions;
|
state.gameVersions = gameVersions;
|
||||||
state.donationPlatforms = donationPlatforms;
|
state.donationPlatforms = donationPlatforms;
|
||||||
state.reportTypes = reportTypes;
|
state.reportTypes = reportTypes;
|
||||||
|
state.homePageProjects = homePageProjects;
|
||||||
|
state.homePageSearch = homePageSearch;
|
||||||
|
state.homePageNotifs = homePageNotifs;
|
||||||
|
|
||||||
await fs.writeFile("./src/generated/state.json", JSON.stringify(state));
|
await fs.writeFile("./src/generated/state.json", JSON.stringify(state));
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@ import ATLauncher from "~/assets/images/external/atlauncher.svg?component";
|
|||||||
import CurseForge from "~/assets/images/external/curseforge.svg?component";
|
import CurseForge from "~/assets/images/external/curseforge.svg?component";
|
||||||
import Checkbox from "~/components/ui/Checkbox.vue";
|
import Checkbox from "~/components/ui/Checkbox.vue";
|
||||||
|
|
||||||
|
import { homePageProjects } from "~/generated/state.json";
|
||||||
|
|
||||||
const os = ref(null);
|
const os = ref(null);
|
||||||
const macValue = ref(null);
|
const macValue = ref(null);
|
||||||
const downloadWindows = ref(null);
|
const downloadWindows = ref(null);
|
||||||
@ -34,19 +36,17 @@ const macLinks = {
|
|||||||
|
|
||||||
let downloadLauncher;
|
let downloadLauncher;
|
||||||
|
|
||||||
const [{ data: rows }, { data: launcherUpdates }] = await Promise.all([
|
const newProjects = homePageProjects.slice(0, 40);
|
||||||
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), {
|
const val = Math.ceil(newProjects.length / 6);
|
||||||
transform: (homepageProjects) => {
|
const rows = ref([
|
||||||
const val = Math.ceil(homepageProjects.length / 6);
|
newProjects.slice(0, val),
|
||||||
return [
|
newProjects.slice(val, val * 2),
|
||||||
homepageProjects.slice(0, val),
|
newProjects.slice(val * 2, val * 3),
|
||||||
homepageProjects.slice(val, val * 2),
|
newProjects.slice(val * 3, val * 4),
|
||||||
homepageProjects.slice(val * 2, val * 3),
|
newProjects.slice(val * 4, val * 5),
|
||||||
homepageProjects.slice(val * 3, val * 4),
|
]);
|
||||||
homepageProjects.slice(val * 4, val * 5),
|
|
||||||
];
|
const [{ data: launcherUpdates }] = await Promise.all([
|
||||||
},
|
|
||||||
}),
|
|
||||||
await useAsyncData("launcherUpdates", () =>
|
await useAsyncData("launcherUpdates", () =>
|
||||||
$fetch("https://launcher-files.modrinth.com/updates.json"),
|
$fetch("https://launcher-files.modrinth.com/updates.json"),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -513,34 +513,32 @@ import ATLauncherLogo from "~/assets/images/external/atlauncher.svg?component";
|
|||||||
import Avatar from "~/components/ui/Avatar.vue";
|
import Avatar from "~/components/ui/Avatar.vue";
|
||||||
import ProjectCard from "~/components/ui/ProjectCard.vue";
|
import ProjectCard from "~/components/ui/ProjectCard.vue";
|
||||||
|
|
||||||
const searchQuery = ref("better");
|
import { homePageProjects, homePageSearch, homePageNotifs } from "~/generated/state.json";
|
||||||
|
|
||||||
|
const searchQuery = ref("leave");
|
||||||
const sortType = ref("relevance");
|
const sortType = ref("relevance");
|
||||||
|
|
||||||
const auth = await useAuth();
|
const auth = await useAuth();
|
||||||
const tags = useTags();
|
const tags = useTags();
|
||||||
|
|
||||||
const [
|
const newProjects = homePageProjects.slice(0, 40);
|
||||||
{ data: rows },
|
const val = Math.ceil(newProjects.length / 3);
|
||||||
{ data: searchProjects, refresh: updateSearchProjects },
|
const rows = ref([
|
||||||
{ data: notifications },
|
newProjects.slice(0, val),
|
||||||
] = await Promise.all([
|
newProjects.slice(val, val * 2),
|
||||||
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), {
|
newProjects.slice(val * 2, val * 3),
|
||||||
transform: (result) => {
|
|
||||||
const val = Math.ceil(result.length / 3);
|
|
||||||
return [result.slice(0, val), result.slice(val, val * 2), result.slice(val * 2, val * 3)];
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
useAsyncData(
|
|
||||||
"demoSearchProjects",
|
|
||||||
() => useBaseFetch(`search?limit=3&query=${searchQuery.value}&index=${sortType.value}`),
|
|
||||||
{
|
|
||||||
transform: (result) => result.hits,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
useAsyncData("updatedProjects", () => useBaseFetch(`search?limit=3&query=&index=updated`), {
|
|
||||||
transform: (result) => result.hits,
|
|
||||||
}),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const notifications = ref(homePageNotifs.hits ?? []);
|
||||||
|
const searchProjects = ref(homePageSearch.hits ?? []);
|
||||||
|
|
||||||
|
async function updateSearchProjects() {
|
||||||
|
const res = await useBaseFetch(
|
||||||
|
`search?limit=3&query=${searchQuery.value}&index=${sortType.value}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
searchProjects.value = res.hits ?? [];
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user