Skip to content

Commit 487db61

Browse files
committed
1 parent d32f3ea commit 487db61

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

claat/parser/md/parse.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const (
5757
MetaTags = "tags"
5858
MetaSource = "source"
5959
MetaDuration = "duration"
60+
MetaHomeURL = "home_url"
6061
)
6162

6263
const (
@@ -437,6 +438,9 @@ func addMetadataToCodelab(m map[string]string, c *types.Codelab, opts parser.Opt
437438
case MetaFeedbackLink:
438439
// Directly assign the feedback link to the codelab field.
439440
c.Feedback = v
441+
case MetaHomeURL:
442+
// Directly assign the home URL to the codelab field.
443+
c.HomeURL = v
440444
case MetaAnalyticsAccount:
441445
// Directly assign the GA id to the codelab field.
442446
c.GA = v

claat/render/template.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@
5959
<script>
6060
hljs.highlightAll();
6161
hljs.addPlugin(new CopyButtonPlugin({ autohide: false}));
62+
{{if .Meta.HomeURL}}
63+
// Override home URL with metadata value
64+
document.addEventListener('DOMContentLoaded', function() {
65+
const homeUrl = "{{.Meta.HomeURL}}";
66+
const arrowBack = document.getElementById('arrow-back');
67+
const doneBtn = document.getElementById('done');
68+
if (arrowBack) arrowBack.href = homeUrl;
69+
if (doneBtn) doneBtn.href = homeUrl;
70+
});
71+
{{end}}
6272
</script>
6373

6474
</body>

claat/types/codelab.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Meta struct {
3636
Feedback string `json:"feedback,omitempty"` // Issues and bugs are sent here
3737
GA string `json:"ga,omitempty"` // Codelab-specific GA tracking ID
3838
GA4 string `json:"ga4,omitempty"` // Codelab-specific GA4 tracking ID
39+
HomeURL string `json:"home_url,omitempty"` // Optional home URL for back/done buttons
3940
Extra map[string]string `json:"extra,omitempty"` // Extra metadata specified in pass_metadata
4041

4142
URL string `json:"url"` // Legacy ID; TODO: remove

0 commit comments

Comments
 (0)