Support baseURL in env file for sitemap generation

This commit is contained in:
Ole Eskild Steensen 2022-12-07 15:37:15 +01:00
parent e61261eaae
commit 4b49875dfa
3 changed files with 7 additions and 3 deletions

View File

@ -22,12 +22,17 @@ module.exports = async() => {
const res = await axios.get(themeUrl);
themeStyle = `<style>${res.data}</style>`;
}
let baseUrl = process.env.SITE_BASE_URL || "";
if(baseUrl && !baseUrl.startsWith("http")){
baseUrl = "https://" + baseUrl;
}
const meta ={
env: process.env.ELEVENTY_ENV,
theme: process.env.THEME,
themeStyle: themeStyle,
baseTheme: process.env.BASE_THEME || "dark",
siteName: process.env.SITE_NAME_HEADER || "Digital Garden",
siteBaseUrl: baseUrl,
};
return meta;

View File

@ -1,6 +1,7 @@
---
permalink: netlify/functions/search/data.json
permalinkBypassOutputDir: true
eleventyExcludeFromCollections: true
---
[{% for post in collections.note %}
{

View File

@ -5,11 +5,9 @@ eleventyExcludeFromCollections: true
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in collections.all %}
{%if page.url !== '/netlify/functions/search/data.json'%}
<url>
<loc>{{ site.url }}{{ page.url | url }}</loc>
<loc>{{ meta.siteBaseUrl }}{{ page.url | url }}</loc>
<lastmod>{{ page.date.toISOString() }}</lastmod>
</url>
{%endif%}
{% endfor %}
</urlset>