Skip to content

Commit

Permalink
Refactor: Removed duplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
anicyne committed Jul 31, 2024
1 parent 3e1de7e commit c1c5385
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { FunctionComponent } from 'react';
import React from 'react';
import { KoliBriAbbr } from '../components/KoliBriAbbr';
import { useDocsPreferredVersion } from '@docusaurus/theme-common';
import { Version } from '../../shares/version';
import { determinateVersionId } from '../shares/version';

const HomepageHeader: FunctionComponent = () => (
<header className="p-8 grid justify-center">
Expand All @@ -26,10 +26,7 @@ const HomepageHeader: FunctionComponent = () => (
);
const HomepageButtons: FunctionComponent = () => {
const docVersion = useDocsPreferredVersion();
const version =
typeof docVersion?.preferredVersion?.name && parseFloat(docVersion?.preferredVersion?.name as Version) < 2
? 'v1'
: 'v2';
const version = determinateVersionId(docVersion);

return (
<div className="grid sm:flex gap-4 justify-center mt-4">
Expand Down
5 changes: 5 additions & 0 deletions src/shares/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type VERSIONS from '../../versions.json';

export type Version = (typeof VERSIONS)[number] & 'current';

export function determinateVersionId(docVersion) {
if (!docVersion || !docVersion.preferredVersion) return null;
return parseFloat(docVersion?.preferredVersion?.name as Version) < 2 ? 'v1' : 'v2';
}
7 changes: 2 additions & 5 deletions src/theme/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { LanguageSwitch } from '@site/src/components/LanguageSwitch';
import Navbar from '@theme-original/Navbar';
import ThemeSelect from './ThemeSelect';
import { useDocsPreferredVersion } from '@docusaurus/theme-common';
import { Version } from '../../shares/version';
import { determinateVersionId } from '../../shares/version';
import { translate } from '@docusaurus/Translate';

export const NavbarWrapper: FunctionComponent<PropsWithChildren> = (props) => {
Expand All @@ -28,10 +28,7 @@ export const NavbarWrapper: FunctionComponent<PropsWithChildren> = (props) => {
// },
// };
const docVersion = useDocsPreferredVersion();
const version =
typeof docVersion?.preferredVersion?.name && parseFloat(docVersion?.preferredVersion?.name as Version) < 2
? 'v1'
: 'v2';
const version = determinateVersionId(docVersion);

return (
<div className="kolibri-navbar-wrapper sticky top-0 z-50 bg-white">
Expand Down

0 comments on commit c1c5385

Please sign in to comment.