1
0
Эх сурвалжийг харах

feat: add theme switcher trigger (#553)

代强 3 жил өмнө
parent
commit
bcc0fe03be
4 өөрчлөгдсөн 32 нэмэгдсэн , 31 устгасан
  1. 24 24
      gatsby-node.js
  2. 1 1
      package.json
  3. 3 0
      src/html.js
  4. 4 6
      yarn.lock

+ 24 - 24
gatsby-node.js

@@ -10,7 +10,6 @@ const path = require('path');
 const fs = require('fs');
 const processGraphQLData = require('./search/generator');
 const items = ['basic', 'chart'];
- 
 const sha1 = require('sha1');
 const hash = sha1(`${new Date().getTime()}${Math.random()}`);
 const glob = require('glob');
@@ -29,7 +28,7 @@ const addPageDataVersion = async file => {
         fs.writeFileSync(file, result, 'utf8');
     }
 };
- 
+
 function resolve(dir) {
     return path.resolve(__dirname, dir);
 }
@@ -41,7 +40,7 @@ const getLocale = path => {
     }
     return locale;
 };
- 
+
 exports.onCreateWebpackConfig = ({ stage, rules, loaders, plugins, actions }) => {
     const isSSR = stage.includes('html');
     const sassLoader = () => 'sass-loader';
@@ -52,15 +51,15 @@ exports.onCreateWebpackConfig = ({ stage, rules, loaders, plugins, actions }) =>
             ...options,
         },
     });
- 
+
     const semiOptions = { esbuild: true };
     const srcScssModuleUse = [];
     const srcScssUse = [];
     const srcCssUse = [];
     const semiDvScssUse = [];
- 
+
     const semiDvJsxRule = [];
- 
+
     // for semi
     semiOptions.scssUse = [
         loaders.css({
@@ -108,7 +107,7 @@ exports.onCreateWebpackConfig = ({ stage, rules, loaders, plugins, actions }) =>
             }
         );
     }
- 
+
     actions.setWebpackConfig({
         resolve: {
             alias: {
@@ -176,37 +175,39 @@ exports.onCreateWebpackConfig = ({ stage, rules, loaders, plugins, actions }) =>
                 }
             ],
         },
-        plugins: [plugins.extractText()],
+        plugins: [plugins.extractText(),plugins.define({
+            "THEME_SWITCHER_URL":JSON.stringify(process.env['THEME_SWITCHER_URL'])
+        })],
     });
 };
- 
+
 exports.onCreateNode = ({ node, getNode, actions }) => {
     const { createNodeField } = actions;
- 
+
     if (node.internal.type === 'Mdx') {
         const mdxNode = getNode(node.parent);
         const levels = mdxNode.relativePath.split(path.sep);
- 
+
         const locale = getLocale(mdxNode.name);
- 
+
         createNodeField({
             node,
             name: 'slug',
             value: `${locale}/${levels[0]}/${levels[1]}`, // eg: zh-CN/chart/area
         });
- 
+
         createNodeField({
             node,
             name: 'type',
             value: `${levels[0]}`,
         });
- 
+
         createNodeField({
             node,
             name: 'typeOrder',
             value: items.indexOf(levels[0]),
         });
- 
+
         createNodeField({
             node,
             name: 'locale',
@@ -214,18 +215,18 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
         });
     }
 };
- 
+
 exports.onPreBootstrap = ({ Joi }) => {
     let orderFunc = require('./content/order');
     console.log('starting order mdx');
     orderFunc();
 };
- 
+
 exports.createPages = async ({ actions, graphql, reporter }) => {
     const { createPage } = actions;
- 
+
     const blogPostTemplate = path.resolve('src/templates/postTemplate.js');
- 
+
     // 开始处理搜索数据
     // console.log('building search data.');
     const searchData = await graphql(`
@@ -248,7 +249,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
            }
          }
        }`);
- 
+
     // 在此你可以处理searchData(GraphQL查询的raw数据) 或者传入回调 处理运算后的数据
     processGraphQLData(searchData, processedData => {});
     // 搜索有用到,但是目前没有搜索,先注释掉,不然影响文档站的本地调试
@@ -304,7 +305,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
         reporter.panicOnBuild('Error while running GraphQL query.');
         return;
     }
- 
+
     result.data.allMdx.edges.forEach(({ next, previous, node }) => {
         createPage({
             path: node.fields.slug,
@@ -319,12 +320,12 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
         });
     });
 };
- 
+
 exports.onPostBootstrap = async () => {
     const loader = path.join(__dirname, 'node_modules/gatsby/cache-dir/loader.js');
     await addPageDataVersion(loader);
 };
- 
+
 exports.onPostBuild = async () => {
     const publicPath = path.join(__dirname, 'public');
     const htmlAndJSFiles = glob.sync(`${publicPath}/**/*.{html,js}`);
@@ -332,4 +333,3 @@ exports.onPostBuild = async () => {
         await addPageDataVersion(file);
     }
 };
- 

+ 1 - 1
package.json

@@ -40,7 +40,7 @@
   "dependencies": {
     "@douyinfe/semi-site-banner": "0.0.1",
     "@douyinfe/semi-site-doc-style": "0.0.1",
-    "@douyinfe/semi-site-header": "0.0.3",
+    "@douyinfe/semi-site-header": "^0.0.5",
     "@douyinfe/semi-site-markdown-blocks": "0.0.1",
     "@mdx-js/react": "^1.6.22",
     "@svgr/core": "^5.5.0",

+ 3 - 0
src/html.js

@@ -156,6 +156,9 @@ export default function HTML(props) {
                 <meta httpEquiv="x-ua-compatible" content="ie=edge" />
                 <meta name="viewport" content="width=1440, initial-scale=0, shrink-to-fit=no" />
                 <script src="https://lf1-cdn-tos.bytescm.com/goofy/semi_convenience/semi-analyze.js" />
+                {
+                    THEME_SWITCHER_URL?<script src={THEME_SWITCHER_URL}/>:<script src="https://unpkg.byted-static.com/latest/ies/semi-theme-switcher-opensource/dist/semi-theme-switcher.js"/>
+                }
                 <link rel="icon" href="https://lf9-static.semi.design/obj/semi-tos/images/favicon.ico" />
                 <script dangerouslySetInnerHTML={{ __html: `(${darkmodeProcesser.toString()})()` }} />
                 {props.headComponents}

+ 4 - 6
yarn.lock

@@ -1676,10 +1676,10 @@
   resolved "https://registry.npmjs.org/@douyinfe/semi-site-doc-style/-/semi-site-doc-style-0.0.1.tgz#c3c803014218ec00441dac32db9a875f6222ed0b"
   integrity sha512-y7Jc1i9q/O2idfaqckSJvghpt4AboQJgZ4iTEK8UMqjQkyWmb5I/NRzVWjOP9S0LEbJNs76OKfZil7DwsOmY/A==
 
-"@douyinfe/semi-site-header@0.0.3":
-  version "0.0.3"
-  resolved "https://registry.npmjs.org/@douyinfe/semi-site-header/-/semi-site-header-0.0.3.tgz#3cf22161d70101e9191e28738242254601d17e81"
-  integrity sha512-pRDwL701g3KQIueTh5mNg/uUK9JJLUfFzC7g7I8k7MSZ8KxtaqdrNqZkulBJY2Cchd3De7UY1aVi4q8bNp0A4A==
+"@douyinfe/semi-site-header@^0.0.5":
+  version "0.0.5"
+  resolved "https://registry.yarnpkg.com/@douyinfe/semi-site-header/-/semi-site-header-0.0.5.tgz#6cd8c46c88a251774d45e5651f3821a22b12c100"
+  integrity sha512-IynSeUySCwoBkeVImIHRwBgPSspfYCDfTWwvH2tjZKNqGjIGAmbCIqq1hkH10/WXwDDC0tuRDFawG906vnl8tg==
   dependencies:
     "@douyinfe/semi-icons" "2.0.0"
     "@douyinfe/semi-ui" "2.0.0"
@@ -25260,10 +25260,8 @@ watchpack@^1.7.4:
   resolved "https://registry.npmjs.org/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453"
   integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ==
   dependencies:
-    chokidar "^3.4.1"
     graceful-fs "^4.1.2"
     neo-async "^2.5.0"
-    watchpack-chokidar2 "^2.0.1"
   optionalDependencies:
     chokidar "^3.4.1"
     watchpack-chokidar2 "^2.0.1"