1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-16 20:20:38 +09:00
namae/CONTRIBUTING.md

92 lines
2.5 KiB
Markdown
Raw Normal View History

2019-07-31 13:40:36 +09:00
# Contribution Guide
## Setup environment
2020-06-19 16:15:53 +09:00
Install `vercel` for development server:
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
```
then install deps and fire up dev server.
```
yarn install
2020-06-19 16:15:53 +09:00
vc dev
2019-07-31 13:40:36 +09:00
```
## Add new provider
2020-06-19 16:15:53 +09:00
Create `src/components/cards/<NewCard>.js`. Here is the example card that checks if spcified repository on GitHub is available.
2019-07-31 13:40:36 +09:00
```jsx
2019-12-24 01:57:07 +09:00
import React from 'react';
import {useTranslation} from 'react-i18next';
import {FaGithub} from 'react-icons/fa';
2019-07-31 13:40:36 +09:00
2019-12-24 01:57:07 +09:00
import {Card, Repeater, DedicatedAvailability} from '../Cards';
2019-08-06 01:17:45 +09:00
2019-12-24 01:57:07 +09:00
export default function GithubCard({name}) {
const {t} = useTranslation();
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}
service="github"
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
);
2019-07-31 13:40:36 +09:00
}
```
2020-06-19 16:15:53 +09:00
and add the card to `src/App.js`:
2019-07-31 13:57:48 +09:00
```jsx
2019-12-24 01:57:07 +09:00
import NewCard from './components/cards/NewCard';
2019-07-31 13:57:48 +09:00
```
2019-07-31 14:00:04 +09:00
```patch
2019-08-06 01:17:45 +09:00
<SearchResult>
<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>
</SearchResult>
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.
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 dedicated response handling.
### DedicatedAvailability
`DedicatedAvailability` is for interacting with defined API endpoint to check availability.
2019-07-31 13:57:48 +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` in the repo.