-
I'm new to 11ty and am integrating Netlify CMS atm. The best I could come up with was to change The end result should just be that I don't have to remember to switch out settings in the config whenever I deploy :) For example: ---
permalink: /admin/config.yml
eleventyExcludeFromCollections: true
hide_from_sitemap: true
---
backend:
site_url: {{ site.url }}
display_url: {{ site.url }}
branch: master # optional, defaults to master
{% if helpers.environment === 'development' %}
name: proxy
local_backend: true
proxy_url: http://localhost:9090/api/v1
{% else %}
name: git-gateway
publish_mode: editorial_workflow
{% endif %} This does work, but it makes very hard to write YAML and keep indentation etc. So, is there a better way using 11ty that I'm not seeing here? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Possibly a better way to do this, but what about just putting the config in a JavaScript/JSON object and then convert to YAML to avoid having to think about indenting. // ./src/config.11ty.js
const yaml = require("js-yaml");
class Config {
get data() {
return {
permalink: "/admin/config.yml",
eleventyHideFromCollections: true,
hide_from_sitemap: true,
};
}
async render(data) {
const backend = {
site_url: data.site?.url,
display_url: data.site?.url,
branch: "master",
name: "git-gateway",
publish_mode: "editorial_workflow",
};
// If this is a development build, adjust a few more properties.
if (process.env.ELEVENTY_ENV === "development") {
backend.name = "proxy";
backend.local_backend = true;
backend.proxy_url = "https://localhost:9090/api/v1";
}
return yaml.dump({ backend });
}
}
module.exports = Config; |
Beta Was this translation helpful? Give feedback.
Possibly a better way to do this, but what about just putting the config in a JavaScript/JSON object and then convert to YAML to avoid having to think about indenting.