Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #177 use rendered provider name in default template #178

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/provider/template.go
Expand Up @@ -330,13 +330,15 @@ description: |-

const defaultProviderTemplate providerTemplate = `---
` + frontmatterComment + `
page_title: "{{.ProviderShortName}} Provider"
{{- $name := .ProviderShortName}}
{{- if ne .ProviderName .RenderedProviderName }}{{ $name = .RenderedProviderName}}{{ end }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe the logic is incorrect here as this will always attempt to use .RenderedProviderName since .ProviderName is always going to differ from .RenderedProviderName.

i think what want is more like this:

{- $name := .ProviderShortName}}
{{- if .RenderedProviderName }}{{ $name = .RenderedProviderName }}{{ end }}
page_title: "{{ $name }} Provider"

(this is also more explicit by checking if the rendered provider name value is set, not just different)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think .RenderedProviderName is always set, and its default value is .ProviderName. Here's the reference:

if g.renderedProviderName == "" {
g.renderedProviderName = providerName
}

Feel free to try it out!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobbednarz have you had the chance to check again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't, however, being explicit in the template makes this clear what the expected outcome is instead of relying on overrides within the generation process.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree! Actually, the solution you proposed was the first one that came to my mind as well. Unfortunately, it just doesn't work because the .RenderedProviderName is never unset, as shown in the previous comment.
Thus, this PR will keep the default behaviour the same as it was before, and it overrides the provider name in the template only if the specific variable has been set.

page_title: "{{$name}} Provider"
subcategory: ""
description: |-
{{ .Description | plainmarkdown | trimspace | prefixlines " " }}
---

# {{.ProviderShortName}} Provider
# {{$name}} Provider

{{ .Description | trimspace }}

Expand Down