Add support for configurable web banner data url
This commit is contained in:
@@ -5,3 +5,5 @@ NUXT_PUBLIC_SITE_NAME="John's Blog"
|
||||
NUXT_PUBLIC_BUILD_BASE_URL=/
|
||||
# Fonts, please preserve last slash
|
||||
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_LAST_ID = 'web_banner_last_id'
|
||||
|
||||
const props = defineProps<{
|
||||
dataUrl: string;
|
||||
}>();
|
||||
|
||||
const webBannerDataUrl = props.dataUrl;
|
||||
|
||||
function getStorageItem(key: string): string | null {
|
||||
if (typeof window === 'undefined') return null
|
||||
return localStorage.getItem(key)
|
||||
@@ -45,7 +51,7 @@ interface WebBannerData {
|
||||
|
||||
onMounted(async () => {
|
||||
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
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const dataUrl = config.public.webBannerDataUrl as string;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<WebDismissibleGlobalBanner/>
|
||||
<WebDismissibleGlobalBanner :data-url="dataUrl"/>
|
||||
<WebHeader/>
|
||||
<slot/>
|
||||
<WebFooter/>
|
||||
|
||||
+2
-1
@@ -10,7 +10,8 @@ export default defineNuxtConfig({
|
||||
siteAuthor: process?.env?.NUXT_PUBLIC_SITE_AUTHOR,
|
||||
siteName: process?.env?.NUXT_PUBLIC_SITE_NAME,
|
||||
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'],
|
||||
|
||||
Reference in New Issue
Block a user