diff --git a/docs/index.md b/docs/index.md index e67094c..cab2af7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -10,6 +10,3 @@ What sets Doco apart is its delivery as a single binary, seamlessly integrating With user-friendly features like sidebar navigation and a search component, Doco makes your documentation accessible and easy to navigate. It's a straightforward, effective tool for quickly generating and deploying organized documentation websites. Opt for Doco for a hassle-free, adaptable documentation solution that aligns with your continuous integration needs. ![Doco Preview](assets/preview.png "Preview of Doco") - -**Next**: -[Getting Started](/getting_started.html) \ No newline at end of file diff --git a/internal/generate.go b/internal/generate.go index 21ef207..88f8d48 100644 --- a/internal/generate.go +++ b/internal/generate.go @@ -22,6 +22,11 @@ var ( tmpl = template.Must(template.New("doco").Parse(string(tmplHTML))) ) +type navlink struct { + Title string `json:"-"` + Link string `json:"-"` +} + // generatedPage is the data passed to the template // to generate the static html files. type generatedPage struct { @@ -31,7 +36,10 @@ type generatedPage struct { SectionName string `json:"section_name"` Content template.HTML `json:"content"` Link string `json:"link"` + filePath string `json:"-"` + Prev navlink `json:"-"` + Next navlink `json:"-"` Style template.CSS `json:"-"` DesktopNavigation template.HTML `json:"-"` } @@ -59,11 +67,10 @@ func Generate(srcFolder, dstFolder string, site *site) error { // Copy all assets err = copyDir(filepath.Join(srcFolder, "assets"), filepath.Join(dstFolder, "assets")) if err != nil { - return fmt.Errorf("error copyiing assets: %w", err) + return fmt.Errorf("error copying assets: %w", err) } var pages []generatedPage - // Generate pages for each of the sections and documents inside them // and write them to the destination folder. for _, v := range site.sections { @@ -77,35 +84,49 @@ func Generate(srcFolder, dstFolder string, site *site) error { name := strings.Replace(doc.filename, filepath.Ext(doc.filename), ".html", 1) name = underscore(name) - // write the file - file, err := os.Create(filepath.Join(dstFolder, v.path, name)) - if err != nil { - return err - } - - deskNav := desktopNavigation(site, doc) - data := generatedPage{ + filePath: filepath.Join(dstFolder, v.path, name), SiteConfig: siteConfig, Title: doc.title, SectionName: v.name, Link: filepath.Join(v.path, name), - Content: doc.html, - Style: template.CSS(style), - DesktopNavigation: deskNav, - } + Content: doc.html, + Style: template.CSS(style), - err = tmpl.Execute(file, data) - if err != nil { - return err + DesktopNavigation: desktopNavigation(site, doc), } pages = append(pages, data) } } + // Generate all of the files + + for index, v := range pages { + if index < len(pages)-1 { + v.Next.Link = pages[index+1].Link + v.Next.Title = pages[index+1].Title + } + + if index > 0 { + v.Prev.Link = pages[index-1].Link + v.Prev.Title = pages[index-1].Title + } + + // write the file + file, err := os.Create(v.filePath) + if err != nil { + return err + } + + err = tmpl.Execute(file, v) + if err != nil { + return err + } + } + f, err := os.Create(filepath.Join(dstFolder, "index.json")) if err != nil { return fmt.Errorf("error generating search index: %w", err) diff --git a/internal/template.html b/internal/template.html index 4a43d48..169b938 100644 --- a/internal/template.html +++ b/internal/template.html @@ -111,6 +111,30 @@

{{ .Content }}
+ +
+
+ {{if not (eq .Prev.Link "")}} + + + + + + Previous + + {{end}} +
+
+ {{if not (eq .Next.Link "")}} + + Next + + + + + {{end}} +
+