From 630b36f02da3007f0895bf6fb9e35221991efc79 Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Thu, 15 Dec 2022 20:09:35 +0100 Subject: [PATCH] Base URL environment variable --- pug.config.js | 6 ++++-- tasks/generate_sitemap.js | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pug.config.js b/pug.config.js index 6f2758fc76c..83aa4c87d50 100644 --- a/pug.config.js +++ b/pug.config.js @@ -2,7 +2,9 @@ const helpers = require('./helpers') const IS_DEV = process.env.NODE_ENV === 'development' -const HOST = IS_DEV ? 'localhost:3000' : 'einundzwanzig.space' +const { DEPLOY_PRIME_URL, URL } = process.env +const BASE = DEPLOY_PRIME_URL || URL || 'https://einundzwanzig.space' +const HOST = IS_DEV ? 'http://localhost:3000' : BASE const random = max => Math.floor(Math.random() * Math.floor(max)) const shuffle = arr => { for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * i); const temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; }; return arr } const formatDate = date => (new Date(date)).toISOString().replace(/T.*/, '').split('-').reverse().join('.') @@ -15,7 +17,7 @@ const assetPath = path => { } const assetUrl = (path, protocol = 'https') => { if (IS_DEV && !path.startsWith('http')) protocol = 'http' - const base = path.startsWith('http') ? '' : `${protocol}://${HOST}` + const base = path.startsWith('http') ? '' : HOST let url = `${base}${assetPath(path)}` if (!url.startsWith(`${protocol}:`)) url = url.replace(/^.*:/, `${protocol}:`) return url diff --git a/tasks/generate_sitemap.js b/tasks/generate_sitemap.js index fc4a56d527f..3f222f555ef 100644 --- a/tasks/generate_sitemap.js +++ b/tasks/generate_sitemap.js @@ -3,8 +3,11 @@ const glob = require('glob') const { writeFileSync } = require('fs') const { resolve } = require('path') +const { DEPLOY_PRIME_URL, URL } = process.env +const BASE = DEPLOY_PRIME_URL || URL || 'https://einundzwanzig.space' + const html = glob.sync(resolve(__dirname, '..', `dist/**/*.html`)) -const pages = html.map(file => file.replace(/.*\/dist/, 'https://einundzwanzig.space').replace(/index\.html$/, '')).filter(f => !f.endsWith('/kontakt/') && !f.endsWith('/datenschutz/')) +const pages = html.map(file => file.replace(/.*\/dist/, BASE).replace(/index\.html$/, '')).filter(f => !f.endsWith('/kontakt/') && !f.endsWith('/datenschutz/')) const now = (new Date()).toISOString() const file = resolve(__dirname, '..', `src/sitemap.pug`) const rendered = pug.renderFile(file, { pages, now, pretty: true })