Skip to content

Commit

Permalink
Fixed linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jibel committed Oct 24, 2023
1 parent 6535dff commit 3000ad9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"embed"
)

// Dir is the embedded directory containing documentation
// Dir is the embedded directory containing documentation.
// Only embed structured documentation.
//
//go:embed index.md tutorial/*.md how-to/*.md explanation/*.md reference/*.md
var Dir embed.FS

// Root of ReadTheDoc
// RTDRootURL is the root url of ReadTheDoc adsys documentation.
const RTDRootURL = "https://canonical-adsys.readthedocs-hosted.com/en/documentation_bootstrap"
16 changes: 9 additions & 7 deletions internal/adsysservice/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ubuntu/decorate"
)

// GetDoc returns a chapter documentation from server
// GetDoc returns a chapter documentation from server.
func (s *Service) GetDoc(r *adsys.GetDocRequest, stream adsys.Service_GetDocServer) (err error) {
defer decorate.OnError(&err, i18n.G("error while getting documentation"))

Expand Down Expand Up @@ -83,7 +83,7 @@ func docStructure(dir embed.FS, indexFilePath, parentChapterName string) (ordere

f, err := dir.Open(indexFilePath)
if err != nil {
return nil, nil, nil, fmt.Errorf("could not get main index file: %v", err)
return nil, nil, nil, fmt.Errorf("could not get main index file: %w", err)
}
defer f.Close()

Expand Down Expand Up @@ -168,7 +168,7 @@ func docStructure(dir embed.FS, indexFilePath, parentChapterName string) (ordere
}

if s.Err() != nil {
return nil, nil, nil, fmt.Errorf("can't scan index file: %v", err)
return nil, nil, nil, fmt.Errorf("can't scan index file: %w", err)
}

return orderedChapters, chaptersToFiles, filesToTitle, err
Expand All @@ -190,7 +190,7 @@ func titleFromPage(dir embed.FS, path string) (string, error) {
title := strings.TrimPrefix(strings.TrimSpace(s.Text()), "# ")

if s.Err() != nil {
return "", fmt.Errorf("can't scan file: %v", s.Err())
return "", fmt.Errorf("can't scan file: %w", s.Err())
}

return title, nil
Expand All @@ -204,7 +204,7 @@ func toCmdlineChapterName(t, parentChapterName string) string {
return strings.ToLower(strings.ReplaceAll(strings.TrimSpace(t), " ", "-"))
}

func renderDocumentationPage(p string, filesToTitle map[string]string, onlineDocURL string) (string, error) {
func renderDocumentationPage(p string, filesToTitle map[string]string) (string, error) {
var out strings.Builder

currentDir := filepath.Dir(p)
Expand Down Expand Up @@ -272,21 +272,23 @@ func renderDocumentationPage(p string, filesToTitle map[string]string, onlineDoc
}

if s.Err() != nil {
return "", fmt.Errorf("can't scan file: %v", s.Err())
return "", fmt.Errorf("can't scan file: %w", s.Err())
}

return out.String(), nil
}

var reURL = regexp.MustCompile(`\.\./images/(.+/)*`)

// imageURLToRTDURL rewrites images links to match Read the Docs format.
func imageURLToRTDURL(imageLine string) string {
return reURL.ReplaceAllString(imageLine, docs.RTDRootURL+"/_images/")
}

// Regular expression pattern to match [title](URL)
// Regular expression pattern to match [title](URL).
var reInternalLinksURL = regexp.MustCompile(`\[(.*?)\]\(.*?\)`)

// stripInternalLinks strips the link part from URL.
func stripInternalLinks(line string) string {
if strings.Contains(line, "http") {
return line
Expand Down

0 comments on commit 3000ad9

Please sign in to comment.