Skip to content

Commit

Permalink
Use native lazy loading by default
Browse files Browse the repository at this point in the history
  • Loading branch information
demosjarco committed Mar 6, 2023
1 parent 98582a7 commit 7df1a90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cook-docs/testdata/recipe.md.gotmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{ template "cook.headerSection" . }}

{{ template "cook.imageSection" . }}
{{ template "cook.lazyImageSection" . }}

{{ template "cook.tableSection" . }}

Expand Down
2 changes: 1 addition & 1 deletion docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ this:
```go title="recipe.md.gotmpl"
{{ template "cook.headerSection" . }}

{{ template "cook.imageSection" . }}
{{ template "cook.lazyImageSection" . }}

{{ template "cook.tableSection" . }}

Expand Down
15 changes: 14 additions & 1 deletion pkg/document/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

const defaultDocumentationTemplate = `{{ template "cook.headerSection" . }}
{{ template "cook.imageSection" . }}
{{ template "cook.lazyImageSection" . }}
{{ template "cook.tableSection" . }}
Expand Down Expand Up @@ -54,6 +54,18 @@ func getImageTemplate() string {
return templateBuilder.String()
}

func getLazyImageTemplate() string {
templateBuilder := strings.Builder{}

templateBuilder.WriteString(`{{ define "cook.lazyImageSection" }}`)
templateBuilder.WriteString("{{ if .Info.ImageFileName }}")
templateBuilder.WriteString(`![{{ .Info.RecipeName }}](../assets/images/{{ lower .Info.ImageFileName | replace " " "-" }}){ loading=lazy }`)
templateBuilder.WriteString("{{ end }}")
templateBuilder.WriteString("{{ end }}")

return templateBuilder.String()
}

func getTableTemplate() string {
templateBuilder := strings.Builder{}

Expand Down Expand Up @@ -306,6 +318,7 @@ func getDocumentationTemplates(recipeSearchRoot string, recipePath string, templ
return []string{
getHeaderTemplate(),
getImageTemplate(),
getLazyImageTemplate(),
getTableTemplate(),
getIngredientsTemplate(),
getCookwareTemplate(),
Expand Down

0 comments on commit 7df1a90

Please sign in to comment.