Skip to content

Commit 62e7e2d

Browse files
committed
Make canonical URL configurable
1 parent f103c57 commit 62e7e2d

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

internal/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type Config struct {
5454
// domain. So it could be https://painting.com. This is required for some
5555
// non critical functionality, such as metadata tags.
5656
RootURL string `env:"ROOT_URL"`
57+
// CanonicalURL specifies the original domain, in case we are accessing the
58+
// site via some other domain, such as scribblers.fly.dev
59+
CanonicalURL string `env:"CANONICAL_URL"`
5760
// ServeDirectories is a map of `path` to `directory`. All directories are
5861
// served under the given path.
5962
ServeDirectories map[string]string `env:"SERVE_DIRECTORIES"`
@@ -148,6 +151,9 @@ func Load() (*Config, error) {
148151

149152
// Prevent user error and let the code decide when we need slashes.
150153
config.RootURL = strings.TrimSuffix(config.RootURL, "/")
154+
if config.CanonicalURL == "" {
155+
config.CanonicalURL = config.RootURL
156+
}
151157
config.RootPath = strings.Trim(config.RootPath, "/")
152158

153159
return &config, nil

internal/frontend/http.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type BasePageConfig struct {
5151
// domain. So it could be https://painting.com. This is required for some
5252
// non critical functionality, such as metadata tags.
5353
RootURL string `json:"rootUrl"`
54+
// CanonicalURL specifies the original domain, in case we are accessing the
55+
// site via some other domain, such as scribblers.fly.dev
56+
CanonicalURL string `json:"canonicalUrl"`
5457
}
5558

5659
var fallbackChecksum = uuid.Must(uuid.NewV4()).String()

internal/frontend/index.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ type SSRHandler struct {
4545

4646
func NewHandler(cfg *config.Config) (*SSRHandler, error) {
4747
basePageConfig := &BasePageConfig{
48-
checksums: make(map[string]string),
49-
hash: md5.New(),
50-
Version: version.Version,
51-
Commit: version.Commit,
52-
RootURL: cfg.RootURL,
48+
checksums: make(map[string]string),
49+
hash: md5.New(),
50+
Version: version.Version,
51+
Commit: version.Commit,
52+
RootURL: cfg.RootURL,
53+
CanonicalURL: cfg.CanonicalURL,
5354
}
5455
if cfg.RootPath != "" {
5556
basePageConfig.RootPath = "/" + cfg.RootPath
5657
}
58+
if basePageConfig.CanonicalURL == "" {
59+
basePageConfig.CanonicalURL = basePageConfig.RootURL
60+
}
5761

5862
indexJsRawTemplate, err := txtTemplate.
5963
New("index-js").

internal/frontend/templates/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
<meta name="keywords" content="skribbl, skribbl io, skribblio,
1212
skribbl.io, scribble, scribblers, scribble.rs, pictionary,
1313
montagsmaler, sketchful, draw and guess, drawmything, free, oss">
14-
<!-- Otherwise google will prevent the official hosting from being indexed. -->
15-
<link rel="canonical" href="https://scribblers.bios-marcel.link" />
14+
<link rel="canonical" href="{{.CanonicalURL}}" />
1615
{{if ne "" .RootURL}}
1716
<meta property="og:image" content="{{.RootURL}}{{.RootPath}}/resources/logo.png">
1817
<meta property="og:image:type" content="image/png">

0 commit comments

Comments
 (0)