You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by ti...@apache.org on 2023/04/19 06:32:21 UTC

[incubator-kvrocks-website] branch main updated: refactor: improve static assets url in dev env (#92)

This is an automated email from the ASF dual-hosted git repository.

tison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks-website.git


The following commit(s) were added to refs/heads/main by this push:
     new f519e60  refactor: improve static assets url in dev env (#92)
f519e60 is described below

commit f519e6017151116184fd2734e922a8a47153e88e
Author: tison <wa...@gmail.com>
AuthorDate: Wed Apr 19 14:32:17 2023 +0800

    refactor: improve static assets url in dev env (#92)
    
    Signed-off-by: tison <wa...@gmail.com>
---
 src/cdn.ts                                |  13 +++++++++++++
 src/components/HomepageFeatures/index.tsx |  10 +++++-----
 src/constants.ts                          |   3 ---
 src/pages/index.tsx                       |   6 ++----
 static/img/feature-0.png                  | Bin 230841 -> 0 bytes
 static/img/{mainPic.png => hero.png}      | Bin
 6 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/cdn.ts b/src/cdn.ts
new file mode 100644
index 0000000..5c8af3a
--- /dev/null
+++ b/src/cdn.ts
@@ -0,0 +1,13 @@
+export function resolveStaticAssetsURL(path: string) {
+    if (!path.startsWith('/')) {
+        path = '/' + path;
+    }
+
+    if (process.env.NODE_ENV === 'development') {
+        return path;
+    }
+
+    // The DNS for cdn.jsdelivr.net and fastly.jsdelivr.net cannot be accessed from some regions.
+    // For now, gcore.jsdelivr.net is still accessible, but its future availability is uncertain.
+    return 'https://gcore.jsdelivr.net/gh/apache/incubator-kvrocks-website@main/static' + path;
+}
diff --git a/src/components/HomepageFeatures/index.tsx b/src/components/HomepageFeatures/index.tsx
index 2495362..cfaf602 100644
--- a/src/components/HomepageFeatures/index.tsx
+++ b/src/components/HomepageFeatures/index.tsx
@@ -1,13 +1,13 @@
 import React from 'react';
 import clsx from 'clsx';
 import styles from './styles.module.css';
-import { IMG_CDN_URL_PREFIX } from '../../constants';
+import {resolveStaticAssetsURL} from "@site/src/cdn";
 
 const imagePaths = {
-  namespace: IMG_CDN_URL_PREFIX + 'namespace.png',
-  cluster: IMG_CDN_URL_PREFIX + 'cluster.png',
-  highAvailable: IMG_CDN_URL_PREFIX + 'high-available.png',
-  replication: IMG_CDN_URL_PREFIX + 'replication.png',
+  namespace: resolveStaticAssetsURL('img/namespace.png'),
+  cluster: resolveStaticAssetsURL('img/cluster.png'),
+  highAvailable: resolveStaticAssetsURL('img/high-available.png'),
+  replication: resolveStaticAssetsURL('img/replication.png'),
 };
 
 type FeatureItem = {
diff --git a/src/constants.ts b/src/constants.ts
deleted file mode 100644
index eb56ed8..0000000
--- a/src/constants.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// The DNS for cdn.jsdelivr.net and fastly.jsdelivr.net have been polluted by the GFW. 
-// For now, gcore.jsdelivr.net is still accessible, but its future availability is uncertain. 
-export const IMG_CDN_URL_PREFIX = 'https://gcore.jsdelivr.net/gh/apache/incubator-kvrocks-website@main/static/img/';
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 1a5fcd4..ff22335 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -6,9 +6,7 @@ import Layout from '@theme/Layout';
 import HomepageFeatures from '@site/src/components/HomepageFeatures';
 
 import styles from './index.module.css';
-import { IMG_CDN_URL_PREFIX } from '../constants';
-
-const mainPic = IMG_CDN_URL_PREFIX + 'mainPic.png';
+import {resolveStaticAssetsURL} from "@site/src/cdn";
 
 function HomepageHeader() {
   const {siteConfig} = useDocusaurusContext();
@@ -21,7 +19,7 @@ function HomepageHeader() {
           <div className={clsx('hero__subtitle',styles.tagline)}>{siteConfig.tagline}</div>
         </div>
         <div className={clsx(styles.image)}>
-          <img src={mainPic} />
+          <img src={resolveStaticAssetsURL('img/hero.png')}  alt="hero banner picture"/>
         </div>
       </div>
       <div className={styles.buttons}>
diff --git a/static/img/feature-0.png b/static/img/feature-0.png
deleted file mode 100644
index 06cd28f..0000000
Binary files a/static/img/feature-0.png and /dev/null differ
diff --git a/static/img/mainPic.png b/static/img/hero.png
similarity index 100%
rename from static/img/mainPic.png
rename to static/img/hero.png