diff options
author | Orville Q. Song <orville@anislet.dev> | 2025-03-15 21:27:43 +0300 |
---|---|---|
committer | Vladimir Druzenko <vvd@FreeBSD.org> | 2025-03-15 21:29:58 +0300 |
commit | 0397053f21db7b5f249b4c837b1a8ee9159a32f0 (patch) | |
tree | f13b8aac3fb8b2cd6a824da8927baee179ee293b /www/codeberg-pages-server/files/config-generater.go | |
parent | graphics/diffpdf: set to expire (diff) |
www/codeberg-pages-server: New port: "Github Pages"-like pages server for Gitea/Forgejo
Gitea lacks the ability to host static pages from Git. The Codeberg
Pages Server addresses this lack by implementing a standalone service
that connects to Gitea via API. It is suitable to be deployed by other
Gitea instances, too, to offer static pages hosting to their users.
https://codeberg.org/Codeberg/pages-server
PR: 284267
Diffstat (limited to 'www/codeberg-pages-server/files/config-generater.go')
-rw-r--r-- | www/codeberg-pages-server/files/config-generater.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/www/codeberg-pages-server/files/config-generater.go b/www/codeberg-pages-server/files/config-generater.go new file mode 100644 index 000000000000..9aa9793db05a --- /dev/null +++ b/www/codeberg-pages-server/files/config-generater.go @@ -0,0 +1,83 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "regexp" + "strings" +) + +var ( + linePattern = regexp.MustCompile(`^ *--([a-zA-Z0-9_-]+)\ value.*\[\$([A-Z0-9_]+)\]`) + descRegexp = regexp.MustCompile(`^.*value\s+(.*)(\(default.*\)|\[.*\]).*$`) + defValRegexp = regexp.MustCompile(`\(default: ([^)]+)\)`) +) + +func main() { + fmt.Println("# See https://codeberg.org/Codeberg/pages-server") + fmt.Println() + + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + line := scanner.Text() + matches := linePattern.FindStringSubmatch(line) + if matches == nil { + continue + } + + optionName := matches[2] + + descMatches := descRegexp.FindStringSubmatch(line) + var description string + if len(descMatches) > 1 { + description = descMatches[1] + } + description = strings.TrimRight(description, " \t") + if strings.HasPrefix(description, "]") { + description = strings.TrimPrefix(description, "]") + description = strings.TrimLeft(description, " ") + } + + defValMatches := defValRegexp.FindStringSubmatch(line) + var defaultValue string + if len(defValMatches) > 1 { + defaultValue = defValMatches[1] + } + + exportCmd := "export" + switch optionName { + case "FORBIDDEN_MIME_TYPES", + "ALLOWED_CORS_DOMAINS", + "BLACKLISTED_PATHS", + "CONFIG_FILE", + "PROFILING_ADDRESS", + "ACME_EAB_KID", + "ACME_EAB_HMAC", + "DNS_PROVIDER": + optionName = "#" + optionName + exportCmd = "#" + exportCmd + } + + if description != "" { + fmt.Printf("# %s\n", description) + } else { + fmt.Println("#") + } + + if defaultValue != "" { + fmt.Printf("%s=%s\n", optionName, defaultValue) + fmt.Printf("%s %s\n", exportCmd, optionName) + } else { + fmt.Printf("%s=\"\"\n", optionName) + uncommented := strings.TrimPrefix(optionName, "#") + fmt.Printf("%s %s\n", exportCmd, uncommented) + } + fmt.Println() + } + + if err := scanner.Err(); err != nil { + fmt.Fprintf(os.Stderr, "read error: %v\n", err) + os.Exit(1) + } +} |