Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/zett-8/gatsby-multilingual-blog

Multilingual blog starter
https://github.com/zett-8/gatsby-multilingual-blog

blog-starter gatsby gatsby-starter i18n multilingual styled-components typescript

Last synced: about 2 months ago
JSON representation

Multilingual blog starter

Awesome Lists containing this project

README

        


Gatsby's multilingual blog starter

Kick off your project with this boilerplate. This starter ships with the several configuration files you might need to get up and running blazing fast app.

## ๐Ÿ–ฅ๏ธ Minimum starter with some setup

- Typescript
- Styled-component
- i18n
- PWA (optional)
- Testing (Jest)

## ๐Ÿ‘€ Demo

[Demo Site](https://gatsby-multilingual-blog.netlify.app/)

## โœ… Status

[![Build test](https://github.com/zett-8/gatsby-multilingual-blog/actions/workflows/build-test.yml/badge.svg)](https://github.com/zett-8/gatsby-multilingual-blog/actions/workflows/build-test.yml)ใ€€
[![Netlify Status](https://api.netlify.com/api/v1/badges/5e416975-85a6-4d39-bd1a-282f9d0666ca/deploy-status)](https://app.netlify.com/sites/gatsby-multilingual-blog/deploys)

## ๐Ÿ’ฏ Lighthouse Performance

![performance](./src/images/performance.png)

## ๐Ÿš€ Quick start

1. **Create a Gatsby site.**

Use the Gatsby CLI to create a new site, specifying this repo.

```shell
gatsby new https://github.com/Zett-8/unbearable-lightness.git
```

1. **Start developing.**

Navigate into your new siteโ€™s directory and start it up.

```shell
cd /
gatsby develop
```

1. **Check on browser**

The site is now running at `http://localhost:8000`

_Note: You'll also see a second link: _`http://localhost:8000/___graphql`_. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql)._

## ๐Ÿ‡บ๐Ÿ‡ณ Set available languages

1. **Edit i18nLanguages.ts**

Set available languages and default language. They are automatically applied in the project.

```typescript
// i18nLanguages.ts

export const i18nLanguages: string[] = [`en`, `ja`]
export const i18nDefaultLanguage: string = `en`
```

2. **Write Translations for each language**

Translations should be { key:value } format. It can be deeply nested if necessary.

```typescript
// locales/index.ts

const translations = {
index: {
description: {
en: `Hello world. This is Multilingual Blog. you can switch languages clicking the top-right button.`,
ja: `ใƒใƒญใƒผใƒฏใƒผใƒซใƒ‰ใ€‚ใ“ใ‚Œใฏๅคš่จ€่ชžๅฏพๅฟœใƒ–ใƒญใ‚ฐใงใ™ใ€‚ๅณไธŠใฎใƒœใ‚ฟใƒณใง่จ€่ชžใ‚’ใ‚นใ‚คใƒƒใƒใ™ใ‚‹ใ“ใจใŒๅฏ่ƒฝใงใ™ใ€‚`,
},
},
}
```

3. **Generate translation.json**

Usually you need to make translation.json file for each language in locales folder. But in this project, all you need to do is just run command `yarn i18n`

```shell
yarn i18n
```

## ๐Ÿ–ผ๏ธ How to write article

1. **Folder and naming**

The article should be placed in

```
/contents////.md
```

Gatsby will automatically retrieve all markdown files on build time and make the path for each article as `//_/`.

2. **Image ratio and size**

All Images are displayed with 16 / 9 ratio. The size should be bigger than 800 x 450 px.

## ๐Ÿ—๏ธ Component architecture

A component file consists of five layers.

1. Import layer
2. Type layer
3. Component layer (Should be stateless. Only concerned rendering.)
4. Style layer
5. Container layer (Able to have state and logic.)

```tsx
/** 1. Import layer **/
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { ChildComponent } from './child-component'

/** 2. Type layer **/
type ContainerProps = {
className?: string
}

type ComponentProps = {
className?: string
someData: any
}

/** 3. Component layer **/
const Component = ({ className, someData }: ComponentProps) => (




)

/** 4. Style layer **/
const StyledComponent = styled(Component)`
width: 100%;
margin: 16px;

font-size: 2rem;
`

/** 5. Container layer **/
export const MyComponent = (props: ContainerProps) => {
const [yourState, setYourState] = useState('')

useEffect(() => {
// do something here
}, [])

return
}
```

## ๐Ÿ“ What's inside?

A quick look at files and directories you'll see in this project.

.
โ”œโ”€โ”€ .github
โ”œโ”€โ”€ __mocks__
โ”œโ”€โ”€ contents
โ”œโ”€โ”€ locales
โ”œโ”€โ”€ src
โ”‚ โ”œโ”€โ”€ components
โ”‚ โ”œโ”€โ”€ images
โ”‚ โ”œโ”€โ”€ pages
โ”‚ โ”œโ”€โ”€ providers
โ”‚ โ”œโ”€โ”€ styled
โ”‚ โ””โ”€โ”€ templates
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .prettierignore
โ”œโ”€โ”€ .prettierrc
โ”œโ”€โ”€ gatsby-browser.ts
โ”œโ”€โ”€ gatsby-config.ts
โ”œโ”€โ”€ gatsby-node.ts
โ”œโ”€โ”€ gatsby-ssr.ts
โ”œโ”€โ”€ gatsby-wrapper.tsx
โ”œโ”€โ”€ i18nLanguages.ts
โ”œโ”€โ”€ jest.config.js
โ”œโ”€โ”€ jest-preprocess.js
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ loadershim.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ setup-test-env.js
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ yarn.lock

## ๐ŸŽ“ Learning Gatsby

Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.org/). Here are some places to start:

- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.

- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar.