Skip to content

Commit 2bbe888

Browse files
committed
update docs
1 parent 57c79f1 commit 2bbe888

File tree

4 files changed

+96
-70
lines changed

4 files changed

+96
-70
lines changed

docs/.vuepress/components/SponsorHome.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts" setup>
2-
import { homeSponsor } from "../data/sponsors";
2+
import { homeSponsor, shouldShowSponsor } from "../data/sponsors";
33
</script>
44

55
<template>
6-
<section v-if="homeSponsor.href && homeSponsor.link" id="special-spsr">
6+
<section v-if="shouldShowSponsor(homeSponsor)" id="special-spsr">
77
<span>特别赞助商</span>
88
<a :href="homeSponsor.href" target="_blank">
99
<img :alt="homeSponsor.alt" :src="homeSponsor.link" width="121" />
@@ -12,7 +12,7 @@ import { homeSponsor } from "../data/sponsors";
1212
</section>
1313
<section v-else id="special-spsr">
1414
<span class="no-brand">
15-
<a href="/fastapi_best_architecture_docs/sponsors">特别赞助位目前空缺 - 现在咨询 💬</a>
15+
<a href="/fastapi_best_architecture_docs/sponsors" target="_blank">特别赞助位目前空缺 - 现在咨询 💬</a>
1616
</span>
1717
</section>
1818
</template>

docs/.vuepress/components/SponsorPanel.vue

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<div class="brand-container">
1010
<div class="gold-sponsors">
1111
<div
12-
v-for="(brand, index) in goldSponsors"
13-
v-show="!isCollapsed || (isCollapsed && !brand.alt.includes('成为赞助商'))"
12+
v-for="(brand, index) in processedGoldSponsors"
13+
v-show="!isCollapsed || (isCollapsed && shouldShowSponsor(brand))"
1414
:key="'gold-' + index"
1515
:class="{ 'collapsed-mode': isCollapsed }"
1616
class="brand-item gold"
@@ -27,8 +27,8 @@
2727
</div>
2828
<div class="general-sponsors">
2929
<div
30-
v-for="(brand, index) in generalSponsors"
31-
v-show="!isCollapsed || (isCollapsed && !brand.alt.includes('成为赞助商'))"
30+
v-for="(brand, index) in processedGeneralSponsors"
31+
v-show="!isCollapsed || (isCollapsed && shouldShowSponsor(brand))"
3232
:key="'general-' + index"
3333
:class="{ 'collapsed-mode': isCollapsed }"
3434
class="brand-item"
@@ -43,36 +43,53 @@
4343
</span>
4444
</div>
4545
</div>
46-
<div v-if="isCollapsed && brandNum() < 9" class="brand-item become-brand" @click="openSponsorLink(sponsorUrl)">
46+
<div
47+
v-if="isCollapsed && shouldShowExtraBecomeSponsor"
48+
class="brand-item become-brand"
49+
@click="openSponsorLink(sponsorUrl)"
50+
>
4751
<span class="brand-text">成为赞助商</span>
4852
</div>
4953
</div>
5054
</template>
5155

5256
<script setup>
5357
import { computed, onMounted, ref } from "vue";
54-
import { generalSponsors, goldSponsors, sponsorUrl } from "../data/sponsors";
58+
import {
59+
defaultSponsor,
60+
generalSponsors,
61+
goldSponsors,
62+
openSponsorLink,
63+
shouldShowSponsor,
64+
sponsorUrl
65+
} from "../data/sponsors";
5566
5667
const isCollapsed = ref(false);
5768
69+
const processedGoldSponsors = computed(() => {
70+
return goldSponsors.map(brand => {
71+
return shouldShowSponsor(brand) ? brand : defaultSponsor;
72+
});
73+
});
74+
75+
const processedGeneralSponsors = computed(() => {
76+
return generalSponsors.map(brand => {
77+
return shouldShowSponsor(brand) ? brand : defaultSponsor;
78+
});
79+
});
80+
81+
const shouldShowExtraBecomeSponsor = computed(() => {
82+
return (goldSponsors.filter(brand => brand.link && shouldShowSponsor(brand)).length +
83+
generalSponsors.filter(brand => brand.link && shouldShowSponsor(brand)).length) < 9;
84+
});
85+
5886
const toggleCollapse = () => {
5987
isCollapsed.value = !isCollapsed.value;
6088
if (typeof window !== 'undefined') {
6189
localStorage.setItem("sponsorCollapsed", isCollapsed.value);
6290
}
6391
};
6492
65-
const openSponsorLink = (href) => {
66-
if (typeof window !== 'undefined') {
67-
window.open(href, "_blank");
68-
}
69-
};
70-
71-
const brandNum = () => {
72-
return goldSponsors.value.filter(item => item.link?.trim() !== '').length +
73-
generalSponsors.value.filter(item => item.link?.trim() !== '').length;
74-
}
75-
7693
onMounted(() => {
7794
if (typeof window !== 'undefined') {
7895
const savedState = localStorage.getItem("sponsorCollapsed");
@@ -81,7 +98,6 @@ onMounted(() => {
8198
});
8299
</script>
83100

84-
85101
<style scoped>
86102
.brand-header {
87103
display: flex;

docs/.vuepress/components/SponsorSidebar.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
</div>
55
<div class="brand-container">
66
<div class="sidebar-brand">
7-
<div class="brand" @click="openSponsorLink(homeSponsor.href)">
8-
<img v-if="homeSponsor.link" :alt="homeSponsor.alt" :src="homeSponsor.link" class="brand-image" />
7+
<div
8+
class="brand"
9+
@click="openSponsorLink(homeSponsor.href)"
10+
>
11+
<img
12+
v-if="shouldShowSponsor(homeSponsor)"
13+
:alt="homeSponsor.alt"
14+
:src="homeSponsor.link"
15+
class="brand-image"
16+
/>
917
<span v-else class="brand-text">成为赞助商</span>
1018
</div>
1119
</div>
1220
</div>
1321
</template>
1422

1523
<script setup>
16-
import { homeSponsor } from "../data/sponsors";
17-
18-
const openSponsorLink = (href) => {
19-
window.open(href, "_blank");
20-
};
24+
import { homeSponsor, openSponsorLink, shouldShowSponsor } from "../data/sponsors";
2125
</script>
2226

2327
<style scoped>

docs/.vuepress/data/sponsors.ts

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,68 @@
1-
import { ref } from "vue";
2-
31
export const sponsorUrl: string = typeof window !== 'undefined' ? window.location.origin + '/fastapi_best_architecture_docs/sponsors.html' : 'https://fastapi-practices.github.io/fastapi_best_architecture_docs/sponsors.html';
42

5-
export const homeSponsor = ref(
6-
{
7-
link: '',
8-
href: sponsorUrl,
9-
alt: '',
10-
}
11-
)
3+
interface Sponsor {
4+
href?: string;
5+
link?: string;
6+
alt?: string;
7+
expiryTime: string; // ISO 格式日期:2099-12-31T23:59:59
8+
}
9+
10+
export const defaultSponsor: Sponsor = {
11+
link: '',
12+
href: sponsorUrl,
13+
alt: '成为赞助商',
14+
expiryTime: '2099-12-31T23:59:59',
15+
};
16+
17+
export const homeSponsor: Sponsor = { ...defaultSponsor };
18+
1219

13-
export const goldSponsors = ref([
20+
export const goldSponsors: Sponsor[] = [
1421
{
1522
link: 'https://dscache.tencent-cloud.cn/upload//rhino-design-800x450-fea2ea55b7b63624628bf9bb22454cb8f91b7d69.png',
1623
href: 'https://curl.qcloud.com/f9VMAii8',
1724
alt: '2核2G云服务器低至 68元/年',
25+
expiryTime: '2025-12-31T23:59:59',
1826
},
1927
{
2028
link: 'https://img14.360buyimg.com/ddimg/jfs/t1/284966/5/22913/37242/68023351Faddd8304/6337ad52ea02ad10.jpg',
2129
href: 'https://share.302.ai/LJojhb',
2230
alt: '302.AI',
31+
expiryTime: '2099-12-31T23:59:59',
2332
},
24-
{
25-
link: '',
26-
href: sponsorUrl,
27-
alt: '成为赞助商',
28-
}
29-
])
33+
{ ...defaultSponsor }
34+
]
3035

31-
export const generalSponsors = ref([
36+
export const generalSponsors: Sponsor[] = [
3237
{
3338
link: 'https://user.by.ltd/templates/lagom/assets/img/logo/logo_big.png',
3439
href: 'https://user.by.ltd/aff.php?aff=12215',
3540
alt: 'Bywave',
41+
expiryTime: '2099-12-31T23:59:59',
3642
},
37-
{
38-
link: '',
39-
href: sponsorUrl,
40-
alt: '成为赞助商',
41-
},
42-
{
43-
link: '',
44-
href: sponsorUrl,
45-
alt: '成为赞助商',
46-
},
47-
{
48-
link: '',
49-
href: sponsorUrl,
50-
alt: '成为赞助商',
51-
},
52-
{
53-
link: '',
54-
href: sponsorUrl,
55-
alt: '成为赞助商',
56-
},
57-
{
58-
link: '',
59-
href: sponsorUrl,
60-
alt: '成为赞助商',
43+
{ ...defaultSponsor },
44+
{ ...defaultSponsor },
45+
{ ...defaultSponsor },
46+
{ ...defaultSponsor },
47+
{ ...defaultSponsor }
48+
]
49+
50+
export const openSponsorLink = (href: string) => {
51+
window.open(href);
52+
};
53+
54+
export function shouldShowSponsor(sponsor: {
55+
href?: string;
56+
link?: string;
57+
expiryTime?: string;
58+
}): boolean {
59+
if (!sponsor.link) return false;
60+
61+
if (sponsor.expiryTime) {
62+
const now = new Date();
63+
const expiryDate = new Date(sponsor.expiryTime);
64+
return now < expiryDate;
6165
}
62-
])
66+
67+
return true;
68+
}

0 commit comments

Comments
 (0)