Skip to content

Commit 756e72f

Browse files
authored
feat: Add the ability to insert text after the package title (#2323)
The current use case for this is to advise users of equivalent Firebase packages. For example: ```toml readme-after-title-text = """> [!TIP] > Flutter applications should use [Firebase AI Logic](https://firebase.google.com/products/firebase-ai-logic). > > The Generate Language API is meant for Dart desktop and cloud applications. > Firebase AI Logic provides client-side access to both the Gemini Developer > API and Vertex AI. """ ``` Which results in a README.md that looks like: <img width="1485" height="909" alt="image" src="https://github.com/user-attachments/assets/a1c9120e-eafd-4394-9562-48c595ab4960" />
1 parent 669121e commit 756e72f

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

internal/sidekick/internal/dart/annotate.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ type modelAnnotations struct {
4747
DefaultHost string
4848
DocLines []string
4949
// A reference to an optional hand-written part file.
50-
PartFileReference string
51-
PackageDependencies []packageDependency
52-
Imports []string
53-
DevDependencies []string
54-
DoNotPublish bool
55-
RepositoryURL string
50+
PartFileReference string
51+
PackageDependencies []packageDependency
52+
Imports []string
53+
DevDependencies []string
54+
DoNotPublish bool
55+
RepositoryURL string
56+
ReadMeAfterTitleText string
5657
}
5758

5859
// HasServices returns true if the model has services.
@@ -206,13 +207,14 @@ func newAnnotateModel(model *api.API) *annotateModel {
206207
// [Template.Services] field.
207208
func (annotate *annotateModel) annotateModel(options map[string]string) error {
208209
var (
209-
packageNameOverride string
210-
generationYear string
211-
packageVersion string
212-
partFileReference string
213-
doNotPublish bool
214-
devDependencies = []string{}
215-
repositoryURL string
210+
packageNameOverride string
211+
generationYear string
212+
packageVersion string
213+
partFileReference string
214+
doNotPublish bool
215+
devDependencies = []string{}
216+
repositoryURL string
217+
readMeAfterTitleText string
216218
)
217219

218220
for key, definition := range options {
@@ -237,6 +239,9 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
237239
)
238240
}
239241
doNotPublish = value
242+
case key == "readme-after-title-text":
243+
// Markdown that will be inserted into the README.md after the title section.
244+
readMeAfterTitleText = definition
240245
case key == "repository-url":
241246
repositoryURL = definition
242247
case strings.HasPrefix(key, "proto:"):
@@ -314,13 +319,14 @@ func (annotate *annotateModel) annotateModel(options map[string]string) error {
314319
}
315320
return ""
316321
}(),
317-
DocLines: formatDocComments(model.Description, model.State),
318-
Imports: calculateImports(annotate.imports),
319-
PartFileReference: partFileReference,
320-
PackageDependencies: packageDependencies,
321-
DevDependencies: devDependencies,
322-
DoNotPublish: doNotPublish,
323-
RepositoryURL: repositoryURL,
322+
DocLines: formatDocComments(model.Description, model.State),
323+
Imports: calculateImports(annotate.imports),
324+
PartFileReference: partFileReference,
325+
PackageDependencies: packageDependencies,
326+
DevDependencies: devDependencies,
327+
DoNotPublish: doNotPublish,
328+
RepositoryURL: repositoryURL,
329+
ReadMeAfterTitleText: readMeAfterTitleText,
324330
}
325331

326332
model.Codec = ann

internal/sidekick/internal/dart/annotate_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ func TestAnnotateModel_Options(t *testing.T) {
8484
}
8585
},
8686
},
87+
{
88+
map[string]string{"readme-after-title-text": "> [!TIP] Still beta!"},
89+
func(t *testing.T, am *annotateModel) {
90+
codec := model.Codec.(*modelAnnotations)
91+
if diff := cmp.Diff("> [!TIP] Still beta!", codec.ReadMeAfterTitleText); diff != "" {
92+
t.Errorf("mismatch in Codec.ReadMeAfterTitleText (-want, +got)\n:%s", diff)
93+
}
94+
},
95+
},
8796
{
8897
map[string]string{"repository-url": "http://example.com/repo"},
8998
func(t *testing.T, am *annotateModel) {

internal/sidekick/internal/dart/templates/README.md.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ The Google Cloud client library for the {{{Title}}}.
2626

2727
We welcome feedback about the APIs, documentation, missing features, bugs, etc.
2828

29+
{{#Codec.ReadMeAfterTitleText}}
30+
{{{Codec.ReadMeAfterTitleText}}}
31+
32+
{{/Codec.ReadMeAfterTitleText}}
2933
## What's this?
3034

3135
The Google Cloud client library for the {{{Title}}}.

0 commit comments

Comments
 (0)