summaryrefslogtreecommitdiffstats
path: root/netlify-preview.js
diff options
context:
space:
mode:
Diffstat (limited to 'netlify-preview.js')
-rw-r--r--netlify-preview.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/netlify-preview.js b/netlify-preview.js
new file mode 100644
index 0000000..5b37433
--- /dev/null
+++ b/netlify-preview.js
@@ -0,0 +1,58 @@
+'use strict';
+
+const fs = require('fs');
+const path = require('path');
+
+const netlifyConfig = 'netlify.toml';
+
+// Read the netlify.toml file
+fs.readFile(path.resolve(__dirname, netlifyConfig), 'utf8', (err, data) => {
+ if (err) {
+ console.error('Error reading file: ', err);
+ return;
+ }
+
+ // Split the file content into lines
+ const lines = data.split('\n');
+
+ // Process each line
+ const processedLines = lines.map((line) => {
+ // -> default-src 'self';
+ // <- default-src 'self' blob:;
+ line = line.replace(/(default-src) ('self')(;)/, '$1 $2 blob:$3');
+
+ // -> style-src 'self' cdn.hypothes.is;
+ // <- style-src 'self' 'unsafe-inline' cdn.hypothes.is;
+ line = line.replace(/(style-src) ('self') (cdn\.hypothes\.is)(;)/, '$1 $2 $3 \'unsafe-inline\'$4');
+
+ // -> media-src 'self';
+ // <- media-src 'self' blob: https://app.netlify.com;
+ line = line.replace(/(media-src) ('self')(;)/, '$1 $2 blob: https://app.netlify.com$3');
+
+ // -> frame-src hypothes.is;
+ // <- frame-src hypothes.is app.netlify.com;
+ line = line.replace(/(frame-src) (hypothes\.is)(;)/, '$1 $2 app.netlify.com$3');
+
+ // -> script-src 'self' www.googletagmanager.com hypothes.is cdn.hypothes.is;
+ // <- script-src 'self' www.googletagmanager.com hypothes.is cdn.hypothes.is netlify-cdp-loader.netlify.app;
+ line = line.replace(
+ /(script-src) ('self' www\.googletagmanager\.com hypothes\.is cdn\.hypothes\.is)(;)/,
+ '$1 $2 netlify-cdp-loader.netlify.app$3'
+ );
+
+ return line;
+ });
+
+ // Join the processed lines back into a single string
+ const output = processedLines.join('\n');
+
+ // Write the modified content back to the file
+ fs.writeFile(path.resolve(__dirname, netlifyConfig), output, 'utf8', (err) => {
+ if (err) {
+ console.error('Error writing file:', err);
+ return;
+ }
+
+ console.log('Done');
+ });
+});