diff --git a/content/bbc/teletext/_index.html b/content/bbc/teletext/_index.html new file mode 100644 index 00000000..7a39fff5 --- /dev/null +++ b/content/bbc/teletext/_index.html @@ -0,0 +1,12 @@ +--- +type: "bookTitle" +title: "Teletext Mode 7" +linkTitle: "Teletext Mode 7" +weight: 20 +categories: + - bbc +--- +
+ +
+ diff --git a/content/bbc/teletext/charset/_index.html b/content/bbc/teletext/charset/_index.html new file mode 100644 index 00000000..98926e19 --- /dev/null +++ b/content/bbc/teletext/charset/_index.html @@ -0,0 +1,203 @@ +--- +type: "bookTitle" +title: "Mode 7 Character set" +linkTitle: "Character set" +weight: 20 +categories: + - bbc +charset: + - char: 32 + name: " " + - char: 33 + name: "!" + - char: 34 + name: "\"" + - char: 35 + name: "#" + - char: 36 + name: "$" + - char: 37 + name: "%" + - char: 38 + name: "&" + - char: 39 + name: "'" + - char: 40 + name: "(" + - char: 41 + name: ")" + - char: 42 + name: "*" + - char: 43 + name: "+" + - char: 44 + name: "," + - char: 45 + name: "-" + - char: 46 + name: "." + - char: 47 + name: "/" + - char: 48 + name: "0" + - char: 49 + name: "1" + - char: 50 + name: "2" + - char: 51 + name: "3" + - char: 52 + name: "4" + - char: 53 + name: "5" + - char: 54 + name: "6" + - char: 55 + name: "7" + - char: 56 + name: "8" + - char: 57 + name: "9" + - char: 58 + name: ":" + - char: 59 + name: ";" + - char: 60 + name: "<" + - char: 61 + name: "=" + - char: 62 + name: ">" + - char: 63 + name: "?" + - char: 64 + name: "@" + - char: 65 + name: "A" + - char: 66 + name: "B" + - char: 67 + name: "C" + - char: 68 + name: "D" + - char: 69 + name: "E" + - char: 70 + name: "F" + - char: 71 + name: "G" + - char: 72 + name: "H" + - char: 73 + name: "I" + - char: 74 + name: "J" + - char: 75 + name: "K" + - char: 76 + name: "L" + - char: 77 + name: "M" + - char: 78 + name: "N" + - char: 79 + name: "O" + - char: 80 + name: "P" + - char: 81 + name: "Q" + - char: 82 + name: "R" + - char: 83 + name: "S" + - char: 84 + name: "T" + - char: 85 + name: "U" + - char: 86 + name: "V" + - char: 87 + name: "W" + - char: 88 + name: "X" + - char: 89 + name: "Y" + - char: 90 + name: "Z" + - char: 91 + name: "[" + - char: 92 + name: "\\" + - char: 93 + name: "]" + - char: 94 + name: "^" + - char: 95 + name: "_" + - char: 96 + name: "`" + - char: 97 + name: "a" + - char: 98 + name: "b" + - char: 99 + name: "c" + - char: 100 + name: "d" + - char: 101 + name: "e" + - char: 102 + name: "f" + - char: 103 + name: "g" + - char: 104 + name: "h" + - char: 105 + name: "i" + - char: 106 + name: "j" + - char: 107 + name: "k" + - char: 108 + name: "l" + - char: 109 + name: "m" + - char: 110 + name: "n" + - char: 111 + name: "o" + - char: 112 + name: "p" + - char: 113 + name: "q" + - char: 114 + name: "r" + - char: 115 + name: "s" + - char: 116 + name: "t" + - char: 117 + name: "u" + - char: 118 + name: "v" + - char: 119 + name: "w" + - char: 120 + name: "x" + - char: 121 + name: "y" + - char: 122 + name: "z" + - char: 123 + name: "{" + - char: 124 + name: "|" + - char: 125 + name: "}" + - char: 126 + name: "~" +--- +
+ +
+ diff --git a/go.mod b/go.mod index 044642d6..0cbc22f6 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/chromedp/chromedp v0.7.4 github.com/gorilla/mux v1.7.2 github.com/microcosm-cc/bluemonday v1.0.16 - github.com/peter-mount/go-kernel v1.1.0 + github.com/peter-mount/go-kernel v1.1.1-0.20220128175407-5a6b80f9340a github.com/xuri/excelize/v2 v2.4.1 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/tools/generator/generator.go b/tools/generator/generator.go index c80d4b56..5b92323a 100644 --- a/tools/generator/generator.go +++ b/tools/generator/generator.go @@ -11,10 +11,9 @@ import ( // Generator is a kernel Service which handles the generation of content based on page metadata. type Generator struct { - config *hugo.Config `kernel:"inject"` // Configuration bookShelf *hugo.BookShelf `kernel:"inject"` - generators map[string]task.Task // Map of available generators worker task.Queue `kernel:"worker"` // Worker queue + generators map[string]task.Task // Map of available generators } func (g *Generator) Start() error { diff --git a/tools/hugo/config.go b/tools/hugo/config.go deleted file mode 100644 index 7b14e070..00000000 --- a/tools/hugo/config.go +++ /dev/null @@ -1,76 +0,0 @@ -package hugo - -import ( - "fmt" - "gopkg.in/yaml.v2" - "io/ioutil" - "path/filepath" -) - -// Config file for doctool -type Config struct { - Webserver WebserverConfig `yaml:"webserver"` // Webserver - PDF PDF `yaml:"pdf"` // Common PDF template, can be overridden per book - configFile *string `yaml:"-" kernel:"flag,c,Config file to use"` // Config file name -} - -type WebserverConfig struct { - Address string `yaml:"address"` // Webserver bind address, default "127.0.0.1" - Port int `yaml:"port"` // Port defaults to 8080 -} - -// PDF configuration -type PDF struct { - PrintBackground bool `yaml:"printBackground"` // Print background graphics - Margin PDFMargin `yaml:"margin"` // Page margins - Width float64 `yaml:"width"` // Page width in inches - Height float64 `yaml:"height"` // Page height in inches - Landscape bool `yaml:"landscape"` // Landscape or Portrait - Header string `yaml:"header"` // Header in html - Footer string `yaml:"footer"` // Footer in html - DisableHeaderFooter bool `yaml:"disableHeaderFooter"` // Disable header & footer generation -} - -// PDFMargin in inches. Default is 1cm ~0.4 inches -type PDFMargin struct { - Top float64 `yaml:"top"` // Top margin in inches - Left float64 `yaml:"left"` // Left margin in inches - Bottom float64 `yaml:"bottom"` // Bottom margin in inches - Right float64 `yaml:"right"` // Right margin in inches -} - -func (c *Config) Start() error { - // Verify then load the config file - if *c.configFile == "" { - *c.configFile = "config.yaml" - } - - filename, err := filepath.Abs(*c.configFile) - if err != nil { - return err - } - - in, err := ioutil.ReadFile(filename) - if err != nil { - return err - } - - err = yaml.Unmarshal(in, c) - if err != nil { - return err - } - - // Default webserver config - if c.Webserver.Address == "" { - c.Webserver.Address = "127.0.0.1" - } - if c.Webserver.Port == 0 { - c.Webserver.Port = 8080 - } - - return nil -} - -func (c *Config) WebPath(f string, a ...interface{}) string { - return fmt.Sprintf("http://%s:%d/"+f, append([]interface{}{c.Webserver.Address, c.Webserver.Port}, a...)...) -} diff --git a/tools/pdf/pdf.go b/tools/pdf/pdf.go index 64116028..229b19f1 100644 --- a/tools/pdf/pdf.go +++ b/tools/pdf/pdf.go @@ -15,15 +15,34 @@ import ( // PDF tool that handles the generation of PDF documentation of a "book" type PDF struct { - config *hugo.Config `kernel:"inject"` // Config + config *Config `kernel:"config,pdf"` // Config bookShelf *hugo.BookShelf `kernel:"inject"` // Bookshelf chromium *web.Chromium `kernel:"inject"` // Chromium browser enable *bool `kernel:"flag,p,disable PDF generation"` // Is PDF generation enabled worker task.Queue `kernel:"worker"` // Worker queue - _ *web.Webserver `kernel:"inject"` // we need these to deploy before this but don't + webserver *web.Webserver `kernel:"inject"` // Webserver _ *hugo.Hugo `kernel:"inject"` // access them directly } +type Config struct { + PrintBackground bool `yaml:"printBackground"` // Print background graphics + Margin Margin `yaml:"margin"` // Page margins + Width float64 `yaml:"width"` // Page width in inches + Height float64 `yaml:"height"` // Page height in inches + Landscape bool `yaml:"landscape"` // Landscape or Portrait + Header string `yaml:"header"` // Header in html + Footer string `yaml:"footer"` // Footer in html + DisableHeaderFooter bool `yaml:"disableHeaderFooter"` // Disable header & footer generation +} + +// Margin in inches. Default is 1cm ~0.4 inches +type Margin struct { + Top float64 `yaml:"top"` // Top margin in inches + Left float64 `yaml:"left"` // Left margin in inches + Bottom float64 `yaml:"bottom"` // Bottom margin in inches + Right float64 `yaml:"right"` // Right margin in inches +} + func (p *PDF) Start() error { if *p.enable { return nil @@ -40,25 +59,23 @@ func (p *PDF) Start() error { // print a specific pdf page. func (p *PDF) printToPDF(book *hugo.Book) chromedp.Tasks { - url := p.config.WebPath("%s/_print/", strings.ToLower(book.WebPath())) - - pdf := p.config.PDF + url := p.webserver.WebPath("%s/_print/", strings.ToLower(book.WebPath())) return chromedp.Tasks{ chromedp.Navigate(url), chromedp.ActionFunc(func(ctx context.Context) error { buf, _, err := page.PrintToPDF(). - WithPrintBackground(pdf.PrintBackground). - WithMarginTop(pdf.Margin.Top). - WithMarginBottom(pdf.Margin.Bottom). - WithMarginLeft(pdf.Margin.Left). - WithMarginRight(pdf.Margin.Right). - WithLandscape(pdf.Landscape). - WithPaperWidth(pdf.Width). - WithPaperHeight(pdf.Height). - WithDisplayHeaderFooter(!pdf.DisableHeaderFooter). - WithHeaderTemplate(book.Expand(pdf.Header)). - WithFooterTemplate(book.Expand(pdf.Footer)). + WithPrintBackground(p.config.PrintBackground). + WithMarginTop(p.config.Margin.Top). + WithMarginBottom(p.config.Margin.Bottom). + WithMarginLeft(p.config.Margin.Left). + WithMarginRight(p.config.Margin.Right). + WithLandscape(p.config.Landscape). + WithPaperWidth(p.config.Width). + WithPaperHeight(p.config.Height). + WithDisplayHeaderFooter(!p.config.DisableHeaderFooter). + WithHeaderTemplate(book.Expand(p.config.Header)). + WithFooterTemplate(book.Expand(p.config.Footer)). Do(ctx) if err != nil { diff --git a/tools/web/webserver.go b/tools/web/webserver.go index 361a4668..d5cd2dfd 100644 --- a/tools/web/webserver.go +++ b/tools/web/webserver.go @@ -2,8 +2,8 @@ package web import ( "context" + "fmt" "github.com/gorilla/mux" - "github.com/peter-mount/documentation/tools/hugo" "log" "net/http" "strconv" @@ -12,8 +12,13 @@ import ( // Webserver provides a webserver if required for other tasks. // It serves the public directory type Webserver struct { - config *hugo.Config `kernel:"inject"` // Config - server *http.Server // enabled + config *WebserverConfig `kernel:"config,webserver"` + server *http.Server +} + +type WebserverConfig struct { + Address string `yaml:"address"` // Webserver bind address, default "127.0.0.1" + Port int `yaml:"port"` // Port defaults to 8080 } func (w *Webserver) Start() error { @@ -24,7 +29,7 @@ func (w *Webserver) Start() error { Handler(http.FileServer(http.Dir("public"))) w.server = &http.Server{ - Addr: w.config.Webserver.Address + ":" + strconv.Itoa(w.config.Webserver.Port), + Addr: w.config.Address + ":" + strconv.Itoa(w.config.Port), Handler: router, } @@ -41,3 +46,7 @@ func (w *Webserver) Stop() { _ = w.server.Shutdown(context.Background()) } } + +func (c *Webserver) WebPath(f string, a ...interface{}) string { + return fmt.Sprintf("http://%s:%d/"+f, append([]interface{}{c.config.Address, c.config.Port}, a...)...) +}