-
Notifications
You must be signed in to change notification settings - Fork 4
建立 Sponsor Footer #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mirumodapon
wants to merge
1
commit into
main
Choose a base branch
from
feat/sponsor-footer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−0
Open
建立 Sponsor Footer #131
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <script setup lang="ts"> | ||
| import type { Sponsor } from '#shared/types/sponsor' | ||
| import { useI18n } from 'vue-i18n' | ||
| import { SPONSOR_LEVELS } from '#shared/types/sponsor' | ||
|
|
||
| const { locale, t } = useI18n() | ||
|
|
||
| const { data } = useFetch('/api/sponsor', { default: () => [] as Sponsor[] }) | ||
|
|
||
| const sponsorGroups = computed(() => { | ||
| const grouped = Object.groupBy(data.value || [], (sponsor) => sponsor.level) | ||
| return SPONSOR_LEVELS | ||
| .filter((level) => grouped[level]?.length) | ||
| .map((level) => ({ | ||
| level, | ||
| sponsors: grouped[level]!, | ||
| })) | ||
| }) | ||
|
|
||
| const hasSponsor = computed(() => !!data.value?.length) | ||
| </script> | ||
|
|
||
| <template> | ||
| <section | ||
| v-if="hasSponsor" | ||
| class="px-8 pb-8 pt-16 bg-gray-50" | ||
| > | ||
| <div class="mx-auto max-w-[1100px]"> | ||
| <div | ||
| v-for="{ level, sponsors } in sponsorGroups" | ||
| :key="level" | ||
| class="mb-8 last:mb-0" | ||
| > | ||
| <h3 class="text-sm text-gray-600 tracking-wider font-bold mb-4 text-center uppercase"> | ||
| {{ t(`level.${level}`) }} | ||
| </h3> | ||
| <div | ||
| class="gap-4 grid grid-cols-2 lg:grid-cols-5 md:grid-cols-4" | ||
| > | ||
| <NuxtLink | ||
| v-for="sponsor in sponsors" | ||
| :key="sponsor.id" | ||
| class="p-3 rounded-lg bg-white flex shadow-sm transition items-center justify-center hover:shadow-md hover:scale-105" | ||
| external | ||
| rel="noreferrer" | ||
| target="_blank" | ||
| :title="sponsor.name[locale]" | ||
| :to="sponsor.link" | ||
| > | ||
| <NuxtImg | ||
| :alt="sponsor.name[locale]" | ||
| class="h-20 max-h-full max-w-full object-contain md:h-24" | ||
| :src="sponsor.image" | ||
| /> | ||
| </NuxtLink> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| </template> | ||
|
|
||
| <i18n lang="yaml"> | ||
| zh: | ||
| title: 贊助夥伴 | ||
| level: | ||
| titanium: 鈦金級 | ||
| diamond: 鑽石級 | ||
| gold: 黃金級 | ||
| silver: 白銀級 | ||
| bronze: 青銅級 | ||
| friend: 好朋友級 | ||
| community: 社群夥伴 | ||
| en: | ||
| title: Sponsors | ||
| level: | ||
| titanium: Titanium | ||
| diamond: Diamond | ||
| gold: Gold | ||
| silver: Silver | ||
| bronze: Bronze | ||
| friend: Friend | ||
| community: Community Partner | ||
| </i18n> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Including
CpSponsorFooterin the default layout means every page render/prerender will trigger its data fetch. Since/api/sponsorultimately hits Google Sheets (fetchSheet('sponsorList')), this can noticeably slownuxt generateand increase the chance of rate limiting. Consider adding caching (e.g., NitrocachedEventHandler/storage) or making the footer fetch lazy/client-side so it doesn’t block all routes during prerender.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSG 的部分應該不會一直請求(?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useFetch在 SSG 下 已經有去重和快取機制,而且/api/sponsor應該已經是個 cache function,應該不用擔心,頂多是每個頁面都會重複CpSponsorFooter的渲染結果而已。ClientOnly反而會導致 Sponsor 的區塊延遲出現,可能不太理想。