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

jiafengzheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git


The following commit(s) were added to refs/heads/master by this push:
     new e99fba72a75 [feature]add build versions plugin (#94)
e99fba72a75 is described below

commit e99fba72a7583cb702f20e1fa6407dcfe4d5fa72
Author: wangyongfeng <943155...@qq.com>
AuthorDate: Tue Sep 13 16:21:49 2022 +0800

    [feature]add build versions plugin (#94)
    
    
    * add build versions plugin
---
 buildVersions.json                     |  1 +
 config/versions-plugin.js              | 20 +++++++++++++++++
 docusaurus.config.js                   |  2 ++
 package.json                           |  3 ++-
 src/components/VersionsDoc/README.md   | 21 ++++++++++++++++++
 src/components/VersionsDoc/index.tsx   | 39 ++++++++++++++++++++++++++++++++++
 src/components/VersionsDoc/styles.scss | 23 ++++++++++++++++++++
 src/theme/MDXComponents.js             |  9 ++++++++
 8 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/buildVersions.json b/buildVersions.json
new file mode 100644
index 00000000000..0637a088a01
--- /dev/null
+++ b/buildVersions.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/config/versions-plugin.js b/config/versions-plugin.js
new file mode 100644
index 00000000000..401dce76d5c
--- /dev/null
+++ b/config/versions-plugin.js
@@ -0,0 +1,20 @@
+const fs = require('fs-extra')
+
+const filePath = './buildVersions.json' 
+
+async function readVersionsFile () {
+    const content = await fs.readFile(filePath, 'utf-8')
+    const versionData = JSON.parse(content)
+    return versionData
+}
+
+module.exports = function (context, options) {
+    return {
+        name: 'versions-plugin',
+        async contentLoaded({ content, actions }) {
+            const versions = await readVersionsFile()
+            const { setGlobalData } = actions;
+            setGlobalData({ versions });
+        },
+    };
+};
\ No newline at end of file
diff --git a/docusaurus.config.js b/docusaurus.config.js
index 383ca8d7ce6..47fee481130 100644
--- a/docusaurus.config.js
+++ b/docusaurus.config.js
@@ -6,6 +6,7 @@ const lightCodeTheme = 
require('prism-react-renderer/themes/github');
 const showAllVersions = true;
 const { ssrTemplate } = require('./config/ssrTemplate');
 const customDocusaurusPlugin = require('./config/custom-docusaurus-plugin');
+const versionsPlugin = require('./config/versions-plugin')
 
 console.log(process.env);
 
@@ -40,6 +41,7 @@ const config = {
     projectName: 'doris', // Usually your repo name.
     plugins: [
         'docusaurus-plugin-sass',
+        versionsPlugin,
         [
             'content-docs',
             /** @type {import('@docusaurus/plugin-content-docs').Options} */
diff --git a/package.json b/package.json
index 96868b0556f..8222f5262f7 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,8 @@
         "docusaurus": "docusaurus",
         "start": "docusaurus start",
         "start:zh-CN": "docusaurus start --locale zh-CN",
-        "build": "PWA_SERVICE_WORKER_URL=https://doris.apache.org docusaurus 
build",
+        "build": "PWA_SERVICE_WORKER_URL=https://doris.apache.org/sw.js 
docusaurus build",
+        "build:version": "docusaurus set-versions && docusaurus build",
         "swizzle": "docusaurus swizzle",
         "deploy": "docusaurus deploy",
         "clear": "docusaurus clear",
diff --git a/src/components/VersionsDoc/README.md 
b/src/components/VersionsDoc/README.md
new file mode 100644
index 00000000000..3579274b760
--- /dev/null
+++ b/src/components/VersionsDoc/README.md
@@ -0,0 +1,21 @@
+# How to use  `<versions>`
+
+You can wrap a piece of Markdown content using the <versions>, and set the 
version number, like this:
+
+```html
+<versions value="1.1,1.2">
+    This is markdown content...
+</versions>
+```
+> Tips: the value must be a string that split by commas.
+
+Then in our website, the MarkDown content will show the version number to 
which it belongs.
+
+If you want to build a single version docs, you can update buildVersions.json:
+
+```json
+["1.1", "1.2"]
+```
+Then run the build:versions command.
+
+
diff --git a/src/components/VersionsDoc/index.tsx 
b/src/components/VersionsDoc/index.tsx
new file mode 100644
index 00000000000..97e11a60a4d
--- /dev/null
+++ b/src/components/VersionsDoc/index.tsx
@@ -0,0 +1,39 @@
+import React from 'react';
+import clsx from 'clsx';
+import Translate from '@docusaurus/Translate';
+import './styles.scss';
+import { usePluginData } from '@docusaurus/useGlobalData';
+
+
+export default function VersionsDoc(props): JSX.Element {
+    const { children, value = '' } = props;
+    const versionsPluginData: any = usePluginData('versions-plugin');
+    const getBuildVersions = (versionsPluginData): string[] => {
+        if (versionsPluginData) {
+            const versionsData = versionsPluginData.versions;
+            if (Array.isArray(versionsData) && versionsData.length > 0) {
+                return versionsData;
+            }
+        }
+        return []
+    }
+    const isShowVersionContent = (buildVersions: string[]) => {
+        if (!value) return false
+        if (buildVersions.length === 0) return true
+        return buildVersions.some(v => value.includes(v))
+    }
+
+    const buildVersions = getBuildVersions(versionsPluginData)
+    return (
+        <div className={clsx('versions-tag')}>
+            {isShowVersionContent(buildVersions) && (
+                <>
+                    <span className="version-sub">
+                        <Translate id="doc.version">Version</Translate>: 
{value}
+                    </span>
+                    {children}
+                </>
+            )}
+        </div>
+    );
+}
diff --git a/src/components/VersionsDoc/styles.scss 
b/src/components/VersionsDoc/styles.scss
new file mode 100644
index 00000000000..c5724760518
--- /dev/null
+++ b/src/components/VersionsDoc/styles.scss
@@ -0,0 +1,23 @@
+
+.versions-tag {
+    position: relative;
+    &:before {
+        content: '';
+        position: absolute;
+        left: -0.7rem;
+        top: 0.5rem;
+        bottom: 0.5rem;
+        border-left: 2px solid var(--ifm-color-primary);
+        opacity: 0.2;
+    }
+    .version-sub {
+        line-height: 1.4;
+        padding: 4px 12px;
+        font-size: 75%;
+        white-space: nowrap;
+        position: relative;
+        left: -1rem;
+        top: -0.2rem;
+        color: var(--ifm-color-primary);
+    }
+}
\ No newline at end of file
diff --git a/src/theme/MDXComponents.js b/src/theme/MDXComponents.js
new file mode 100644
index 00000000000..e00f3395f98
--- /dev/null
+++ b/src/theme/MDXComponents.js
@@ -0,0 +1,9 @@
+// 导入原映射
+import MDXComponents from '@theme-original/MDXComponents';
+import VersionsDoc from '@site/src/components/VersionsDoc';
+
+export default {
+  // 复用默认的映射
+  ...MDXComponents,
+  versions: VersionsDoc,
+};
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to