Cache homepage projects in tags (#1336)
* Cache homepage projects in tags * Update app page
This commit is contained in:
parent
ae4f3759c2
commit
04b85630b9
10
.github/workflows/frontend-pages.yml
vendored
10
.github/workflows/frontend-pages.yml
vendored
@ -17,4 +17,12 @@ jobs:
|
||||
accountId: '9ddae624c98677d68d93df6e524a6061'
|
||||
project: 'frontend'
|
||||
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[];
|
||||
donationPlatforms?: any[];
|
||||
reportTypes?: any[];
|
||||
homePageProjects?: any[];
|
||||
homePageSearch?: any[];
|
||||
homePageNotifs?: any[];
|
||||
} = {};
|
||||
|
||||
try {
|
||||
@ -153,21 +156,34 @@ export default defineNuxtConfig({
|
||||
},
|
||||
};
|
||||
|
||||
const [categories, loaders, gameVersions, donationPlatforms, reportTypes] = await Promise.all(
|
||||
[
|
||||
$fetch(`${API_URL}tag/category`, headers),
|
||||
$fetch(`${API_URL}tag/loader`, headers),
|
||||
$fetch(`${API_URL}tag/game_version`, headers),
|
||||
$fetch(`${API_URL}tag/donation_platform`, headers),
|
||||
$fetch(`${API_URL}tag/report_type`, headers),
|
||||
],
|
||||
);
|
||||
const [
|
||||
categories,
|
||||
loaders,
|
||||
gameVersions,
|
||||
donationPlatforms,
|
||||
reportTypes,
|
||||
homePageProjects,
|
||||
homePageSearch,
|
||||
homePageNotifs,
|
||||
] = await Promise.all([
|
||||
$fetch(`${API_URL}tag/category`, headers),
|
||||
$fetch(`${API_URL}tag/loader`, headers),
|
||||
$fetch(`${API_URL}tag/game_version`, headers),
|
||||
$fetch(`${API_URL}tag/donation_platform`, 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.loaders = loaders;
|
||||
state.gameVersions = gameVersions;
|
||||
state.donationPlatforms = donationPlatforms;
|
||||
state.reportTypes = reportTypes;
|
||||
state.homePageProjects = homePageProjects;
|
||||
state.homePageSearch = homePageSearch;
|
||||
state.homePageNotifs = homePageNotifs;
|
||||
|
||||
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 Checkbox from "~/components/ui/Checkbox.vue";
|
||||
|
||||
import { homePageProjects } from "~/generated/state.json";
|
||||
|
||||
const os = ref(null);
|
||||
const macValue = ref(null);
|
||||
const downloadWindows = ref(null);
|
||||
@ -34,19 +36,17 @@ const macLinks = {
|
||||
|
||||
let downloadLauncher;
|
||||
|
||||
const [{ data: rows }, { data: launcherUpdates }] = await Promise.all([
|
||||
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), {
|
||||
transform: (homepageProjects) => {
|
||||
const val = Math.ceil(homepageProjects.length / 6);
|
||||
return [
|
||||
homepageProjects.slice(0, val),
|
||||
homepageProjects.slice(val, val * 2),
|
||||
homepageProjects.slice(val * 2, val * 3),
|
||||
homepageProjects.slice(val * 3, val * 4),
|
||||
homepageProjects.slice(val * 4, val * 5),
|
||||
];
|
||||
},
|
||||
}),
|
||||
const newProjects = homePageProjects.slice(0, 40);
|
||||
const val = Math.ceil(newProjects.length / 6);
|
||||
const rows = ref([
|
||||
newProjects.slice(0, val),
|
||||
newProjects.slice(val, val * 2),
|
||||
newProjects.slice(val * 2, val * 3),
|
||||
newProjects.slice(val * 3, val * 4),
|
||||
newProjects.slice(val * 4, val * 5),
|
||||
]);
|
||||
|
||||
const [{ data: launcherUpdates }] = await Promise.all([
|
||||
await useAsyncData("launcherUpdates", () =>
|
||||
$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 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 auth = await useAuth();
|
||||
const tags = useTags();
|
||||
|
||||
const [
|
||||
{ data: rows },
|
||||
{ data: searchProjects, refresh: updateSearchProjects },
|
||||
{ data: notifications },
|
||||
] = await Promise.all([
|
||||
useAsyncData("projects", () => useBaseFetch("projects_random?count=40"), {
|
||||
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 newProjects = homePageProjects.slice(0, 40);
|
||||
const val = Math.ceil(newProjects.length / 3);
|
||||
const rows = ref([
|
||||
newProjects.slice(0, val),
|
||||
newProjects.slice(val, val * 2),
|
||||
newProjects.slice(val * 2, val * 3),
|
||||
]);
|
||||
|
||||
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>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user