Refactored ads.txt to use .env file setting.
This commit is contained in:
parent
1a8090adc2
commit
f53200fe10
|
@ -1,2 +1,3 @@
|
||||||
|
GOOGLE_ADSENSE_ADS_TXT="google.com, pub-1234567890abcdef, DIRECT, fedcba9876543210"
|
||||||
GOOGLE_ANALYTICS_GTAG=G-1234567890
|
GOOGLE_ANALYTICS_GTAG=G-1234567890
|
||||||
SITE_URL=http://localhost
|
SITE_URL=http://localhost
|
|
@ -1 +0,0 @@
|
||||||
google.com, pub-8937572456576531, DIRECT, f08c47fec0942fa0
|
|
|
@ -11,11 +11,13 @@ const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
export interface ProcessEnv {
|
export interface ProcessEnv {
|
||||||
|
GOOGLE_ADSENSE_ADS_TXT?: string;
|
||||||
GOOGLE_ANALYTICS_GTAG?: string;
|
GOOGLE_ANALYTICS_GTAG?: string;
|
||||||
SITE_URL?: string;
|
SITE_URL?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
|
GoogleAdsenseAdsTxt: string;
|
||||||
GoogleAnalyticsGTag: string;
|
GoogleAnalyticsGTag: string;
|
||||||
siteUrl: string;
|
siteUrl: string;
|
||||||
}
|
}
|
||||||
|
@ -30,10 +32,12 @@ dotEnvConfig = dotenvExpand.expand({
|
||||||
processEnv: process.env as dotenvExpand.DotenvParseInput
|
processEnv: process.env as dotenvExpand.DotenvParseInput
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getGoogleAnalyticsGtag = () => env.GOOGLE_ANALYTICS_GTAG||'';
|
export const getGoogleAnalyticsGtag = () => (env.GOOGLE_ANALYTICS_GTAG||``).trim();
|
||||||
export const getSiteUrl = () => trimSlashes(env.SITE_URL||'http://localhost');
|
export const getGoogleAdsenseAdsTxt = () => (env.GOOGLE_ADSENSE_ADS_TXT||``).trim()||`google.com, pub-1234567890abcdef, DIRECT, fedcba9876543210`;
|
||||||
|
export const getSiteUrl = () => trimSlashes(env.SITE_URL||`http://localhost`);
|
||||||
|
|
||||||
export const config: Config = {
|
export const config: Config = {
|
||||||
GoogleAnalyticsGTag: getGoogleAnalyticsGtag(),
|
GoogleAnalyticsGTag: getGoogleAnalyticsGtag(),
|
||||||
|
GoogleAdsenseAdsTxt: getGoogleAdsenseAdsTxt(),
|
||||||
siteUrl: getSiteUrl(),
|
siteUrl: getSiteUrl(),
|
||||||
};
|
};
|
||||||
|
|
12
src/pages/ads.txt.ts
Normal file
12
src/pages/ads.txt.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import type { APIRoute } from 'astro';
|
||||||
|
import { config } from "../config";
|
||||||
|
|
||||||
|
const adsTxt = config.GoogleAdsenseAdsTxt;
|
||||||
|
|
||||||
|
export const GET: APIRoute = () => {
|
||||||
|
return new Response(adsTxt, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/plain; charset=utf-8',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user