Netlify-cms: One repo for multiple websites

Created on 27 Apr 2018  路  12Comments  路  Source: netlify/netlify-cms

I'm interested in using a single Netlify CMS repo accross multiple websites. So for example, having one admin area where content is edited and then it displays across the different websites.

I'm aware of branch subdomains, but my question is - is it possible not to have to merge content from one branch to another - can content be queried from a single source without having to merge branches? If you deploy on a master branch can that content then be displayed on any subdomain branches as part of that deploy?

Thanks.

Most helpful comment

@camsloanftc now it makes sense.

I would handle it by creating a node script that checks an environment variable. Based on the value of the environment variable, the correct command would be executed. The Environment variable would be stored in the site admin console at app.netlify.com and not in the netlify.toml file.

All 12 comments

You can have a single repo with multiple websites, and Netlify CMS can edit any of that content in one instance. You just need separate Netlify sites for each. The trick there is cding into the right directory in each site's build command.

Sent with GitHawk

Ah - that makes sense. How would I go about cding into directories for each site - is that something you set up in the Netlify UI somewhere?

Yep, just edit the build command. Typically it's something like npm run build. If each website directory in your repo has it's own package.json with it's own build script, then in the Netlify site for each, your build command would be cd directory-name && npm run build. Likewise, the "Publish directory" field would need to reflect the right path, probably directory-name/dist.

The downside to doing this with a lot of websites is that every site rebuilds and redeploys when anything changes in the repo.

How about having multiple repositories managed inside one instance of Netlify CMS? That'd be really useful for me at the moment.

@hughrawlinson can you open a separate issue explaining what you're trying to do?

This "cding" is quite hacky, I have to say. I cannot use a more finetuned netlify.toml then, right? This should be handled much better in the future.

The build command for your Netlify site is entered to a bash prompt, so cd is perfectly legit. If there was a special setting in Netlify to set a base directory, it would probably use cd underneath anyway.

This would be quite helpful.

We have a case where we want to deploy our Storybook with a different command than our main website.

The problem is that we also want to use [context.production] to run a different build command for our main site on production vs staging.

Adding this to the netlify.toml currently overrides the command for both sites.

@camsloanftc You can run different commands based on context in the setting of the netlify.toml

# Global settings applied to the whole site.
[build]
  command = "yarn build"
  publish = "public"

# build a preview of the site (Drafts and Future dates also)
[context.deploy-preview]
  command = "yarn build:preview"

# build a staging build for the `staging` branch
[context.staging]
  command = "yarn build:stage"

You can of course use any commands that fit your case

@talves - Yes we are doing that already, but we need to run a different command for our Storybook site, which relies on the same repo. So ideally we would need some way to use the URL of the site to check if it is the storybook url or the main website url, or have the ability to select a different netlify.toml file depending on the site we are building. This may be too much to ask though.

@camsloanftc now it makes sense.

I would handle it by creating a node script that checks an environment variable. Based on the value of the environment variable, the correct command would be executed. The Environment variable would be stored in the site admin console at app.netlify.com and not in the netlify.toml file.

Oh great call I had not thought of that.

Was this page helpful?
0 / 5 - 0 ratings