From 48af0d200eae37be6436afec1f7763a6b1f4c24d Mon Sep 17 00:00:00 2001 From: Dominik Menke Date: Sat, 26 Oct 2024 03:49:06 +0200 Subject: [PATCH] chore: update readme generator (#2311) --- README.md | 213 +++++++++++++++++++++++++------ internal/dns/docs/generator.go | 109 ++++++---------- internal/dns/docs/readme.md.tmpl | 11 ++ 3 files changed, 223 insertions(+), 110 deletions(-) create mode 100644 internal/dns/docs/readme.md.tmpl diff --git a/README.md b/README.md index 586881e8ed..1e16afebc9 100644 --- a/README.md +++ b/README.md @@ -51,43 +51,182 @@ Detailed documentation is available [here](https://go-acme.github.io/lego/dns). -| | | | | -|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------| -| [Akamai EdgeDNS](https://go-acme.github.io/lego/dns/edgedns/) | [Alibaba Cloud DNS](https://go-acme.github.io/lego/dns/alidns/) | [all-inkl](https://go-acme.github.io/lego/dns/allinkl/) | [Amazon Lightsail](https://go-acme.github.io/lego/dns/lightsail/) | -| [Amazon Route 53](https://go-acme.github.io/lego/dns/route53/) | [ArvanCloud](https://go-acme.github.io/lego/dns/arvancloud/) | [Aurora DNS](https://go-acme.github.io/lego/dns/auroradns/) | [Autodns](https://go-acme.github.io/lego/dns/autodns/) | -| [Azure (deprecated)](https://go-acme.github.io/lego/dns/azure/) | [Azure DNS](https://go-acme.github.io/lego/dns/azuredns/) | [Bindman](https://go-acme.github.io/lego/dns/bindman/) | [Bluecat](https://go-acme.github.io/lego/dns/bluecat/) | -| [Brandit](https://go-acme.github.io/lego/dns/brandit/) | [Bunny](https://go-acme.github.io/lego/dns/bunny/) | [Checkdomain](https://go-acme.github.io/lego/dns/checkdomain/) | [Civo](https://go-acme.github.io/lego/dns/civo/) | -| [Cloud.ru](https://go-acme.github.io/lego/dns/cloudru/) | [CloudDNS](https://go-acme.github.io/lego/dns/clouddns/) | [Cloudflare](https://go-acme.github.io/lego/dns/cloudflare/) | [ClouDNS](https://go-acme.github.io/lego/dns/cloudns/) | -| [CloudXNS](https://go-acme.github.io/lego/dns/cloudxns/) | [ConoHa](https://go-acme.github.io/lego/dns/conoha/) | [Constellix](https://go-acme.github.io/lego/dns/constellix/) | [Core-Networks](https://go-acme.github.io/lego/dns/corenetworks/) | -| [CPanel/WHM](https://go-acme.github.io/lego/dns/cpanel/) | [Derak Cloud](https://go-acme.github.io/lego/dns/derak/) | [deSEC.io](https://go-acme.github.io/lego/dns/desec/) | [Designate DNSaaS for Openstack](https://go-acme.github.io/lego/dns/designate/) | -| [Digital Ocean](https://go-acme.github.io/lego/dns/digitalocean/) | [DirectAdmin](https://go-acme.github.io/lego/dns/directadmin/) | [DNS Made Easy](https://go-acme.github.io/lego/dns/dnsmadeeasy/) | [dnsHome.de](https://go-acme.github.io/lego/dns/dnshomede/) | -| [DNSimple](https://go-acme.github.io/lego/dns/dnsimple/) | [DNSPod (deprecated)](https://go-acme.github.io/lego/dns/dnspod/) | [Domain Offensive (do.de)](https://go-acme.github.io/lego/dns/dode/) | [Domeneshop](https://go-acme.github.io/lego/dns/domeneshop/) | -| [DreamHost](https://go-acme.github.io/lego/dns/dreamhost/) | [Duck DNS](https://go-acme.github.io/lego/dns/duckdns/) | [Dyn](https://go-acme.github.io/lego/dns/dyn/) | [Dynu](https://go-acme.github.io/lego/dns/dynu/) | -| [EasyDNS](https://go-acme.github.io/lego/dns/easydns/) | [Efficient IP](https://go-acme.github.io/lego/dns/efficientip/) | [Epik](https://go-acme.github.io/lego/dns/epik/) | [Exoscale](https://go-acme.github.io/lego/dns/exoscale/) | -| [External program](https://go-acme.github.io/lego/dns/exec/) | [freemyip.com](https://go-acme.github.io/lego/dns/freemyip/) | [G-Core](https://go-acme.github.io/lego/dns/gcore/) | [Gandi Live DNS (v5)](https://go-acme.github.io/lego/dns/gandiv5/) | -| [Gandi](https://go-acme.github.io/lego/dns/gandi/) | [Glesys](https://go-acme.github.io/lego/dns/glesys/) | [Go Daddy](https://go-acme.github.io/lego/dns/godaddy/) | [Google Cloud](https://go-acme.github.io/lego/dns/gcloud/) | -| [Google Domains](https://go-acme.github.io/lego/dns/googledomains/) | [Hetzner](https://go-acme.github.io/lego/dns/hetzner/) | [Hosting.de](https://go-acme.github.io/lego/dns/hostingde/) | [Hosttech](https://go-acme.github.io/lego/dns/hosttech/) | -| [HTTP request](https://go-acme.github.io/lego/dns/httpreq/) | [http.net](https://go-acme.github.io/lego/dns/httpnet/) | [Huawei Cloud](https://go-acme.github.io/lego/dns/huaweicloud/) | [Hurricane Electric DNS](https://go-acme.github.io/lego/dns/hurricane/) | -| [HyperOne](https://go-acme.github.io/lego/dns/hyperone/) | [IBM Cloud (SoftLayer)](https://go-acme.github.io/lego/dns/ibmcloud/) | [IIJ DNS Platform Service](https://go-acme.github.io/lego/dns/iijdpf/) | [Infoblox](https://go-acme.github.io/lego/dns/infoblox/) | -| [Infomaniak](https://go-acme.github.io/lego/dns/infomaniak/) | [Internet Initiative Japan](https://go-acme.github.io/lego/dns/iij/) | [Internet.bs](https://go-acme.github.io/lego/dns/internetbs/) | [INWX](https://go-acme.github.io/lego/dns/inwx/) | -| [Ionos](https://go-acme.github.io/lego/dns/ionos/) | [IPv64](https://go-acme.github.io/lego/dns/ipv64/) | [iwantmyname](https://go-acme.github.io/lego/dns/iwantmyname/) | [Joker](https://go-acme.github.io/lego/dns/joker/) | -| [Joohoi's ACME-DNS](https://go-acme.github.io/lego/dns/acme-dns/) | [Liara](https://go-acme.github.io/lego/dns/liara/) | [Lima-City](https://go-acme.github.io/lego/dns/limacity/) | [Linode (v4)](https://go-acme.github.io/lego/dns/linode/) | -| [Liquid Web](https://go-acme.github.io/lego/dns/liquidweb/) | [Loopia](https://go-acme.github.io/lego/dns/loopia/) | [LuaDNS](https://go-acme.github.io/lego/dns/luadns/) | [Mail-in-a-Box](https://go-acme.github.io/lego/dns/mailinabox/) | -| [Manual](https://go-acme.github.io/lego/dns/manual/) | [Metaname](https://go-acme.github.io/lego/dns/metaname/) | [mijn.host](https://go-acme.github.io/lego/dns/mijnhost/) | [Mittwald](https://go-acme.github.io/lego/dns/mittwald/) | -| [MyDNS.jp](https://go-acme.github.io/lego/dns/mydnsjp/) | [MythicBeasts](https://go-acme.github.io/lego/dns/mythicbeasts/) | [Name.com](https://go-acme.github.io/lego/dns/namedotcom/) | [Namecheap](https://go-acme.github.io/lego/dns/namecheap/) | -| [Namesilo](https://go-acme.github.io/lego/dns/namesilo/) | [NearlyFreeSpeech.NET](https://go-acme.github.io/lego/dns/nearlyfreespeech/) | [Netcup](https://go-acme.github.io/lego/dns/netcup/) | [Netlify](https://go-acme.github.io/lego/dns/netlify/) | -| [Nicmanager](https://go-acme.github.io/lego/dns/nicmanager/) | [NIFCloud](https://go-acme.github.io/lego/dns/nifcloud/) | [Njalla](https://go-acme.github.io/lego/dns/njalla/) | [Nodion](https://go-acme.github.io/lego/dns/nodion/) | -| [NS1](https://go-acme.github.io/lego/dns/ns1/) | [Open Telekom Cloud](https://go-acme.github.io/lego/dns/otc/) | [Oracle Cloud](https://go-acme.github.io/lego/dns/oraclecloud/) | [OVH](https://go-acme.github.io/lego/dns/ovh/) | -| [plesk.com](https://go-acme.github.io/lego/dns/plesk/) | [Porkbun](https://go-acme.github.io/lego/dns/porkbun/) | [PowerDNS](https://go-acme.github.io/lego/dns/pdns/) | [Rackspace](https://go-acme.github.io/lego/dns/rackspace/) | -| [RcodeZero](https://go-acme.github.io/lego/dns/rcodezero/) | [reg.ru](https://go-acme.github.io/lego/dns/regru/) | [RFC2136](https://go-acme.github.io/lego/dns/rfc2136/) | [RimuHosting](https://go-acme.github.io/lego/dns/rimuhosting/) | -| [Sakura Cloud](https://go-acme.github.io/lego/dns/sakuracloud/) | [Scaleway](https://go-acme.github.io/lego/dns/scaleway/) | [Selectel v2](https://go-acme.github.io/lego/dns/selectelv2/) | [Selectel](https://go-acme.github.io/lego/dns/selectel/) | -| [SelfHost.(de/eu)](https://go-acme.github.io/lego/dns/selfhostde/) | [Servercow](https://go-acme.github.io/lego/dns/servercow/) | [Shellrent](https://go-acme.github.io/lego/dns/shellrent/) | [Simply.com](https://go-acme.github.io/lego/dns/simply/) | -| [Sonic](https://go-acme.github.io/lego/dns/sonic/) | [Stackpath](https://go-acme.github.io/lego/dns/stackpath/) | [Tencent Cloud DNS](https://go-acme.github.io/lego/dns/tencentcloud/) | [Timeweb Cloud](https://go-acme.github.io/lego/dns/timewebcloud/) | -| [TransIP](https://go-acme.github.io/lego/dns/transip/) | [UKFast SafeDNS](https://go-acme.github.io/lego/dns/safedns/) | [Ultradns](https://go-acme.github.io/lego/dns/ultradns/) | [Variomedia](https://go-acme.github.io/lego/dns/variomedia/) | -| [VegaDNS](https://go-acme.github.io/lego/dns/vegadns/) | [Vercel](https://go-acme.github.io/lego/dns/vercel/) | [Versio.[nl/eu/uk]](https://go-acme.github.io/lego/dns/versio/) | [VinylDNS](https://go-acme.github.io/lego/dns/vinyldns/) | -| [VK Cloud](https://go-acme.github.io/lego/dns/vkcloud/) | [Volcano Engine/火山引擎](https://go-acme.github.io/lego/dns/volcengine/) | [Vscale](https://go-acme.github.io/lego/dns/vscale/) | [Vultr](https://go-acme.github.io/lego/dns/vultr/) | -| [Webnames](https://go-acme.github.io/lego/dns/webnames/) | [Websupport](https://go-acme.github.io/lego/dns/websupport/) | [WEDOS](https://go-acme.github.io/lego/dns/wedos/) | [Yandex 360](https://go-acme.github.io/lego/dns/yandex360/) | -| [Yandex Cloud](https://go-acme.github.io/lego/dns/yandexcloud/) | [Yandex PDD](https://go-acme.github.io/lego/dns/yandex/) | [Zone.ee](https://go-acme.github.io/lego/dns/zoneee/) | [Zonomi](https://go-acme.github.io/lego/dns/zonomi/) | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Akamai EdgeDNSAlibaba Cloud DNSall-inklAmazon Lightsail
Amazon Route 53ArvanCloudAurora DNSAutodns
Azure (deprecated)Azure DNSBindmanBluecat
BranditBunnyCheckdomainCivo
Cloud.ruCloudDNSCloudflareClouDNS
CloudXNSConoHaConstellixCore-Networks
CPanel/WHMDerak ClouddeSEC.ioDesignate DNSaaS for Openstack
Digital OceanDirectAdminDNS Made EasydnsHome.de
DNSimpleDNSPod (deprecated)Domain Offensive (do.de)Domeneshop
DreamHostDuck DNSDynDynu
EasyDNSEfficient IPEpikExoscale
External programfreemyip.comG-CoreGandi
Gandi Live DNS (v5)GlesysGo DaddyGoogle Cloud
Google DomainsHetznerHosting.deHosttech
HTTP requesthttp.netHuawei CloudHurricane Electric DNS
HyperOneIBM Cloud (SoftLayer)IIJ DNS Platform ServiceInfoblox
InfomaniakInternet Initiative JapanInternet.bsINWX
IonosIPv64iwantmynameJoker
Joohoi's ACME-DNSLiaraLima-CityLinode (v4)
Liquid WebLoopiaLuaDNSMail-in-a-Box
ManualMetanamemijn.hostMittwald
MyDNS.jpMythicBeastsName.comNamecheap
NamesiloNearlyFreeSpeech.NETNetcupNetlify
NicmanagerNIFCloudNjallaNodion
NS1Open Telekom CloudOracle CloudOVH
plesk.comPorkbunPowerDNSRackspace
RcodeZeroreg.ruRFC2136RimuHosting
Sakura CloudScalewaySelectelSelectel v2
SelfHost.(de|eu)ServercowShellrentSimply.com
SonicStackpathTencent Cloud DNSTimeweb Cloud
TransIPUKFast SafeDNSUltradnsVariomedia
VegaDNSVercelVersio.[nl|eu|uk]VinylDNS
VK CloudVolcano Engine/火山引擎VscaleVultr
WebnamesWebsupportWEDOSYandex 360
Yandex CloudYandex PDDZone.eeZonomi
diff --git a/internal/dns/docs/generator.go b/internal/dns/docs/generator.go index 30e543faa3..3ffdcc92c5 100644 --- a/internal/dns/docs/generator.go +++ b/internal/dns/docs/generator.go @@ -8,11 +8,11 @@ import ( "errors" "fmt" "go/format" - "io" + html "html/template" "log" "os" "path/filepath" - "sort" + "slices" "strings" "text/template" @@ -22,11 +22,12 @@ import ( const ( root = "../../../" - mdTemplate = root + "internal/dns/docs/dns.md.tmpl" - cliTemplate = root + "internal/dns/docs/dns.go.tmpl" - cliOutput = root + "cmd/zz_gen_cmd_dnshelp.go" - docOutput = root + "docs/content/dns" - readmePath = root + "README.md" + mdTemplate = root + "internal/dns/docs/dns.md.tmpl" + cliTemplate = root + "internal/dns/docs/dns.go.tmpl" + cliOutput = root + "cmd/zz_gen_cmd_dnshelp.go" + docOutput = root + "docs/content/dns" + readmeTemplate = root + "internal/dns/docs/readme.md.tmpl" + readmePath = root + "README.md" ) const ( @@ -109,7 +110,8 @@ func generateCLIHelp(models *descriptors.Providers) error { } func generateReadMe(models *descriptors.Providers) error { - maximum, lines := extractTableData(models) + tpl := html.Must(html.New(filepath.Base(readmeTemplate)).ParseFiles(readmeTemplate)) + providers := orderProviders(models) file, err := os.Open(readmePath) if err != nil { @@ -128,8 +130,7 @@ func generateReadMe(models *descriptors.Providers) error { if text == startLine { _, _ = fmt.Fprintln(buffer, text) - err = writeDNSTable(buffer, lines, maximum) - if err != nil { + if err = tpl.Execute(buffer, providers); err != nil { return err } skip = true @@ -157,83 +158,45 @@ func generateReadMe(models *descriptors.Providers) error { return os.WriteFile(readmePath, buffer.Bytes(), 0o666) } -func extractTableData(models *descriptors.Providers) (int, [][]string) { - readmePattern := "[%s](https://go-acme.github.io/lego/dns/%s/)" - - items := []string{fmt.Sprintf(readmePattern, "Manual", "manual")} - - var maximum int - - for _, pvd := range models.Providers { - item := fmt.Sprintf(readmePattern, strings.ReplaceAll(pvd.Name, "|", "/"), pvd.Code) - items = append(items, item) - - if maximum < len(item) { - maximum = len(item) - } - } +func orderProviders(models *descriptors.Providers) [][]descriptors.Provider { + providers := append(models.Providers, descriptors.Provider{ + Name: "Manual", + Code: "manual", + }) const nbCol = 4 - sort.Slice(items, func(i, j int) bool { - return strings.ToLower(items[i]) < strings.ToLower(items[j]) + slices.SortFunc(providers, func(a, b descriptors.Provider) int { + return strings.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name)) }) - var lines [][]string - var line []string + var matrix [][]descriptors.Provider + var row []descriptors.Provider - for i, item := range items { + for i, p := range providers { switch { - case len(line) == nbCol: - lines = append(lines, line) - line = []string{item} - - case i == len(items)-1: - line = append(line, item) - for j := len(line); j < nbCol; j++ { - line = append(line, "") + case len(row) == nbCol: + matrix = append(matrix, row) + row = []descriptors.Provider{p} + + case i == len(providers)-1: + row = append(row, p) + for j := len(row); j < nbCol; j++ { + row = append(row, descriptors.Provider{}) } - lines = append(lines, line) + matrix = append(matrix, row) default: - line = append(line, item) + row = append(row, p) } } - if len(line) < nbCol { - for j := len(line); j < nbCol; j++ { - line = append(line, "") - } - lines = append(lines, line) - } - - return maximum, lines -} - -func writeDNSTable(w io.Writer, lines [][]string, size int) error { - _, err := fmt.Fprintf(w, "\n") - if err != nil { - return err - } - - _, err = fmt.Fprintf(w, "|%[1]s|%[1]s|%[1]s|%[1]s|\n", strings.Repeat(" ", size+2)) - if err != nil { - return err - } - - _, err = fmt.Fprintf(w, "|%[1]s|%[1]s|%[1]s|%[1]s|\n", strings.Repeat("-", size+2)) - if err != nil { - return err - } - - linePattern := fmt.Sprintf("| %%-%[1]ds | %%-%[1]ds | %%-%[1]ds | %%-%[1]ds |\n", size) - for _, line := range lines { - _, err = fmt.Fprintf(w, linePattern, line[0], line[1], line[2], line[3]) - if err != nil { - return err + if len(row) < nbCol { + for j := len(row); j < nbCol; j++ { + row = append(row, descriptors.Provider{}) } + matrix = append(matrix, row) } - _, err = fmt.Fprintf(w, "\n") - return err + return matrix } diff --git a/internal/dns/docs/readme.md.tmpl b/internal/dns/docs/readme.md.tmpl new file mode 100644 index 0000000000..3e0140243a --- /dev/null +++ b/internal/dns/docs/readme.md.tmpl @@ -0,0 +1,11 @@ + + +{{- range . -}} + + {{- range . }} + + {{- end }} + +{{- end -}} +
{{ .Name }}
+