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

89 lines
2.4 KiB
Markdown
Raw Normal View History

2019-07-31 13:40:36 +09:00
# Contribution Guide
## Setup environment
2019-07-31 13:57:48 +09:00
Install `now` for development server:
2019-07-31 13:40:36 +09:00
```
yarn global add now
```
then install deps and fire up dev server.
```
yarn install
yarn start
```
## Add new provider
2019-07-31 13:57:48 +09:00
Create `web/src/components/cards/<NewCard>.js` and paste following template into it:
2019-07-31 13:40:36 +09:00
```jsx
import React from 'react'
import { FaGithub } from 'react-icons/fa'
import { Card } from '../Card'
2019-07-31 13:57:48 +09:00
import { ExistentialAvailability } from '../Availability'
2019-07-31 13:40:36 +09:00
import { capitalize } from '../../util/text'
2019-07-31 13:57:48 +09:00
export default function NewCard({ name }) {
2019-07-31 13:40:36 +09:00
return (
<Card
2019-07-31 13:57:48 +09:00
title="NewCard"
2019-07-31 13:40:36 +09:00
key={name}
nameList={[name, `${name}-team`]}
alternativeList={[`${capitalize(name)}HQ`]}>
{(name) => (
2019-07-31 13:57:48 +09:00
<ExistentialAvailability
2019-07-31 13:40:36 +09:00
name={name}
2019-07-31 13:57:48 +09:00
target={`https://api.newservice.com/items/${name}`}
link={`https://newservice.com/${name}`}
prefix="newservice.com/"
2019-07-31 13:40:36 +09:00
icon={<FaGithub />}
/>
)}
</Card>
)
}
```
2019-07-31 13:57:48 +09:00
and add the card to `/web/src/App.js`:
```jsx
import NewCard from './components/cards/NewCard'
```
```jsx
<Cards>
<CardHeader>Result for {query}</CardHeader>
<CardContainer>
<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} />
<NewCard name={query} />
</CardContainer>
</Cards>
```
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.
```
```