Skip to content

Commit

Permalink
task: adding next and prev to the pages
Browse files Browse the repository at this point in the history
  • Loading branch information
paganotoni committed Jan 19, 2024
1 parent 098b7ec commit a2fe414
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
55 changes: 38 additions & 17 deletions internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:"-"`
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions internal/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ <h1 id="welcome" class="font-bold text-4xl mb-2">
<div id="htmlcontainer" class="max-w-5xl">
{{ .Content }}
</div>

<div class="flex flex-row justify-between text-gray-600 pt-8">
<div>
{{if not (eq .Prev.Link "")}}
<a class="p-6 border-2 rounded-lg flex flex-row gap-3 items-center hover:shadow-md" href="/{{.Prev.Link}}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M10.5 19.5 3 12m0 0 7.5-7.5M3 12h18" />
</svg>

Previous
</a>
{{end}}
</div>
<div>
{{if not (eq .Next.Link "")}}
<a class="p-6 border-2 rounded-lg flex flex-row gap-3 items-center hover:shadow-md" href="/{{.Next.Link}}">
Next
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5 21 12m0 0-7.5 7.5M21 12H3" />
</svg>
</a>
{{end}}
</div>
</div>
</main>


Expand Down

0 comments on commit a2fe414

Please sign in to comment.