fix(migrate): migration CLI should correctly migrate gtag options (#6276)

* fix(migrate): migration CLI should correctly migrate gtag options

* fix
This commit is contained in:
Joshua Chen 2022-01-06 20:39:23 +08:00 committed by GitHub
parent 4efdd33df9
commit 1d957d97e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 37 deletions

View file

@ -43,6 +43,7 @@ module.exports = {
}, },
blog: {}, blog: {},
theme: {}, theme: {},
googleAnalytics: {trackingID: 'UA-44373548-31'},
}, },
], ],
], ],
@ -78,6 +79,5 @@ module.exports = {
indexName: 'docusaurus', indexName: 'docusaurus',
algoliaOptions: {facetFilters: ['language:LANGUAGE', 'version:VERSION']}, algoliaOptions: {facetFilters: ['language:LANGUAGE', 'version:VERSION']},
}, },
gtag: {trackingID: 'UA-44373548-31'},
}, },
}; };

View file

@ -247,6 +247,7 @@ export function createConfigFile({
'enableUpdateBy', 'enableUpdateBy',
'docsSideNavCollapsible', 'docsSideNavCollapsible',
'gaTrackingId', 'gaTrackingId',
'gaGtag',
]; ];
const value = siteConfig[key as keyof typeof siteConfig]; const value = siteConfig[key as keyof typeof siteConfig];
if (value !== undefined && !knownFields.includes(key)) { if (value !== undefined && !knownFields.includes(key)) {
@ -293,6 +294,15 @@ export function createConfigFile({
}, },
blog: {}, blog: {},
theme: {}, theme: {},
...(() => {
if (siteConfig.gaTrackingId) {
if (siteConfig.gaGtag) {
return {gtag: {trackingID: siteConfig.gaTrackingId}};
}
return {googleAnalytics: {trackingID: siteConfig.gaTrackingId}};
}
return undefined;
})(),
}, },
], ],
], ],
@ -351,11 +361,6 @@ export function createConfigFile({
}, },
}, },
algolia: siteConfig.algolia ? siteConfig.algolia : undefined, algolia: siteConfig.algolia ? siteConfig.algolia : undefined,
gtag: siteConfig.gaTrackingId
? {
trackingID: siteConfig.gaTrackingId,
}
: undefined,
}, },
}; };
} }

View file

@ -18,6 +18,8 @@ export type Data = {
export type ClassicPresetEntries = { export type ClassicPresetEntries = {
docs: {[key: string]: unknown}; docs: {[key: string]: unknown};
blog: {[key: string]: unknown}; blog: {[key: string]: unknown};
gtag?: {trackingID: string} | undefined;
googleAnalytics?: {trackingID: string} | undefined;
theme: {[key: string]: unknown}; theme: {[key: string]: unknown};
}; };
@ -51,9 +53,6 @@ export interface VersionTwoConfig {
themes?: []; themes?: [];
presets: [[string, ClassicPresetEntries]]; presets: [[string, ClassicPresetEntries]];
themeConfig: { themeConfig: {
gtag?: {
trackingID?: string;
};
navbar: { navbar: {
title?: string; title?: string;
logo?: { logo?: {
@ -120,6 +119,7 @@ export type VersionOneConfig = {
translationRecruitingLink?: string; translationRecruitingLink?: string;
algolia?: Record<string, unknown>; algolia?: Record<string, unknown>;
gaTrackingId?: string; gaTrackingId?: string;
gaGtag?: boolean;
highlight?: Record<string, unknown>; highlight?: Record<string, unknown>;
markdownPlugins?: Array<() => void>; markdownPlugins?: Array<() => void>;
scripts?: Array<{src: string; [key: string]: unknown} | string>; scripts?: Array<{src: string; [key: string]: unknown} | string>;

View file

@ -363,29 +363,43 @@ module.exports = {
#### `gaTrackingId` {#gatrackingid} #### `gaTrackingId` {#gatrackingid}
```js {5} title="docusaurus.config.js" ```js title="docusaurus.config.js"
module.exports = { module.exports = {
// ... // ...
themeConfig: { presets: [
googleAnalytics: { [
trackingID: 'UA-141789564-1', '@docusaurus/preset-classic',
}, {
// ... // ...
}, // highlight-start
googleAnalytics: {
trackingID: 'UA-141789564-1',
},
// highlight-end
},
],
],
}; };
``` ```
#### `gaGtag` {#gagtag} #### `gaGtag` {#gagtag}
```js {5} title="docusaurus.config.js" ```js title="docusaurus.config.js"
module.exports = { module.exports = {
// ... // ...
themeConfig: { presets: [
gtag: { [
trackingID: 'UA-141789564-1', '@docusaurus/preset-classic',
}, {
// ... // ...
}, // highlight-start
gtag: {
trackingID: 'UA-141789564-1',
},
// highlight-end
},
],
],
}; };
``` ```

View file

@ -363,29 +363,43 @@ module.exports = {
#### `gaTrackingId` {#gatrackingid} #### `gaTrackingId` {#gatrackingid}
```jsx {5} title="docusaurus.config.js" ```js title="docusaurus.config.js"
module.exports = { module.exports = {
// ... // ...
themeConfig: { presets: [
googleAnalytics: { [
trackingID: 'UA-141789564-1', '@docusaurus/preset-classic',
}, {
// ... // ...
}, // highlight-start
googleAnalytics: {
trackingID: 'UA-141789564-1',
},
// highlight-end
},
],
],
}; };
``` ```
#### `gaGtag` {#gagtag} #### `gaGtag` {#gagtag}
```jsx {5} title="docusaurus.config.js" ```js title="docusaurus.config.js"
module.exports = { module.exports = {
// ... // ...
themeConfig: { presets: [
gtag: { [
trackingID: 'UA-141789564-1', '@docusaurus/preset-classic',
}, {
// ... // ...
}, // highlight-start
gtag: {
trackingID: 'UA-141789564-1',
},
// highlight-end
},
],
],
}; };
``` ```