• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / modo / 13162005183

05 Feb 2025 04:28PM CUT coverage: 72.707%. Remained the same
13162005183

Pull #206

github

web-flow
Merge 323cbe4df into 30d34556d
Pull Request #206: Fix souce links for packages with upper-case characters

1 of 2 new or added lines in 1 file covered. (50.0%)

1649 of 2268 relevant lines covered (72.71%)

26.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.15
/internal/format/hugo.go
1
package format
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "os"
7
        "path"
8
        "strings"
9
        "text/template"
10

11
        "github.com/mlange-42/modo/internal/document"
12
)
13

14
const landingPageContentHugo = `---
15
title: Landing page
16
type: docs
17
---
18

19
JSON created by mojo doc should be placed next to this file.
20

21
Additional documentation files go here, too.
22
They will be processed for doc-tests and copied to folder 'site/content'.
23
`
24

25
type Hugo struct{}
26

27
func (f *Hugo) Accepts(files []string) error {
×
28
        return nil
×
29
}
×
30

31
func (f *Hugo) ProcessMarkdown(element any, text string, proc *document.Processor) (string, error) {
1✔
32
        b := strings.Builder{}
1✔
33
        err := proc.Template.ExecuteTemplate(&b, "hugo_front_matter.md", element)
1✔
34
        if err != nil {
1✔
35
                return "", err
×
36
        }
×
37
        b.WriteRune('\n')
1✔
38
        b.WriteString(text)
1✔
39
        return b.String(), nil
1✔
40
}
41

42
func (f *Hugo) WriteAuxiliary(p *document.Package, dir string, proc *document.Processor) error {
×
43
        return nil
×
44
}
×
45

46
func (f *Hugo) ToFilePath(p string, kind string) string {
6✔
47
        if kind == "package" || kind == "module" {
10✔
48
                return path.Join(p, "_index.md")
4✔
49
        }
4✔
50
        return p + ".md"
2✔
51
}
52

53
func (f *Hugo) ToLinkPath(p string, kind string) string {
3✔
54
        p = f.ToFilePath(p, kind)
3✔
55
        return fmt.Sprintf("{{< ref \"%s\" >}}", p)
3✔
56
}
3✔
57

58
func (f *Hugo) Input(in string, sources []document.PackageSource) string {
1✔
59
        return in
1✔
60
}
1✔
61

62
func (f *Hugo) Output(out string) string {
2✔
63
        return path.Join(out, "content")
2✔
64
}
2✔
65

66
func (f *Hugo) GitIgnore(in, out string, sources []document.PackageSource) []string {
1✔
67
        return []string{
1✔
68
                "# files generated by 'mojo doc'",
1✔
69
                fmt.Sprintf("/%s/*.json", in),
1✔
70
                "# files generated by Modo",
1✔
71
                fmt.Sprintf("/%s/%s/", out, "content"),
1✔
72
                "# files generated by Hugo",
1✔
73
                fmt.Sprintf("/%s/%s/", out, "public"),
1✔
74
                fmt.Sprintf("/%s/*.lock", out),
1✔
75
                "# test file generated by Modo",
1✔
76
                "/test/",
1✔
77
        }
1✔
78
}
1✔
79

80
func (f *Hugo) CreateDirs(base, in, out string, sources []document.PackageSource, templ *template.Template) error {
1✔
81
        inDir, outDir := path.Join(base, in), path.Join(base, f.Output(out))
1✔
82
        testDir := path.Join(base, "test")
1✔
83
        if err := mkDirs(inDir); err != nil {
1✔
84
                return err
×
85
        }
×
86
        if err := os.WriteFile(path.Join(inDir, "_index.md"), []byte(landingPageContentHugo), 0644); err != nil {
1✔
87
                return err
×
88
        }
×
89
        if err := mkDirs(outDir); err != nil {
1✔
90
                return err
×
91
        }
×
92
        if err := mkDirs(testDir); err != nil {
1✔
93
                return err
×
94
        }
×
95
        return f.createInitialFiles(base, path.Join(base, out), templ)
1✔
96
}
97

98
func (f *Hugo) createInitialFiles(docDir, hugoDir string, templ *template.Template) error {
1✔
99
        config, err := document.GetGitOrigin(docDir)
1✔
100
        if err != nil {
1✔
101
                return err
×
102
        }
×
103

104
        files := [][]string{
1✔
105
                {"hugo.yaml", "hugo.yaml"},
1✔
106
                {"hugo.mod", "go.mod"},
1✔
107
                {"hugo.sum", "go.sum"},
1✔
108
        }
1✔
109
        for _, f := range files {
4✔
110
                outFile := path.Join(hugoDir, f[1])
3✔
111
                exists, _, err := fileExists(outFile)
3✔
112
                if err != nil {
3✔
113
                        return err
×
114
                }
×
115
                if exists {
3✔
116
                        fmt.Printf("WARNING: Hugo file %s already exists, skip creating\n", outFile)
×
117
                        return nil
×
118
                }
×
119
        }
120

121
        for _, f := range files {
4✔
122
                outFile := path.Join(hugoDir, f[1])
3✔
123
                b := bytes.Buffer{}
3✔
124
                if err := templ.ExecuteTemplate(&b, f[0], &config); err != nil {
3✔
125
                        return err
×
126
                }
×
127
                if err := os.WriteFile(outFile, b.Bytes(), 0644); err != nil {
3✔
128
                        return err
×
129
                }
×
130
        }
131
        return nil
1✔
132
}
133

134
func (f *Hugo) Clean(out, tests string) error {
1✔
135
        if err := emptyDir(out); err != nil {
1✔
136
                return err
×
137
        }
×
138
        return emptyDir(tests)
1✔
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc