summaryrefslogtreecommitdiffstats
path: root/netlify-pr.go
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2024-04-13 09:04:18 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2024-04-13 09:44:25 +0200
commit0c6aad8d28d9398dc36c70149e221f3af62203cc (patch)
tree82feb54ad7f30d39be2d28b8a3a111a4d7698f76 /netlify-pr.go
parent69e11ac3fa82228ee544cc5423f344d84d1569f8 (diff)
downloadgohugo-theme-ed-0c6aad8d28d9398dc36c70149e221f3af62203cc.tar.gz
Replace Go script with Node.js implementation
Diffstat (limited to 'netlify-pr.go')
-rw-r--r--netlify-pr.go66
1 files changed, 0 insertions, 66 deletions
diff --git a/netlify-pr.go b/netlify-pr.go
deleted file mode 100644
index 58fac5d..0000000
--- a/netlify-pr.go
+++ /dev/null
@@ -1,66 +0,0 @@
-package main
-
-// Path netlify.toml file for Netlify Deploy Preview to allow some
-// violation for CSP header.
-
-import (
- "fmt"
- "log"
- "os"
- "regexp"
- "strings"
-)
-
-const netlifyConfig = "netlify.toml"
-
-func main() {
- input, err := os.ReadFile(netlifyConfig)
- if err != nil {
- log.Fatalln(err)
- }
-
- lines := strings.Split(string(input), "\n")
- for i, line := range lines {
- newStr := line
-
- // -> default-src 'self';
- // <- default-src 'self' blob:;
- reStr := regexp.MustCompile("(default-src) ('self')(;)")
- repStr := "${1} ${2} blob:${3}"
- newStr = reStr.ReplaceAllString(newStr, repStr)
-
- // -> style-src 'self' cdn.hypothes.is;
- // <- style-src 'self' 'unsafe-inline' cdn.hypothes.is;
- reStr = regexp.MustCompile(`(style-src) ('self') (cdn\.hypothes\.is)(;)`)
- repStr = "${1} ${2} ${3} 'unsafe-inline'${4}"
- newStr = reStr.ReplaceAllString(newStr, repStr)
-
- // -> media-src 'self';
- // <- media-src 'self' blob: https://app.netlify.com;
- reStr = regexp.MustCompile("(media-src) ('self')(;)")
- repStr = "${1} ${2} blob: https://app.netlify.com${3}"
- newStr = reStr.ReplaceAllString(newStr, repStr)
-
- // -> frame-src hypothes.is;
- // <- frame-src hypothes.is app.netlify.com;
- reStr = regexp.MustCompile(`(frame-src) (hypothes\.is)(;)`)
- repStr = "${1} ${2} app.netlify.com${3}"
- newStr = reStr.ReplaceAllString(newStr, repStr)
-
- // -> 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;
- reStr = regexp.MustCompile(`(script-src) ('self' www\.googletagmanager\.com hypothes\.is cdn\.hypothes\.is)(;)`)
- repStr = "${1} ${2} netlify-cdp-loader.netlify.app${3}"
- newStr = reStr.ReplaceAllString(newStr, repStr)
-
- lines[i] = newStr
- }
-
- output := strings.Join(lines, "\n")
- err = os.WriteFile(netlifyConfig, []byte(output), 0644)
- if err != nil {
- log.Fatalln(err)
- }
-
- fmt.Println("Done")
-}