|
| 1 | +# A statically generated blog example using Next.js and Umbraco Heartcore |
| 2 | + |
| 3 | +This example showcases Next.js's [Static Generation](https://nextjs.org/docs/basic-features/pages) feature using [Umbraco Heartcore](https://umbraco.com/heartcore) as the data source. |
| 4 | + |
| 5 | +## Demo |
| 6 | + |
| 7 | +- **Live**: [https://next-blog-umbraco-heartcore.vercel.app/](https://next-blog-umbraco-heartcore.vercel.app/) |
| 8 | +- **Preview Mode**: [https://next-blog-umbraco-heartcore.vercel.app/api/preview...](https://next-blog-umbraco-heartcore.vercel.app/api/preview?secret=ivfgc53v8d8ikh7z4nnd5hzwgs298ma6&slug=/posts/learn-how-to-pre-render-pages-using-static-generation-with-next-js) |
| 9 | + |
| 10 | +## Deploy your own |
| 11 | + |
| 12 | +Once you have access to [the environment variables you'll need](#step-3-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example): |
| 13 | + |
| 14 | +[](https://vercel.com/import/git?c=1&s=https://github.com/vercel/next.js/tree/canary/examples/cms-umbraco-heartcore&env=UMBRACO_PROJECT_ALIAS,UMBRACO_API_KEY,UMBRACO_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20Umbraco%20Heartcore&envLink=https://vercel.link/cms-umbraco-heartcore-env) |
| 15 | + |
| 16 | +### Related examples |
| 17 | + |
| 18 | +- [WordPress](/examples/cms-wordpress) |
| 19 | +- [DatoCMS](/examples/cms-datocms) |
| 20 | +- [Sanity](/examples/cms-sanity) |
| 21 | +- [TakeShape](/examples/cms-takeshape) |
| 22 | +- [Prismic](/examples/cms-prismic) |
| 23 | +- [Contentful](/examples/cms-contentful) |
| 24 | +- [Strapi](/examples/cms-strapi) |
| 25 | +- [Agility CMS](/examples/cms-agilitycms) |
| 26 | +- [Cosmic](/examples/cms-cosmic) |
| 27 | +- [ButterCMS](/examples/cms-buttercms) |
| 28 | +- [Storyblok](/examples/cms-storyblok) |
| 29 | +- [GraphCMS](/examples/cms-graphcms) |
| 30 | +- [Kontent](/examples/cms-kontent) |
| 31 | +- [Ghost](/examples/cms-ghost) |
| 32 | +- [Blog Starter](/examples/blog-starter) |
| 33 | + |
| 34 | +## How to use |
| 35 | + |
| 36 | +Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: |
| 37 | + |
| 38 | +```bash |
| 39 | +npx create-next-app --example cms-umbraco-heartcore cms-umbraco-heartcore-app |
| 40 | +# or |
| 41 | +yarn create next-app --example cms-umbraco-heartcore cms-umbraco-heartcore-app |
| 42 | +``` |
| 43 | + |
| 44 | +## Configuration |
| 45 | + |
| 46 | +### Step 1. Create an account and a project in Umbraco Heartcore |
| 47 | + |
| 48 | +First, [create an account in Umbraco Heartcore](https://umbraco.com/heartcore), this will also create an empty project. |
| 49 | + |
| 50 | +### Step 2. Login into Umbraco Heartcore and install sample data |
| 51 | + |
| 52 | +After your account has been created, you are redirected to the Umbraco Cloud Portal, from here you click on the **Go to backoffice** link and login to your new Umbraco Heartcore project. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +From the dashboard click **Install sample** on the **Blog Starter** sample. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +### Step 3. Set up environment variables |
| 61 | + |
| 62 | +Copy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git): |
| 63 | + |
| 64 | +```bash |
| 65 | +cp .env.local.example .env.local |
| 66 | +``` |
| 67 | + |
| 68 | +Then set each variable in `.env.local`: |
| 69 | + |
| 70 | +- `UMBRACO_PROJECT_ALIAS`: Set it to the project alias, which can be found under **Settings** -> **Headless**. |
| 71 | +- `UMBRACO_API_KEY`: Create a new API Key under **Users > "Your Username" > API Keys**. |
| 72 | +- `UMBRACO_PREVIEW_SECRET` can be any random string (but avoid spaces), like `MY_SECRET` - this is used for [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode). |
| 73 | + |
| 74 | +Your `.env.local` file should look like this: |
| 75 | + |
| 76 | +```bash |
| 77 | +UMBRACO_PROJECT_ALIAS=... |
| 78 | +UMBRACO_API_KEY=... |
| 79 | +UMBRACO_PREVIEW_SECRET=... |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 4. Run Next.js in development mode |
| 83 | + |
| 84 | +```bash |
| 85 | +npm install |
| 86 | +npm run dev |
| 87 | + |
| 88 | +# or |
| 89 | + |
| 90 | +yarn install |
| 91 | +yarn dev |
| 92 | +``` |
| 93 | + |
| 94 | +Your blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/zeit/next.js/discussions). |
| 95 | + |
| 96 | +### Step 5. Try preview mode |
| 97 | + |
| 98 | +Then click save and go back to the **Content** section, click on _Posts_ and then on a post and: |
| 99 | + |
| 100 | +- **Update the title**. For example, you can add `[Draft]` in front of the title. |
| 101 | +- Click **Save**, but **DO NOT** click **Publish**. By doing this, the post will be in the draft state. |
| 102 | + |
| 103 | +Now, if you go to the post page on localhost, you won't see the updated title. However, if you use **Preview Mode**, you'll be able to see the change ([Documentation](/docs/advanced-features/preview-mode.md)). |
| 104 | + |
| 105 | +To enable the Preview Mode, go to this URL: |
| 106 | + |
| 107 | +``` |
| 108 | +http://localhost:3000/api/preview?secret=<secret>&slug=<slug> |
| 109 | +``` |
| 110 | + |
| 111 | +- `<secret>` should be the string you entered for `STRAPI_PREVIEW_SECRET`. |
| 112 | +- `<slug>` should be the post's `url`, which can be found under **Info**. |
| 113 | + |
| 114 | +You should now be able to see the draft post. To exit the preview mode, you can click **Click here to exit preview mode** at the top of the page. |
| 115 | + |
| 116 | +To make it easier to go into **Preview Mode** you can enable a preview button on the posts in the backoffice. |
| 117 | + |
| 118 | +In Umbraco Heartcore, go to **Settings > Headless > Preview**. From here you can add a new Preview Url by clicking the **Add Preview Url** button. |
| 119 | + |
| 120 | +Fill in the form with the following values: |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +- **Root Content**: Select the **Posts** node |
| 125 | +- **Culture**: en-US |
| 126 | +- **Url**: http://localhost:3000/api/preview?secret=YOUR_PREVIEW_SECRET |
| 127 | +- **Name**: Local Test |
| 128 | +- **Path type**: Path in querystring |
| 129 | +- **Querystring parameter nam**: slug |
| 130 | + |
| 131 | +If you go back to one of the posts, you should now see a **Preview** button at the bottom right of the screen next to the **Save** button. If you click it, you should be in **Preview Mode**. |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +### Step 6. Deploy on Vercel |
| 136 | + |
| 137 | +You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
| 138 | + |
| 139 | +#### Deploy Your Local Project |
| 140 | + |
| 141 | +To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example). |
| 142 | + |
| 143 | +**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file. |
| 144 | + |
| 145 | +#### Deploy from Our Template |
| 146 | + |
| 147 | +Alternatively, you can deploy using our template by clicking on the Deploy button below. |
| 148 | + |
| 149 | +[](https://vercel.com/import/git?c=1&s=https://github.com/vercel/next.js/tree/canary/examples/cms-umbraco-heartcore&env=UMBRACO_PROJECT_ALIAS,UMBRACO_API_KEY,UMBRACO_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20Umbraco%20Heartcore&envLink=https://vercel.link/cms-umbraco-heartcore-env) |
0 commit comments