global-water-watch / global-water-watch-website

Global Water Watch website
https://www.globalwaterwatch.io/
2 stars 0 forks source link

Global Water Watch Website

Website

Getting started

This project requires Node.js and Yarn to be installed. To get started:

# create env file, and set the variables
cp .env.example .env

# install dependencies
yarn

Ask a team member how to obtain the required env variables.

See available scripts (like yarn dev) below.

Architecture

The site is created as lightweight isomorphic website connected to a headless CMS, so that it can grow from a landing page to a full-fledged site including a geo app. The setup includes:

Directory structure

This package uses Nuxt's default directory structure. A component's file (*.vue) and optional data structure (*.fragment.graphql) are bundled in a directory with the name of the component. Pages typically also have an adjoining *.query.graphql file for data loading.

src/
  assets/icons/
  components/
    Example/
      index.js
      Example.vue
      Example.fragment.graphql

  pages/
    _param/
      index.vue
      index.query.graphql

  static/
    fonts/
    images/

CMS data loading

The Nuxt app is connected to the CMS via the DatoCMS GraphQL API. To make data loading simple, this project uses graphql-loader, a custom $datocms plugin for data fetching and live previews. Together these enable us to put *.query.graphql files next to our page templates (*.vue), load them directly and use the helper to fetch the data:

<template>
  <div>
    <h1>{{ page.title }}</h1>
    <DatocmsImage :data="page.image.responsiveImage" />
  </div>
</template>

<script>
import query from './index.query.graphql'

export default {
  async asyncData ({ $datocms, $preview }) {
    const { page } = await $datocms.fetchData({ query, preview: !!$preview })
    return { page }
  },
  head () {
    return this.$datocms.toHead(this.page.seo)
  },
  mounted () {
    if (this.$nuxt.isPreview) {
      this.$datocms.subscribeToData({
        query,
        onData: ({ page }) => { this.page = page },
      })
    }
  },
}
</script>

Where a simple index.query.graphql could look like:

#import '../components/ResponsiveImage/ResponsiveImage.fragment.graphql'

query ExampleQuery($locale: SiteLocale) {
  page: examplePage(locale: $locale) {
    title
    seo: _seoMetaTags { attributes, content, tag }
    image {
        responsiveImage(
          imgixParams: { fit: crop, w: 300, h: 300, auto: format }
        ) {
          ...responsiveImageFragment
        }
      }
  }
}

Preview mode

Finally you can view unpublished content by enabling preview mode. Navigate to /?preview=true&secret={PREVIEW_MODE_SECRET} or follow preview links from the CMS to enable it.

Scripts

yarn ... task
dev starts development server on localhost:4999 (is "GWWW" in "T9")
dev:netlify starts development server in Netlify setup on localhost:4999, more realistic, less DX, helpful for testing (edge) functions
analyze analyzes and visualizes output bundles
build creates optimised production build
start starts local server to test production build

Release to production

Follow these steps in order to release a new version to production:

  1. Make a new pull request to merge development into main
  2. Use the preview to check that everything works correctly in the new version
  3. Merge the pull request
  4. Draft a new release
    1. Set main as the target
    2. Create a new tag by increasing the version number
    3. Set the release title to "Release ${version}"
    4. Automatically generate release notes
    5. Publish the release
  5. Congrats! Check Netlify for updates on the deploy process