https://github.com/mitchmac/tina-cloud-starter-april-19
https://github.com/mitchmac/tina-cloud-starter-april-19
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mitchmac/tina-cloud-starter-april-19
- Owner: mitchmac
- Created: 2021-04-19T15:09:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-04-20T17:15:56.000Z (about 5 years ago)
- Last Synced: 2025-10-14T15:44:43.661Z (8 months ago)
- Language: TypeScript
- Homepage: tina-cloud-starter-april-19-git-main-mitchmac.vercel.app
- Size: 8.82 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tina Cloud Starter đĻ
Basic TinaCMS starter based on [Next.js](https://nextjs.org) and [TinaCMS](https://tina.io) that connects to Tina Cloud Content API.

## Project scope:
- Run this project locally using local content within this repository.
- Connect to Tina Cloud to benefit from its GraphQL Content API.
- Deploy the site to visually edit your site.
- Invite collaborators.
## Table of contents
- đ´ [What is this?](#what-is-this)
- đ´ [Fork and Clone](#fork-and-clone-this-repository)
- âŦī¸ [Install](#install)
- đ [Run the project locally](#run-the-project-locally)
- đ [Edit content locally](#edit-content-locally)
- đĻ [Connect to Tina Cloud](#connect-to-tina-cloud)
- âī¸ [Register your local application with Tina Cloud](#register-your-local-application-with-tina-cloud)
- đ [Connect your local project with Tina Cloud](#connect-your-local-project-with-tina-cloud)
- đ [Edit content](#edit-content)
- âŦī¸ [Deploy](#deploy)
- Ⲡ[Vercel](#vercel)
- [Netlify](#netlify)
- đ [Starter structure](#starter-structure)
- đ [Content Modeling](#content-modeling)
- đĄ [Local development workflow tips](#local-development-workflow-tips)
## What is this?
This is a [TinaCMS](https://tina.io)-enabled Next.js app, so you can edit your content on a live page. In this project the Tina file-based CMS is used via GraphQL: it's powered by a schema that _you_ define. It not only serves content from Markdown files in your repository, but it also generates TinaCMS forms for you automatically â¨.
Feel free to read more about [why we built this](). Now, let's get started!
## Fork this repository
Start by **forking** the repositorty and then pull it down to your computer.
## Install
> âšī¸ This project uses `yarn` as a package manager, if `yarn` isn't installed on your machine, open a terminal and run `npm install -g yarn`
Install the project's dependencies:
```
yarn install
```
> â ī¸ If you'd like to use `npm` beware that there is no `package-lock.json` so we can't guarantee the dependencies are the same for you.
## Run the project locally
To run the local development server:
```
yarn dev
```
This command starts the GraphQL server and the Next.js application in development mode. It also regenerates your schema types for TypeScript and GraphQL so changes to your `.tina` config are reflected immediately.
One of the most interesting aspects of the Tina Cloud Content API is that it doesn't actually require anything from the Cloud to work locally. Since Tina is by default a Git-backed CMS, everything can be run from your local filesystem via the CLI.
This is ideal for development workflows and the API is identical to the one used in the cloud, so once you're ready to deploy your application you won't face any challenges there.
Open [`http://localhost:3000`](http://localhost:3000) in your browser.
The default homepage displays some basic content: a page title, a heading, and a button.
Click on the **Raw JSON** link to display the corresponding structured data:
```json
{
"__typename": "Page_Doc_Data",
"title": "Page Title",
"blocks": [
{
"__typename": "BlockHero_Data",
"heading": "Welcome to my website!",
"message": "This is some quality content right here. Here's another bit of text."
},
{
"__typename": "BlockCta_Data",
"text": "Click Me"
}
],
"_body": null
}
```
## Edit content locally
We need to define some local environment variables in order to run the project.
Copy `.env.local.sample` to `.env.local`:
```
cp .env.local.sample .env.local
```
`NEXT_PUBLIC_USE_LOCAL_CLIENT` should be set to `1`, other values can be ignored for now.
Restart your server and visit [`http://localhost:3000/admin`](http://localhost:3000/admin`),
the same page is displayed but you can notice a pencil icon at the bottom left corner.
Click to open Tina's sidebar which displays a form with fields you can edit and see update live on the page.
Since we're working locally, saving results in changes to your local filesystem.
> đ issue: when adding a block and populating its content, that data on your page updates to the wrong block.
> [Watch this issue](https://github.com/tinacms/tinacms/issues/1669).
Read the [folder structure](#folder-structure) section below to learn more about how this site's routing works.
## Connect to Tina Cloud
While the fully-local development workflow is the recommended way for developers to work,
you'll obviously want other editors and collaborators to be able to make changes on a hosted website with authentication.
> âšī¸ Changes from the `/admin` route show up on your home page after your site finishes a rebuild.
## Register your local application with Tina Cloud
1. Visit [auth.tinajs.dev](https://auth.tinajs.dev/register), create an organization, and sign in. Make a note of your orgnization name.
2. Create an app which connects to the GitHub repository you've just forked. Once your app is created, open settings and copy the client ID.
## Connect your local project with Tina Cloud
In the `env.local` file set:
- `NEXT_PUBLIC_USE_LOCAL_CLIENT` to `0`.
- `NEXT_PUBLIC_ORGANIZATION_NAME` to your Tina Cloud organization name
- `NEXT_PUBLIC_TINA_CLIENT_ID` to the Client ID displayed in your Tina Cloud App.
Restart your server and run `yarn dev` again.
Open [`http://localhost:3000/admin`](http://localhost:3000/admin`)

This time a modal asks you to authenticate through Tina Cloud. Upon success, your edits will be sent to the cloud server (and subsequently to GitHub).
#### Edit content
Make some edits through the sidebar and click save.
Changes are saved in your GitHub repository.
Now that Tina Cloud editing is working correctly, we can deploy the site so that other team members can make edits too.
## Deploy
### Vercel
[](https://vercel.com/new/)
Connect to your GitHub repository and set the same environment variables as the ones in your `env.local` file:
```
NEXT_PUBLIC_ORGANIZATION_NAME=
NEXT_PUBLIC_TINA_CLIENT_ID=
```

đ Congratulations, your site is now live!
You can test that everything is configured correctly by navigating to `[your deployment URL]/admin`,
logging in to Tina Cloud, and making some edits. Your changes should be saved to your GitHub repository.
### Netlify
[](https://app.netlify.com/start/)
Connect to your GitHub repository, click on **advanced** to set the same environment variables as the ones in your `env.local` file:

```
NEXT_PUBLIC_ORGANIZATION_NAME=
NEXT_PUBLIC_TINA_CLIENT_ID=
```
Set the **build command** to `yarn build`,
Set the **publish directory**. To `.next/` .
Once you're done, click "Deploy site".
Install the ["Next on Netlify" plugin](https://www.netlify.com/blog/2020/12/07/announcing-one-click-install-next.js-build-plugin-on-netlify/)
in order to take advantage of server-side rendering and Next.js preview features.
Trigger a new deploy for changes to take effect.
You can test that everything is configured correctly by navigating to `[your deployment URL]/admin`,
logging in to Tina Cloud, and making some edits. Your changes should be saved to your GitHub repository.
---
## Starter structure
Tina Cloud Starter is a [Next.js](https://nextjs.org) application. The file-based routing happens through the `pages` directory.
### `pages/[[...slug]].tsx`
This is the only public route for the website, any path you visit will be passed in as arguments to the Content API,
with first value from the path being used as the `section` slug, and everything after that representing the document's path _relative_ to the configured section path. When deploying to a server, these paths are statically generated at build time.
### `pages/admin/[[...slug]].tsx`
This is the route where you are able to edit your content.
It's protected by an authentication layer, so be sure you've set up an account in the **Getting Started** steps above.
It matches the routing pattern seen in `[[...slug]].tsx`.
For example, to edit `http://localhost:3000/posts/hello-world`, visit `http://localhost:3000/admin/posts/hello-world`.
### `components/document-renderer.tsx`
The document renderer component demonstrates the rich development experience gained by using auto-generated types from the Tina CLI.
The `` shows how you can use the provided types to step through the data.
This a great hand-off point to your design system.
It's at this layer where the data-fetching and routing logic has already been handled, and you can focus on the look and feel of your website.
We've provided a few components to get you started, but the idea is to let you run with it yourself, or plug in your favorite design system.
Enjoy!
## Content Modeling
With Tina Cloud there's no need to build forms manually like you would with TinaCMS. Instead, you're required to define a schema which acts as the single source of truth for the shape and structure of your content.
This is set up for you in `./.tina/schema.ts`, let's break down what this function is doing:
```ts
import { defineSchema } from "tina-graphql-gateway-cli";
export default defineSchema({
collections: [
{
label: "Pages",
name: "pages",
path: "content/pages",
templates: [
{
label: "Page",
name: "page",
fields: [
{
type: "text",
label: "Title",
name: "title",
},
],
},
],
},
],
});
```
### `defineSchema`
Be sure this is your default export from this file, we'll validate the schema and build out the GraphQL API with it.
### `collections`
The top-level key in the schema is an array of _collections_, a `collection` informs the API about _where_ to save content. You can see from the example that a `pages` document would be stored in `content/pages`, and it can be the shape of any `template` from the `templates` key.
### `templates`
Templates are responsible for defining the shape of your content, you'll see in the schema for this starter that we use `templates` for `sections` as well as `blocks`.
## Local development workflow tips
### Guided tour
Watch our [walkthrough video](https://www.loom.com/share/e62776f138ec485d81d71c68364857a8) to see on how you can leverage the tooling provided and get the most out of the starter.
### Typescript
A good way to ensure your components match the shape of your data is to leverage the auto-generated TypeScript types.
These are rebuilt when your `.tina` config changes.
### Visual Studio Code
#### GraphQL extension
Tina Cloud generates your GraphQL schema automatically. đĒ
[Install GraphQL extension](https://marketplace.visualstudio.com/items?itemName=GraphQL.vscode-graphql) to benefit from type auto-completion.
#### Forestry Schema extension
[Install Forestry extension](https://marketplace.visualstudio.com/items?itemName=jeffsee55.forestry-schema) to lint your YAML-based content models.
### Explore the GraphQL API
If you have a GraphQL client like [Altair](https://altair.sirmuel.design/) go to `http://localhost:4001/graphql` to learn more about our GraphQL API.