Add support for configurable web banner data url
This commit is contained in:
+3
-1
@@ -4,4 +4,6 @@ NUXT_PUBLIC_AUTHOR=John Doe
|
|||||||
NUXT_PUBLIC_SITE_NAME="John's Blog"
|
NUXT_PUBLIC_SITE_NAME="John's Blog"
|
||||||
NUXT_PUBLIC_BUILD_BASE_URL=/
|
NUXT_PUBLIC_BUILD_BASE_URL=/
|
||||||
# Fonts, please preserve last slash
|
# Fonts, please preserve last slash
|
||||||
NUXT_PUBLIC_FONTS_URL=https://fonts.example.com/
|
NUXT_PUBLIC_FONTS_URL=https://fonts.example.com/
|
||||||
|
|
||||||
|
NUXT_PUBLIC_BANNER_DATA_URL=https://example.com/api/web/banner/latest
|
||||||
@@ -21,6 +21,12 @@ const visible = ref(false)
|
|||||||
const STORAGE_KEY_DISMISSED = 'web_banner_dismissed'
|
const STORAGE_KEY_DISMISSED = 'web_banner_dismissed'
|
||||||
const STORAGE_KEY_LAST_ID = 'web_banner_last_id'
|
const STORAGE_KEY_LAST_ID = 'web_banner_last_id'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
dataUrl: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const webBannerDataUrl = props.dataUrl;
|
||||||
|
|
||||||
function getStorageItem(key: string): string | null {
|
function getStorageItem(key: string): string | null {
|
||||||
if (typeof window === 'undefined') return null
|
if (typeof window === 'undefined') return null
|
||||||
return localStorage.getItem(key)
|
return localStorage.getItem(key)
|
||||||
@@ -45,7 +51,7 @@ interface WebBannerData {
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const data = await $fetch<WebBannerData>('https://files.techit.win/files/config/web/banner/tmp/index.json')
|
const data = await $fetch<WebBannerData>(webBannerDataUrl)
|
||||||
|
|
||||||
if (!data) return
|
if (!data) return
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
const dataUrl = config.public.webBannerDataUrl as string;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<WebDismissibleGlobalBanner/>
|
<WebDismissibleGlobalBanner :data-url="dataUrl"/>
|
||||||
<WebHeader/>
|
<WebHeader/>
|
||||||
<slot/>
|
<slot/>
|
||||||
<WebFooter/>
|
<WebFooter/>
|
||||||
|
|||||||
+2
-1
@@ -10,7 +10,8 @@ export default defineNuxtConfig({
|
|||||||
siteAuthor: process?.env?.NUXT_PUBLIC_SITE_AUTHOR,
|
siteAuthor: process?.env?.NUXT_PUBLIC_SITE_AUTHOR,
|
||||||
siteName: process?.env?.NUXT_PUBLIC_SITE_NAME,
|
siteName: process?.env?.NUXT_PUBLIC_SITE_NAME,
|
||||||
twitterUsername: process?.env?.NUXT_PUBLIC_TWITTER_USERNAME,
|
twitterUsername: process?.env?.NUXT_PUBLIC_TWITTER_USERNAME,
|
||||||
fontUrl: process?.env?.NUXT_PUBLIC_FONTS_URL
|
fontUrl: process?.env?.NUXT_PUBLIC_FONTS_URL,
|
||||||
|
webBannerDataUrl: process?.env?.NUXT_PUBLIC_BANNER_DATA_URL
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modules: ['@nuxt/content', '@nuxtjs/sitemap', '@nuxt/image', '@nuxt/icon'],
|
modules: ['@nuxt/content', '@nuxtjs/sitemap', '@nuxt/image', '@nuxt/icon'],
|
||||||
|
|||||||
Reference in New Issue
Block a user