Skip to content

Commit

Permalink
feat: improve demo scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Jul 21, 2023
1 parent fd52ca1 commit 8325f4c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
17 changes: 1 addition & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,7 @@
name="description"
content="Admin client for Surmon.me powered by Veact and AntDesign"
/>
<!-- Google AdSense -->
<script
async
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4710915636313788"
crossorigin="anonymous"
></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84887611-4"></script>
<script>
window.dataLayer = window.dataLayer || []
function gtag() {
dataLayer.push(arguments)
}
gtag('js', new Date())
gtag('config', 'UA-84887611-4')
</script>
<!-- DEMO_SLOT -->
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/AppLayout/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Icon from '@ant-design/icons'
import { scrollTo } from '@/services/scroller'
import { routeMap } from '@/routes'
import { PageHeaderAD } from './PageAD'
import { ENABLED_AD } from '@/config'

import styles from './style.module.less'

Expand All @@ -28,7 +29,7 @@ export const AppContent: React.FC<React.PropsWithChildren> = (props) => {
))}
</Breadcrumb>
</div>
<PageHeaderAD />
{ENABLED_AD && <PageHeaderAD />}
<div className={styles.pageContent}>{props?.children}</div>
<BackTop className={styles.backTop} onClick={() => scrollTo(document.body)}>
<div className={styles.tigger}>
Expand Down
11 changes: 4 additions & 7 deletions src/components/AppLayout/PageAD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import React from 'react'
import { onMounted, useRef } from 'veact'
import { Button } from 'antd'
import * as Icon from '@ant-design/icons'
import { ENABLED_AD } from '@/config'

import styles from './style.module.less'

export const PageHeaderAD: React.FC = () => {
const isEnabledAD = useRef(Boolean(ENABLED_AD))
const isVisibleAD = useRef(true)
const closeAD = () => {
isEnabledAD.value = false
isVisibleAD.value = false
}

onMounted(() => {
if (isEnabledAD.value) {
;((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({})
}
;((window as any).adsbygoogle = (window as any).adsbygoogle || []).push({})
})

if (isEnabledAD.value) {
if (isVisibleAD.value) {
return (
<div className={styles.appPageHeaderMammon}>
<div className={styles.mammonBox}>
Expand Down
27 changes: 24 additions & 3 deletions vite.config.demo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import { UserConfig } from 'vite'

const DEMO_BASE_PATH = '/veact-admin/'
const GOOGLE_ANALYTICS_MEASUREMENT_ID = 'G-WNSSKPKKMG'
const GOOGLE_ADSENSE_CLIENT_ID = 'ca-pub-4710915636313788'

const DEMO_HACK_SCRIPT = `<script src="${DEMO_BASE_PATH}__demo__/index.js"></script>`

const GOOGLE_ANALYTICS_TAG_SCRIPT = `
<script async src="https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_MEASUREMENT_ID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GOOGLE_ANALYTICS_MEASUREMENT_ID}');
</script>
`

const GOOGLE_ADSENSE_SCRIPT = `
<script
async
crossorigin="anonymous"
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${GOOGLE_ADSENSE_CLIENT_ID}"
></script>
`

export const demoConfiger = (defaultConfig: UserConfig): UserConfig => {
return {
Expand All @@ -13,9 +35,8 @@ export const demoConfiger = (defaultConfig: UserConfig): UserConfig => {
name: 'demo-html-transform',
transformIndexHtml(html) {
return html.replace(
`</head>`,
// append mock entry
`<script src="${DEMO_BASE_PATH}__demo__/index.js"></script></head>`
`<!-- DEMO_SLOT -->`,
[DEMO_HACK_SCRIPT, GOOGLE_ANALYTICS_TAG_SCRIPT, GOOGLE_ADSENSE_SCRIPT].join('\n')
)
}
}
Expand Down

0 comments on commit 8325f4c

Please sign in to comment.