2019-07-31 13:40:36 +09:00
# Contribution Guide
2020-07-31 12:00:26 +09:00
## Setup
2019-07-31 13:40:36 +09:00
2021-10-27 16:26:29 +09:00
Install `vercel` :
2019-07-31 13:40:36 +09:00
```
2020-06-19 16:15:53 +09:00
npm i -g vercel
2019-07-31 13:40:36 +09:00
```
2021-10-27 16:26:29 +09:00
then install deps and fire up a dev server.
2019-07-31 13:40:36 +09:00
```
yarn install
2020-06-19 16:15:53 +09:00
vc dev
2019-07-31 13:40:36 +09:00
```
2022-03-10 02:57:58 +09:00
Run tests before creating a pull request:
```
yarn test
```
2020-07-31 12:00:26 +09:00
## Adding new provider
2019-07-31 13:40:36 +09:00
2021-10-27 16:26:29 +09:00
Create `src/components/cards/providers/<NewCard>.tsx` . Here is the example card for checking GitHub namespaces.
2019-07-31 13:40:36 +09:00
2020-07-31 12:00:26 +09:00
```tsx
2019-12-24 01:57:07 +09:00
import React from 'react';
2020-07-19 13:39:03 +09:00
import { useTranslation } from 'react-i18next';
import { FaGithub } from 'react-icons/fa';
2019-07-31 13:40:36 +09:00
2020-07-19 13:39:03 +09:00
import { Card, Repeater, DedicatedAvailability } from '../core';
2019-08-06 01:17:45 +09:00
2020-07-19 13:39:03 +09:00
const GithubCard: React.FC< { query: string }> = ({ name }) => {
const { t } = useTranslation();
2019-12-24 01:57:07 +09:00
const lowerCase = name.toLowerCase();
2019-08-06 01:17:45 +09:00
2019-12-24 01:57:07 +09:00
const names = [name];
2019-08-06 01:17:45 +09:00
const moreNames = [
`${lowerCase}hq` ,
`${lowerCase}-team` ,
`${lowerCase}-org` ,
`${lowerCase}-js` ,
2019-12-24 01:57:07 +09:00
];
2019-07-31 13:40:36 +09:00
return (
2019-08-06 01:17:45 +09:00
< Card title = {t('providers.github')} >
< Repeater items = {names} moreItems = {moreNames} >
{(name) => (
< DedicatedAvailability
name={name}
2021-10-27 16:26:29 +09:00
service="github" // route to http://namae.dev/api/services/github/< query > which is /api/services/github/[query].ts on GitHub
2019-08-06 01:17:45 +09:00
link={`https://github.com/${name}` }
prefix="github.com/"
icon={< FaGithub / > }
/>
)}
< / Repeater >
2019-07-31 13:40:36 +09:00
< / Card >
2019-12-24 01:57:07 +09:00
);
2020-07-19 13:39:03 +09:00
};
2019-07-31 13:40:36 +09:00
```
2020-07-19 13:39:03 +09:00
and add the card to `src/components/cards/index.tsx` :
2019-07-31 13:57:48 +09:00
```jsx
2020-07-19 13:39:03 +09:00
import NewCard from './providers/NewCard';
2019-07-31 13:57:48 +09:00
```
2019-07-31 14:00:04 +09:00
```patch
2020-07-19 13:39:03 +09:00
< >
2019-08-06 01:17:45 +09:00
< Cards >
2019-07-31 13:57:48 +09:00
< GithubCard name = {query} / >
< DomainCard name = {query} / >
< TwitterCard name = {query} / >
< HomebrewCard name = {query} / >
< NpmCard name = {query} / >
< PypiCard name = {query} / >
< CratesioCard name = {query} / >
< JsOrgCard name = {query} / >
< SlackCard name = {query} / >
< S3Card name = {query} / >
2019-07-31 14:00:04 +09:00
+ < NewCard name = {query} / >
2019-08-06 01:17:45 +09:00
< / Cards >
2020-07-19 13:39:03 +09:00
< />
2019-07-31 13:57:48 +09:00
```
2019-07-31 13:40:36 +09:00
### ExistentialAvailability
`ExistentialAvailability` check if the response from passed URL returns `404` or not.
2021-10-27 16:26:29 +09:00
For example, `<ExistentialAvailability target="https://formulae.brew.sh/api/formula/git.json" />` will send a request to `target` and see if it returns with 404. For security reasons, `target` must send back `Access-Control-Allow-Origin: *` header for bridging across cross-site requests. If they don't support `Access-Control-Allow-Origin` , you might want to use `DedicatedAvailability` for server-side handling.
2019-07-31 13:40:36 +09:00
### DedicatedAvailability
`DedicatedAvailability` is for interacting with defined API endpoint to check availability.
2021-10-27 16:26:29 +09:00
For example, `<DedicatedAvailability service="<service>" />` will send a request to `https://namae.dev/availability/<service>/<query>` which is routed to `/api/services/<service>.js` .
2020-07-31 12:00:26 +09:00
2021-10-27 16:26:29 +09:00
## Adding a new language
2020-07-31 12:00:26 +09:00
Suppose we'll add a support for Esperanto.
```bash
cd public/locales
cp -r en eo
# edit eo/translation.json
```
then edit `src/util/i18n.ts` :
```patch
- const TRANSLATION_VERSION = '2';
+ const TRANSLATION_VERSION = '3';
i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
backend: {
backends: [LocalStorageBackend, XHR],
backendOptions: [
{
versions: {
en: TRANSLATION_VERSION,
ja: TRANSLATION_VERSION,
'zh-Hans': TRANSLATION_VERSION,
'zh-Hant': TRANSLATION_VERSION,
+ eo: TRANSLATION_VERSION,
},
},
],
},
fallbackLng: 'en',
debug: false,
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
});
```