Skip to content
Snippets Groups Projects
README.md 5.11 KiB
Newer Older
# Gatsby theme for Onegeo Portal

Julien MARGAIL's avatar
Julien MARGAIL committed
**Note:** To install the developpment environment see bellow "Quick Start :: Developping the gatsby-theme"

---

## Quick Start :: Using the gatsby-theme
Julien MARGAIL's avatar
Julien MARGAIL committed
TODO: review this step - deprecated
Julien MARGAIL's avatar
Julien MARGAIL committed

Julien MARGAIL's avatar
Julien MARGAIL committed
gatsby new portal https://gitlab.com/geofit/gatsby-starter-onegeo.git
Julien MARGAIL's avatar
Julien MARGAIL committed
Config npm to use git.neogeo.fr npm packages for @onegeo-suite namespace (ONEGEO Suite Libs Group Access Token (read-api))
Julien MARGAIL's avatar
Julien MARGAIL committed
npm config set @onegeo-suite:registry https://git.neogeo.fr/api/v4/packages/npm/
Julien MARGAIL's avatar
Julien MARGAIL committed
npm config set -- '//git.neogeo.fr/api/v4/packages/npm/:_authToken' "glpat-Ax2yhvq-vpbcDo8DhsGF"
Julien MARGAIL's avatar
Julien MARGAIL committed
cd portal
npm install @onegeo-suite/gatsby-theme-onegeo
```

Edit `.env` file (from .sample.env)

Then add the theme to your `gatsby-config.js`. We'll use the long-form
here for educational purposes.

```javascript
module.exports = {
            resolve: "@onegeo-suite/gatsby-theme-onegeo",
Rename or delete portal default Starter index page `./src/pages/index.tsx`. Will be replaced by the default index page of the `@onegeo-suite/gatsby-theme-onegeo`

That's it, you can now run your gatsby site using

```shell
gatsby develop
```

Julien MARGAIL's avatar
Julien MARGAIL committed
## Quick Start :: Developping the gatsby-theme

### Requirements

-   VS Code (recommended) (https://code.visualstudio.com/download)
    -   Extensions:
        -   Git Graph [git-graph](https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph)
        -   GitLens — Git supercharged [gitlens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)
        -   Prettier - Code formatter [prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
-   Git (https://git-scm.com/download)

```
git config --global user.name "Sam Smith"
git config --global user.email sam@example.com
```

-   NodeJS npm & yarn (https://nodejs.org/en/download/)

v16.x required  
Recommended : use 'nvm' to manage node versions

```
node -v
npm install -g yarn
```


```
npm install -g gatsby-cli
```

-   TypeScript compiler `tsc`

```
npm i -g typescript
```

Julien MARGAIL's avatar
Julien MARGAIL committed
### Setting environment
Julien MARGAIL's avatar
Julien MARGAIL committed
mkdir myProject
cd myProject

Julien MARGAIL's avatar
Julien MARGAIL committed
git clone git@git.neogeo.fr:onegeo-suite/sites/onegeo-suite-site-portal.git portal
Julien MARGAIL's avatar
Julien MARGAIL committed
cd portal
rm -dRf .git
Julien MARGAIL's avatar
Julien MARGAIL committed
rm -f package-lock.json
Julien MARGAIL's avatar
Julien MARGAIL committed
cd  ..

Julien MARGAIL's avatar
Julien MARGAIL committed
git clone git@git.neogeo.fr:onegeo-suite/libs/gatsby-theme-onegeo.git
Julien MARGAIL's avatar
Julien MARGAIL committed

code .
```

Add a `package.json` file

```json
{
    "name": "gatsby-theme-workspace",
    "private": true,
    "version": "0.0.1",
    "license": "0BSD",
    "scripts": {
        "clean": "yarn workspace portal clean",
        "start": "yarn workspace portal develop",
        "build": "yarn workspace portal build",
        "serve": "yarn workspace portal serve"
    },
    "workspaces": ["portal", "gatsby-theme-onegeo"]
Julien MARGAIL's avatar
Julien MARGAIL committed
```shell
cat << EOF > package.json
{
  "name": "gatsby-theme-workspace",
  "private": true,
  "version": "0.0.1",
  "license": "0BSD",
  "scripts": {
    "clean": "yarn workspace portal clean",
    "start": "yarn workspace portal develop",
    "build": "yarn workspace portal build",
    "serve": "yarn workspace portal serve"
  },
  "workspaces": ["portal", "gatsby-theme-onegeo"]
}
EOF
```

From `portal` folder

Edit portal `.env` file (from .sample.env)
Julien MARGAIL's avatar
Julien MARGAIL committed
cd portal
mv .sample.env .env
nano .env
Julien MARGAIL's avatar
Julien MARGAIL committed
```
Julien MARGAIL's avatar
Julien MARGAIL committed
PF_DOMAIN=
PF_PORT=443
PF_PROTOCOL=https
PF_URL=${PF_PROTOCOL}://${PF_DOMAIN}:${PF_PORT}
Julien MARGAIL's avatar
Julien MARGAIL committed
DIRECTUS_URL=${PF_URL}/directus/
Julien MARGAIL's avatar
Julien MARGAIL committed
DIRECTUS_TOKEN=

OGS_LOGIN_PATH=/login
OGS_EXPLORER_PATH=/explorer

DEV_BASE_URL=
Julien MARGAIL's avatar
Julien MARGAIL committed
TYPESENSE_API_TOKEN=
```

Edit portal `gatsby-config.js` to add theme plugin (uncomment lines)
      resolve: "@onegeo-suite/gatsby-theme-onegeo",
Julien MARGAIL's avatar
Julien MARGAIL committed
Edit portal `tailwind.config.js` to manage TailwindCSS in dev mode (comment & uncomment lines)

```
module.exports = {
  future: {},
  content: [
Julien MARGAIL's avatar
Julien MARGAIL committed
    // dev plugin
    "./../gatsby-*/src/**/*.{js,jsx,ts,tsx}",
    // dev site
    //"./node_modules/@onegeo-suite/**/*.{js,jsx,ts,tsx}",
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
```

Rename or delete portal default Starter index page `./src/pages/index.tsx`. Will be replaced by the default index page of the `@onegeo-suite/gatsby-theme-onegeo` to test components.
Julien MARGAIL's avatar
Julien MARGAIL committed
From project root path `./myProject`
Julien MARGAIL's avatar
Julien MARGAIL committed
npm install
```

Project structure should be like this

```
- ./myProject
  ├─ gatsby-theme-onegeo
  |  ├─ src
  |  ├─ ...
  |  └─ package.json
  ├─ node_modules
  ├─ portal
  |  ├─ node_modules
  |  ├─ src
  |  ├─ ...
  |  ├─ .env
  |  ├─ gatsby-config.js
  |  └─ package.json
  ├─ package-lock.json
  └─ package.json
Julien MARGAIL's avatar
Julien MARGAIL committed
Sometimes you may need to clean gatsby cache with

```shell
npm run clean
```

Building npm package (cf. CI/CD) ...

## Doing more with themes

You can use this as a place to start when developing themes. I
generally suggest using [yarn
workspaces](https://yarnpkg.com/lang/en/docs/workspaces/) like the
[gatsby-theme-examples repo
does](https://github.com/ChristopherBiscardi/gatsby-theme-examples),
but using `yarn link` or `npm link` is a viable alternative if you're
not familiar with workspaces.