@@ -15,7 +15,7 @@ import (
1515
1616/* This file creates a folder full of docusaurus markdown files for https://unpackerr.zip */
1717
18- func printDocusaurus (config * Config , output string ) {
18+ func createDocusaurus (config * Config , output string ) {
1919 // Generate index file first.
2020 if err := makeGenerated (config , output ); err != nil {
2121 log .Fatalln (err )
@@ -24,14 +24,15 @@ func printDocusaurus(config *Config, output string) {
2424 for _ , section := range config .Order {
2525 // If Order contains a missing section, bail.
2626 if config .Sections [section ] == nil {
27- log .Fatalln (section + ": in order, but missing from sections. This is a bug in conf-builder .yml." )
27+ log .Fatalln (section + ": in order, but missing from sections. This is a bug in definitions .yml." )
2828 }
29-
29+ // We only care about sections with parameters defined.
3030 if len (config .Sections [section ].Params ) < 1 {
3131 continue
3232 }
3333
3434 if config .Defs [section ] != nil {
35+ // Repeat this section based on defined definitions.
3536 data := config .Sections [section ].makeDefinedDocs (config .Prefix , config .Defs [section ], config .DefOrder [section ])
3637 if err := writeDocusaurus (output , string (section ), data ); err != nil {
3738 log .Fatalln (err )
@@ -47,72 +48,74 @@ func printDocusaurus(config *Config, output string) {
4748
4849func writeDocusaurus (dir , file , content string ) error {
4950 _ = os .Mkdir (dir , dirMode )
50- date := "---\n # Generated: " + time .Now ().Round (time .Second ).String () + "\n ---\n \n "
51+ date := "---\n ## => Content Auto Generated, " +
52+ strings .ToUpper (time .Now ().UTC ().Round (time .Second ).Format ("02 Jan 2006 15:04 UTC" )) + "\n ---\n \n "
5153 filePath := filepath .Join (dir , file + ".md" )
5254 log .Printf ("Writing: %s, size: %d" , filePath , len (content ))
5355 //nolint:wrapcheck
5456 return os .WriteFile (filePath , []byte (date + content ), fileMode )
5557}
5658
57- // makeGenerated writes a special file that the website can import.
59+ // makeGenerated writes a special index file that the website can import.
5860// Adds all param sections except global into a docusaurus import format.
61+ // Also creates a footer file that can be imported and displayed.
5962func makeGenerated (config * Config , output string ) error {
60- var (
61- first bytes.Buffer
62- second bytes.Buffer
63- )
63+ var first , second bytes.Buffer
6464
6565 for _ , section := range config .Order {
6666 if len (config .Sections [section ].Params ) > 0 && section != "global" {
67- title := "G" + string (section )
68- first .WriteString ("import " + title + " from './" + string (section ) + ".md';\n " )
69- second .WriteString ("<" + title + "/>\n " )
67+ first .WriteString ("import G" + string (section ) + " from './" + string (section ) + ".md';\n " )
68+ second .WriteString ("<G" + string (section ) + "/>\n " )
7069 }
7170 }
7271
73- return writeDocusaurus (output , "index" , first .String ()+ "\n " + second .String ())
72+ err := writeDocusaurus (output , "index" , first .String ()+ "\n " + second .String ())
73+ if err != nil {
74+ return err
75+ }
76+
77+ return writeDocusaurus (output , "footer" , `<font color="gray" style={{'float': 'right', 'font-style': 'italic'}}>` +
78+ "This page was [generated automatically](https://github.com/Unpackerr/unpackerr/tree/main/init/config), " +
79+ strings .ToUpper (time .Now ().UTC ().Round (time .Second ).Format ("02 Jan 2006 15:04 UTC" ))+ "</font>\n " )
7480}
7581
7682func (h * Header ) makeDocs (prefix string , section section ) string {
77- buf := bytes. Buffer {}
78- buf . WriteString ( "## " + h . Title + " \n \n <details> \n " )
83+ conf := h . makeSection ( section , true , true ) // Generate this portion of the config file.
84+ env := h . makeCompose ( prefix , true ) // Generate this portion of the docker-compose example.
7985
80- conf := h .makeSection (section , true , true )
81- env := h .makeCompose (prefix , true )
82- header := "[" + string (section ) + "]"
86+ buf := bytes.Buffer {}
87+ buf .WriteString ("## " + h .Title + "\n \n <details>\n <summary>Examples. Prefix: <b>" + prefix )
8388
84- if h .Kind == list {
85- header = "[[" + string (section ) + "]]"
86- }
89+ if ! h .NoHeader {
90+ brace1 , brace2 := "[" , "]"
91+ if h .Kind == list {
92+ brace1 , brace2 = "[[" , "]]"
93+ }
8794
88- if h .NoHeader {
89- buf .WriteString (" <summary>Examples. Prefix: <b>" + prefix + "</b></summary>\n \n " )
90- } else {
91- buf .WriteString (" <summary>Examples. Prefix: <b>" + prefix + h .Prefix +
92- "</b>, Header: <b>" + header + "</b></summary>\n \n " )
95+ buf .WriteString (h .Prefix + "</b>, Header: <b> " ) // Add to the line above.
96+ buf .WriteString (brace1 + string (section ) + brace2 ) // Add to the line above.
9397 }
9498
99+ buf .WriteString ("</b></summary>\n \n " ) // Add to the line above.
95100 buf .WriteString ("- Using the config file:\n \n ```yaml\n " )
96101 buf .WriteString (strings .TrimSpace (conf ) + "\n ```\n \n " )
97102 buf .WriteString ("- Using environment variables:\n \n ```js\n " )
98103 buf .WriteString (env + "```\n \n </details>\n \n " )
99- buf .WriteString (h .Docs + "\n " ) // Docs comes before the table.
100- buf .WriteString (h .makeDocsTable (prefix ) + "\n " )
101- buf .WriteString (h .Tail ) // Tail goes after the docs and table.
104+ buf .WriteString (h .Docs + "\n " + h .makeDocsTable (prefix ) + "\n " + h .Tail )
102105
103106 if h .Notes != "" { // Notes become a sub header.
104- buf .WriteString ("### " + h .Title + " Notes \n \n " + h .Notes )
107+ buf .WriteString ("### Notes for " + h .Title + "\n \n " + h .Notes )
105108 }
106109
107110 return buf .String ()
108111}
109112
110- func (h * Header ) makeDocsTable (prefix string ) string {
111- const (
112- tableHeader = "|Config Name|Variable Name|Default / Note|\n |---|---|---|\n "
113- tableFormat = "|%s|`%s`|%v / %s|\n "
114- )
113+ const (
114+ tableHeader = "|Config Name|Variable Name|Default / Note|\n |---|---|---|\n "
115+ tableFormat = "|%s|`%s`|%v / %s|\n "
116+ )
115117
118+ func (h * Header ) makeDocsTable (prefix string ) string {
116119 buf := bytes.Buffer {}
117120 buf .WriteString (tableHeader )
118121
0 commit comments