Skip to content

Commit

Permalink
feat: add version component into footer.
Browse files Browse the repository at this point in the history
  • Loading branch information
riccox committed Oct 10, 2024
1 parent 650ad4d commit 168c1e3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/components/Footer/Version.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FC } from 'react';
import { useTranslation } from 'react-i18next';

declare const __GIT_HASH__: string;

export const Version: FC = () => {
const { t } = useTranslation();
const gitHash = __GIT_HASH__ || 'unknown';

return (
<span>
{t('common:version')}: {gitHash.slice(0, 7)}
</span>
);
};
4 changes: 3 additions & 1 deletion src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FC } from 'react';
import { Copyright } from '@/components/Footer/Copyright';
import { LangSelector } from '../lang';
import { Version } from './Version';

interface Props {
className?: string;
Expand All @@ -9,7 +10,8 @@ interface Props {
export const Footer: FC<Props> = ({ className = '' }) => {
return (
<div className={`${className} gap-x-2 flex justify-center w-full text-neutral-400 text-xs`}>
<Copyright />-
<Copyright /> -
<Version /> -
<a className={`hover:underline`} href={`//github.com/riccox/meilisearch-ui`} target="_blank" rel="noreferrer">
Github
</a>
Expand Down
9 changes: 5 additions & 4 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"empty": "Empty!",
"or": "OR",
"empty": "Empty",
"or": "or",
"unknown": "Unknown",
"uploading": "Uploading",
"search": "Search",
Expand Down Expand Up @@ -30,11 +30,12 @@
"created_at": "Created At",
"updated_at": "Updated At",
"expired_at": "Expired At",
"learn_more": "Learn more",
"learn_more": "Learn More",
"type": "Type",
"status": "Status",
"dashboard": "Dashboard",
"version": "Version",
"toast": {
"fail": "Fail, {{msg}}"
"fail": "Failed, {{msg}}"
}
}
1 change: 1 addition & 0 deletions src/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"type": "类型",
"status": "状态",
"dashboard": "仪表盘",
"version": "版本",
"toast": {
"fail": "失败, {{msg}}"
}
Expand Down
19 changes: 18 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
// vite.config.ts
import { defineConfig, loadEnv } from 'vite';
import { defineConfig, loadEnv, Plugin } from 'vite';
import path from 'path';
import react from '@vitejs/plugin-react-swc';
import { TanStackRouterVite } from '@tanstack/router-vite-plugin';
import tsconfigPaths from 'vite-tsconfig-paths';
import SemiPlugin from './src/lib/semi';
import UnoCSS from 'unocss/vite';
import { execSync } from 'child_process';

// 创建一个插件来注入 Git hash
function gitHashPlugin(): Plugin {
return {
name: 'git-hash-plugin',
config: (config) => {
const hash = execSync('git rev-parse HEAD').toString().trim();
return {
define: {
__GIT_HASH__: JSON.stringify(hash),
},
};
},
};
}

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
Expand All @@ -20,6 +36,7 @@ export default defineConfig(({ mode }) => {
SemiPlugin({
theme: '@semi-bot/semi-theme-meilisearch',
}),
gitHashPlugin(), // 添加我们的新插件
],
resolve: {
alias: {
Expand Down

0 comments on commit 168c1e3

Please sign in to comment.