-
-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
292 additions
and
197 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,137 @@ | ||
<script lang="ts"> | ||
// shared data across instances so we load only once | ||
let data = $ref<SponsorData>() | ||
const base = `https://sponsors.vuejs.org` | ||
const dataUrl = `${base}/vite.json` | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, onUnmounted } from 'vue' | ||
interface Sponsor { | ||
url: string | ||
img: string | ||
name: string | ||
} | ||
interface SponsorData { | ||
special: Sponsor[] | ||
platinum: Sponsor[] | ||
platinum_china: Sponsor[] | ||
gold: Sponsor[] | ||
silver: Sponsor[] | ||
bronze: Sponsor[] | ||
} | ||
const { tier, placement = 'aside' } = defineProps<{ | ||
tier: keyof SponsorData | ||
placement?: 'aside' | 'page' | 'landing' | ||
}>() | ||
let container = $ref<HTMLElement>() | ||
let visible = $ref(false) | ||
onMounted(async () => { | ||
// only render when entering view | ||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
if (entries[0].isIntersecting) { | ||
visible = true | ||
observer.disconnect() | ||
} | ||
}, | ||
{ rootMargin: '0px 0px 300px 0px' } | ||
) | ||
observer.observe(container) | ||
onUnmounted(() => observer.disconnect()) | ||
// load data | ||
if (!data) { | ||
data = await (await fetch(dataUrl)).json() | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="container" | ||
class="sponsor-container" | ||
:class="[tier.startsWith('plat') ? 'platinum' : tier, placement]" | ||
> | ||
<template v-if="data && visible"> | ||
<a | ||
v-for="{ url, img, name } of data[tier]" | ||
class="sponsor-item" | ||
:href="url" | ||
target="_blank" | ||
rel="sponsored noopener" | ||
> | ||
<picture v-if="img.endsWith('png')"> | ||
<source | ||
type="image/avif" | ||
:srcset="`${base}/images/${img.replace(/\.png$/, '.avif')}`" | ||
/> | ||
<img :src="`${base}/images/${img}`" :alt="name" /> | ||
</picture> | ||
<img v-else :src="`${base}/images/${img}`" :alt="name" /> | ||
</a> | ||
</template> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.sponsor-container { | ||
--max-width: 100%; | ||
display: flex; | ||
justify-content: space-evenly; | ||
flex-wrap: wrap; | ||
} | ||
.sponsor-container.platinum { | ||
--max-width: 260px; | ||
} | ||
.sponsor-container.gold { | ||
--max-width: 160px; | ||
} | ||
.sponsor-container.silver { | ||
--max-width: 140px; | ||
} | ||
.sponsor-item { | ||
margin: 2px 0; | ||
display: flex; | ||
align-items: center; | ||
border-radius: 2px; | ||
transition: background-color 0.2s ease; | ||
height: calc(var(--max-width) / 2 - 6px); | ||
} | ||
.sponsor-item.action { | ||
font-size: 11px; | ||
color: #999; | ||
} | ||
.sponsor-item img { | ||
width: 100%; | ||
max-width: calc(var(--max-width) - 30px); | ||
max-height: calc(var(--max-width) / 2 - 20px); | ||
margin: 10px 20px; | ||
} | ||
.special .sponsor-item { | ||
height: 160px; | ||
} | ||
.special .sponsor-item img { | ||
max-width: 300px; | ||
max-height: 150px; | ||
} | ||
/* aside mode (on content pages) */ | ||
.sponsor-container.platinum.aside { | ||
--max-width: 200px; | ||
} | ||
.sponsor-container.gold.aside { | ||
--max-width: 124px; | ||
} | ||
.aside .sponsor-item { | ||
margin: 0; | ||
} | ||
</style> |
This file contains 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,31 @@ | ||
<script setup lang="ts"> | ||
import SponsorsGroup from './SponsorsGroup.vue' | ||
import { useData } from 'vitepress' | ||
const { frontmatter } = useData() | ||
</script> | ||
|
||
<template> | ||
<div v-if="frontmatter.sponsors !== false"> | ||
<a | ||
class="sponsors-aside-text" | ||
href="https://github.com/sponsors/yyx990803" | ||
target="_blank" | ||
>Sponsors</a | ||
> | ||
<SponsorsGroup tier="platinum" /> | ||
<SponsorsGroup tier="gold" /> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
a.sponsors-aside-text { | ||
color: #999; | ||
display: block; | ||
margin: 3em 0 1em; | ||
font-weight: 700; | ||
font-size: 11px; | ||
text-transform: uppercase; | ||
letter-spacing: 0.4px; | ||
padding-left: 2em; | ||
} | ||
</style> |
This file contains 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 |
---|---|---|
@@ -1,47 +1,14 @@ | ||
import Theme from 'vitepress/theme' | ||
import { h } from 'vue' | ||
import sponsors from './sponsors.json' | ||
import './sponsors.css' | ||
import SponsorsSidebar from './SponsorsSidebar.vue' | ||
import './custom.css' | ||
|
||
export default { | ||
...Theme, | ||
Layout() { | ||
return h(Theme.Layout, null, { | ||
'sidebar-bottom': () => | ||
h('div', { class: 'sponsors sidebar' }, [ | ||
h( | ||
'a', | ||
{ | ||
href: 'https://github.com/sponsors/yyx990803', | ||
target: '_blank', | ||
rel: 'noopener' | ||
}, | ||
[h('span', 'Sponsors')] | ||
), | ||
...sponsors.map(({ href, src, name, id }) => | ||
h( | ||
'a', | ||
{ | ||
href, | ||
target: '_blank', | ||
rel: 'noopener', | ||
'aria-label': 'sponsor-img' | ||
}, | ||
[h('img', { src, alt: name, id: `sponsor-${id}` })] | ||
) | ||
) | ||
]), | ||
'page-top-ads': () => | ||
h('div', { id: 'wwads-container' }, [ | ||
h('div', { | ||
class: 'wwads-cn wwads-vertical', | ||
'data-id': 111, | ||
style: { | ||
maxWidth: '150px' | ||
} | ||
}) | ||
]) | ||
h('div', { class: 'sponsors sidebar' }, [h(SponsorsSidebar)]) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.