Skip to content

Commit

Permalink
[add] OS License Filter & Project links
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Mar 2, 2024
1 parent 7fea39b commit c678b57
Show file tree
Hide file tree
Showing 11 changed files with 548 additions and 42 deletions.
66 changes: 66 additions & 0 deletions components/License/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { FeatureAttitude, InfectionRange } from 'license-filter';

import { i18n } from '../../models/Translation';

const { t } = i18n;

type OptionValue = Record<string, { value: number; text: string }[]>;

type LicenseTips = Record<string, { text: string }[]>;

const options: string[] = [
'popularity',
'reuseCondition',
'infectionIntensity',
'jurisdiction',
'patentStatement',
'patentRetaliation',
'enhancedAttribution',
'privacyLoophole',
'marketingEndorsement',
];

export const optionValue = () => {
const optionValue = options.reduce((optionValue, option) => {
optionValue[option] = [
{
value: FeatureAttitude.Undefined,
text: t('feature_attitude_undefined'),
},
{
value: FeatureAttitude.Positive,
text: t('feature_attitude_positive'),
},
{
value: FeatureAttitude.Negative,
text: t('feature_attitude_negative'),
},
];
return optionValue;
}, {} as OptionValue);

optionValue.infectionRange = [
{ value: 0, text: t('infection_range_undefined') },
{ value: InfectionRange.Library, text: t('infection_range_library') },
{ value: InfectionRange.File, text: t('infection_range_file') },
{ value: InfectionRange.Module, text: t('infection_range_module') },
];

return optionValue;
};

export const licenseTips: () => LicenseTips = () => ({
popularity: [
{ text: t('tip_popularity_0') },
{ text: t('tip_popularity_1') },
],
reuseCondition: [{ text: t('tip_reuse_condition') }],
infectionIntensity: [{ text: t('tip_infection_intensity') }],
jurisdiction: [{ text: t('tip_jurisdiction') }],
patentStatement: [{ text: t('tip_patent_statement') }],
patentRetaliation: [{ text: t('tip_patent_retaliation') }],
enhancedAttribution: [{ text: t('tip_enhanced_attribution') }],
privacyLoophole: [{ text: t('tip_privacy_loophole') }],
marketingEndorsement: [{ text: t('tip_marketing_endorsement') }],
infectionRange: [{ text: t('tip_infection_range') }],
});
48 changes: 30 additions & 18 deletions components/MainNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
import { observer } from 'mobx-react';
import dynamic from 'next/dynamic';
import { FC } from 'react';
import { Container, Nav, Navbar } from 'react-bootstrap';
import { Container, Nav, NavDropdown, Navbar } from 'react-bootstrap';

import { API_Host } from '../models/Base';
import { i18n } from '../models/Translation';
import { MainRoutes } from './data';

const { t } = i18n,
LanguageMenu = dynamic(import('./LanguageMenu'), { ssr: false });

const Name = process.env.NEXT_PUBLIC_SITE_NAME || '';

export const MainNavigator: FC = observer(() => (
<Navbar bg="primary" variant="dark" fixed="top" expand="sm" collapseOnSelect>
<Container>
<Navbar.Brand href="/">{Name}</Navbar.Brand>
<Navbar.Brand href="/">{t('open_source_treasure_box')}</Navbar.Brand>

<Navbar.Toggle aria-controls="navbar-inner" />

<Navbar.Collapse id="navbar-inner">
<Nav className="me-auto">
<Nav.Link href="/article">{t('article')}</Nav.Link>

<Nav.Link href="/component">{t('component')}</Nav.Link>

<Nav.Link href="/pagination">{t('pagination')}</Nav.Link>

<Nav.Link href="/scroll-list">{t('scroll_list')}</Nav.Link>

<Nav.Link
target="_blank"
href="https://github.com/idea2app/Next-Bootstrap-TS"
>
{t('source_code')}
</Nav.Link>
{MainRoutes().map(({ title, path, subs }) =>
path ? (
<Nav.Link
key={title}
className="text-nowrap text-center"
href={path}
target={
new URL(path, API_Host).origin !== API_Host ? '_blank' : ''
}
>
{title}
</Nav.Link>
) : (
<NavDropdown key={title} title={title} className="text-center">
{subs?.map(({ title, path }) => (
<NavDropdown.Item
key={title}
href={path}
className="text-center text-xxl-start"
>
{title}
</NavDropdown.Item>
))}
</NavDropdown>
),
)}
</Nav>

<LanguageMenu />
Expand Down
31 changes: 16 additions & 15 deletions components/PageHead.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import { observer } from 'mobx-react';
import Head from 'next/head';
import type { FC, PropsWithChildren } from 'react';

import { i18n } from '../models/Translation';

export type PageHeadProps = PropsWithChildren<{
title?: string;
description?: string;
}>;

const Name = process.env.NEXT_PUBLIC_SITE_NAME,
const { t } = i18n,
Summary = process.env.NEXT_PUBLIC_SITE_SUMMARY;

export const PageHead: FC<PageHeadProps> = ({
title,
description = Summary,
children,
}) => (
<Head>
<title>
{title}
{title && ' - '}
{Name}
</title>
export const PageHead: FC<PageHeadProps> = observer(
({ title, description = Summary, children }) => (
<Head>
<title>
{title}
{title && ' - '}
{t('open_source_treasure_box')}
</title>

{description && <meta name="description" content={description} />}
{description && <meta name="description" content={description} />}

{children}
</Head>
{children}
</Head>
),
);
27 changes: 27 additions & 0 deletions components/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { i18n } from '../models/Translation';

const { t } = i18n;

export interface Link {
title: string;
path?: string;
subs?: Link[];
}

export const MainRoutes: () => Link[] = () => [
{ title: t('license_tool'), path: '/tool/license-filter' },
{
title: `${t('Web_polyfill_CDN')} v1`,
path: 'https://polyfill.kaiyuanshe.cn/',
},
{
title: `${t('Web_polyfill_CDN')} v2`,
path: 'https://polyfiller.kaiyuanshe.cn/',
},
{ title: t('open_source_mirror'), path: 'http://mirror.kaiyuanshe.cn/' },
{ title: 'Git Pager', path: 'https://git-pager.vercel.app/' },
{
title: t('source_code'),
path: 'https://github.com/kaiyuanshe/OSS-toolbox',
},
];
6 changes: 3 additions & 3 deletions models/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { HTTPClient } from 'koajax';
export const isServer = () => typeof window === 'undefined';

const VercelHost = process.env.VERCEL_URL,
GithubToken = process.env.NEXT_PUBLIC_GITHUB_TOKEN;
GithubToken = process.env.GITHUB_TOKEN;

const API_Host = isServer()
export const API_Host = isServer()
? VercelHost
? `https://${VercelHost}`
: 'http://localhost:3000'
Expand All @@ -17,7 +17,7 @@ export const ownClient = new HTTPClient({
});

export const githubClient = new HTTPClient({
baseURI: 'https://api.github.com/',
baseURI: isServer() ? 'https://api.github.com/' : `${API_Host}/api/github/`,
responseType: 'json',
}).use(({ request }, next) => {
if (GithubToken)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"koajax": "^0.9.6",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"license-filter": "^0.2.4",
"lodash": "^4.17.21",
"mobx": "^6.12.0",
"mobx-i18n": "^0.5.0",
Expand Down
Loading

0 comments on commit c678b57

Please sign in to comment.