feat(SSR): 为站点添加SSR机制 #38

Manually merged
remilia merged 9 commits from feat/ssr into master 2025-09-28 16:58:29 +08:00
12 changed files with 419 additions and 397 deletions
Showing only changes of commit 1ac9c76c3e - Show all commits

View File

@ -101,12 +101,24 @@
const localePath = useLocalePath();
// 搜索相关
const loading = ref(true);
const { search } = useMeilisearch();
const keyword = ref('');
const activeRequestId = ref(0);
const sections = ref<SearchSection[]>([]);
const {
data: sections,
pending: loading,
error,
refresh,
} = await useAsyncData(
() => `search-${route.query.query ?? ''}`,
async () => {
const q = String(route.query.query ?? '').trim();
if (!q) return [];
return await search(q, { limit: 12 });
}
);
// 本地化+空Section过滤
const filteredSections = computed(() =>
sections.value
@ -137,7 +149,7 @@
return map;
});
// 分控制
// 分控制
const currentPage = ref(1);
const hasResults = computed(() =>
@ -165,7 +177,6 @@
return;
}
loading.value = true;
try {
const results = await search(trimmed, { limit: 12 });
if (requestId === activeRequestId.value) {
@ -178,10 +189,6 @@
if (requestId === activeRequestId.value) {
sections.value = [];
}
} finally {
if (requestId === activeRequestId.value) {
loading.value = false;
}
}
};
@ -204,12 +211,8 @@
);
onMounted(() => {
if (typeof route.query.query === 'string' && route.query.query.trim()) {
if (typeof route.query.query === 'string' && route.query.query.trim())
keyword.value = route.query.query;
performSearch(route.query.query);
} else {
loading.value = false;
}
});
useHead(() => ({