Add SEO controls and sitemap for compliance pages
Add search engine indexing toggle, robots.txt, and sitemap.xml generation for compliance pages. Replace checkboxes with toggle components in the compliance page UI and add an "Open" button in the page header to quickly access the live compliance page. The search engine indexing toggle is disabled when the compliance page is inactive. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
5
pkg/coredata/migrations/20260324T120000Z.sql
Normal file
5
pkg/coredata/migrations/20260324T120000Z.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE trust_centers
|
||||
ADD COLUMN search_engine_indexing TEXT NOT NULL DEFAULT 'NOT_INDEXABLE';
|
||||
|
||||
ALTER TABLE trust_centers
|
||||
ALTER COLUMN search_engine_indexing DROP DEFAULT;
|
||||
77
pkg/coredata/search_engine_indexing.go
Normal file
77
pkg/coredata/search_engine_indexing.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SearchEngineIndexing string
|
||||
|
||||
const (
|
||||
SearchEngineIndexingIndexable SearchEngineIndexing = "INDEXABLE"
|
||||
SearchEngineIndexingNotIndexable SearchEngineIndexing = "NOT_INDEXABLE"
|
||||
)
|
||||
|
||||
func (s SearchEngineIndexing) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
func (s SearchEngineIndexing) IsValid() bool {
|
||||
switch s {
|
||||
case SearchEngineIndexingIndexable, SearchEngineIndexingNotIndexable:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *SearchEngineIndexing) UnmarshalText(text []byte) error {
|
||||
*s = SearchEngineIndexing(text)
|
||||
if !s.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid SearchEngineIndexing", string(text))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SearchEngineIndexing) MarshalText() ([]byte, error) {
|
||||
return []byte(s.String()), nil
|
||||
}
|
||||
|
||||
func (s *SearchEngineIndexing) Scan(value any) error {
|
||||
var str string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
str = v
|
||||
case []byte:
|
||||
str = string(v)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type for SearchEngineIndexing: %T", value)
|
||||
}
|
||||
|
||||
switch str {
|
||||
case "INDEXABLE":
|
||||
*s = SearchEngineIndexingIndexable
|
||||
case "NOT_INDEXABLE":
|
||||
*s = SearchEngineIndexingNotIndexable
|
||||
default:
|
||||
return fmt.Errorf("invalid SearchEngineIndexing value: %q", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SearchEngineIndexing) Value() (driver.Value, error) {
|
||||
return s.String(), nil
|
||||
}
|
||||
@@ -30,17 +30,18 @@ import (
|
||||
|
||||
type (
|
||||
TrustCenter struct {
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
Active bool `db:"active"`
|
||||
Slug string `db:"slug"`
|
||||
MailingListID *gid.GID `db:"mailing_list_id"`
|
||||
LogoFileID *gid.GID `db:"logo_file_id"`
|
||||
DarkLogoFileID *gid.GID `db:"dark_logo_file_id"`
|
||||
NonDisclosureAgreementFileID *gid.GID `db:"non_disclosure_agreement_file_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
ID gid.GID `db:"id"`
|
||||
OrganizationID gid.GID `db:"organization_id"`
|
||||
TenantID gid.TenantID `db:"tenant_id"`
|
||||
Active bool `db:"active"`
|
||||
Slug string `db:"slug"`
|
||||
SearchEngineIndexing SearchEngineIndexing `db:"search_engine_indexing"`
|
||||
MailingListID *gid.GID `db:"mailing_list_id"`
|
||||
LogoFileID *gid.GID `db:"logo_file_id"`
|
||||
DarkLogoFileID *gid.GID `db:"dark_logo_file_id"`
|
||||
NonDisclosureAgreementFileID *gid.GID `db:"non_disclosure_agreement_file_id"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
TrustCenters []*TrustCenter
|
||||
@@ -85,6 +86,7 @@ SELECT
|
||||
dark_logo_file_id,
|
||||
active,
|
||||
slug,
|
||||
search_engine_indexing,
|
||||
non_disclosure_agreement_file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -136,6 +138,7 @@ SELECT
|
||||
dark_logo_file_id,
|
||||
active,
|
||||
slug,
|
||||
search_engine_indexing,
|
||||
non_disclosure_agreement_file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -187,6 +190,7 @@ SELECT
|
||||
dark_logo_file_id,
|
||||
active,
|
||||
slug,
|
||||
search_engine_indexing,
|
||||
non_disclosure_agreement_file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -238,6 +242,7 @@ SELECT
|
||||
dark_logo_file_id,
|
||||
active,
|
||||
slug,
|
||||
search_engine_indexing,
|
||||
non_disclosure_agreement_file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -284,6 +289,7 @@ INSERT INTO trust_centers (
|
||||
dark_logo_file_id,
|
||||
active,
|
||||
slug,
|
||||
search_engine_indexing,
|
||||
non_disclosure_agreement_file_id,
|
||||
created_at,
|
||||
updated_at
|
||||
@@ -296,6 +302,7 @@ INSERT INTO trust_centers (
|
||||
@dark_logo_file_id,
|
||||
@active,
|
||||
@slug,
|
||||
@search_engine_indexing,
|
||||
@non_disclosure_agreement_file_id,
|
||||
@created_at,
|
||||
@updated_at
|
||||
@@ -311,6 +318,7 @@ INSERT INTO trust_centers (
|
||||
"dark_logo_file_id": tc.DarkLogoFileID,
|
||||
"active": tc.Active,
|
||||
"slug": tc.Slug,
|
||||
"search_engine_indexing": tc.SearchEngineIndexing,
|
||||
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
||||
"created_at": tc.CreatedAt,
|
||||
"updated_at": tc.UpdatedAt,
|
||||
@@ -340,6 +348,7 @@ UPDATE trust_centers
|
||||
SET
|
||||
active = @active,
|
||||
slug = @slug,
|
||||
search_engine_indexing = @search_engine_indexing,
|
||||
logo_file_id = @logo_file_id,
|
||||
dark_logo_file_id = @dark_logo_file_id,
|
||||
non_disclosure_agreement_file_id = @non_disclosure_agreement_file_id,
|
||||
@@ -357,6 +366,7 @@ WHERE
|
||||
"dark_logo_file_id": tc.DarkLogoFileID,
|
||||
"active": tc.Active,
|
||||
"slug": tc.Slug,
|
||||
"search_engine_indexing": tc.SearchEngineIndexing,
|
||||
"non_disclosure_agreement_file_id": tc.NonDisclosureAgreementFileID,
|
||||
"updated_at": tc.UpdatedAt,
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ type (
|
||||
ID gid.GID
|
||||
Active *bool
|
||||
Slug *string
|
||||
SearchEngineIndexing *coredata.SearchEngineIndexing
|
||||
NonDisclosureAgreementFileID *gid.GID
|
||||
}
|
||||
|
||||
@@ -178,6 +179,9 @@ func (s TrustCenterService) Update(
|
||||
if req.Slug != nil {
|
||||
trustCenter.Slug = *req.Slug
|
||||
}
|
||||
if req.SearchEngineIndexing != nil {
|
||||
trustCenter.SearchEngineIndexing = *req.SearchEngineIndexing
|
||||
}
|
||||
trustCenter.UpdatedAt = time.Now()
|
||||
|
||||
if err := trustCenter.Update(ctx, conn, s.svc.scope); err != nil {
|
||||
|
||||
@@ -41,3 +41,43 @@ func (h *Handler) HandleLLMsTxt(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) HandleRobotsTxt(w http.ResponseWriter, r *http.Request) {
|
||||
tc := CompliancePageFromContext(r.Context())
|
||||
if tc == nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
baseURL := CompliancePageBaseURLFromContext(r.Context())
|
||||
if baseURL == nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
|
||||
if err := h.trustService.RenderRobotsTxt(r.Context(), w, tc.SearchEngineIndexing, *baseURL); err != nil {
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) HandleSitemap(w http.ResponseWriter, r *http.Request) {
|
||||
tc := CompliancePageFromContext(r.Context())
|
||||
if tc == nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
baseURL := CompliancePageBaseURLFromContext(r.Context())
|
||||
if baseURL == nil {
|
||||
http.Error(w, "not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
|
||||
if err := h.trustService.RenderSitemap(r.Context(), w, tc.ID, tc.TenantID, *baseURL); err != nil {
|
||||
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,20 @@ enum TrustCenterVisibility
|
||||
)
|
||||
}
|
||||
|
||||
enum SearchEngineIndexing
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/coredata.SearchEngineIndexing"
|
||||
) {
|
||||
INDEXABLE
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.SearchEngineIndexingIndexable"
|
||||
)
|
||||
NOT_INDEXABLE
|
||||
@goEnum(
|
||||
value: "go.probo.inc/probo/pkg/coredata.SearchEngineIndexingNotIndexable"
|
||||
)
|
||||
}
|
||||
|
||||
enum ControlImplementationState
|
||||
@goModel(
|
||||
model: "go.probo.inc/probo/pkg/coredata.ControlImplementationState"
|
||||
@@ -1685,6 +1699,7 @@ type TrustCenter implements Node
|
||||
) {
|
||||
id: ID!
|
||||
active: Boolean!
|
||||
searchEngineIndexing: SearchEngineIndexing!
|
||||
logoFileUrl: String @goField(forceResolver: true)
|
||||
darkLogoFileUrl: String @goField(forceResolver: true)
|
||||
ndaFileName: String
|
||||
@@ -3893,6 +3908,7 @@ input UpdateOrganizationContextInput {
|
||||
input UpdateTrustCenterInput {
|
||||
trustCenterId: ID!
|
||||
active: Boolean
|
||||
searchEngineIndexing: SearchEngineIndexing
|
||||
}
|
||||
|
||||
input UploadTrustCenterNDAInput {
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
type TrustCenter struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Active bool `json:"active"`
|
||||
SearchEngineIndexing coredata.SearchEngineIndexing `json:"searchEngineIndexing"`
|
||||
LogoFileURL *string `json:"logoFileUrl,omitempty"`
|
||||
DarkLogoFileURL *string `json:"darkLogoFileUrl,omitempty"`
|
||||
NdaFileName *string `json:"ndaFileName,omitempty"`
|
||||
@@ -53,9 +54,10 @@ func NewTrustCenter(tc *coredata.TrustCenter, file *coredata.File) *TrustCenter
|
||||
Organization: &Organization{
|
||||
ID: tc.OrganizationID,
|
||||
},
|
||||
Active: tc.Active,
|
||||
NdaFileName: ndaFileName,
|
||||
CreatedAt: tc.CreatedAt,
|
||||
UpdatedAt: tc.UpdatedAt,
|
||||
Active: tc.Active,
|
||||
SearchEngineIndexing: tc.SearchEngineIndexing,
|
||||
NdaFileName: ndaFileName,
|
||||
CreatedAt: tc.CreatedAt,
|
||||
UpdatedAt: tc.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2106,8 +2106,9 @@ func (r *mutationResolver) UpdateTrustCenter(ctx context.Context, input types.Up
|
||||
trustCenter, file, err := prb.TrustCenters.Update(
|
||||
ctx,
|
||||
&probo.UpdateTrustCenterRequest{
|
||||
ID: input.TrustCenterID,
|
||||
Active: input.Active,
|
||||
ID: input.TrustCenterID,
|
||||
Active: input.Active,
|
||||
SearchEngineIndexing: input.SearchEngineIndexing,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -178,6 +178,8 @@ func (s *Server) trustCenterRouter() chi.Router {
|
||||
|
||||
r.Mount("/api/trust/v1", s.apiServer.CompliancePageHandler())
|
||||
r.Get("/llms.txt", h.HandleLLMsTxt)
|
||||
r.Get("/robots.txt", h.HandleRobotsTxt)
|
||||
r.Get("/sitemap.xml", h.HandleSitemap)
|
||||
r.Handle("/*", s.trustWebServer)
|
||||
|
||||
return r
|
||||
|
||||
@@ -31,6 +31,12 @@ import (
|
||||
//go:embed compliance.md.tmpl
|
||||
var complianceTmplContent string
|
||||
|
||||
//go:embed sitemap.xml.tmpl
|
||||
var sitemapTmplContent string
|
||||
|
||||
//go:embed robots.txt.tmpl
|
||||
var robotsTmplContent string
|
||||
|
||||
var complianceTmpl = template.Must(
|
||||
template.New("compliance").
|
||||
Funcs(template.FuncMap{
|
||||
@@ -44,6 +50,14 @@ var complianceTmpl = template.Must(
|
||||
Parse(complianceTmplContent),
|
||||
)
|
||||
|
||||
var sitemapTmpl = template.Must(
|
||||
template.New("sitemap").Parse(sitemapTmplContent),
|
||||
)
|
||||
|
||||
var robotsTmpl = template.Must(
|
||||
template.New("robots").Parse(robotsTmplContent),
|
||||
)
|
||||
|
||||
type (
|
||||
compliancePageData struct {
|
||||
OrgName string
|
||||
@@ -166,6 +180,105 @@ func (s *Service) RenderCompliancePageMarkdown(
|
||||
return nil
|
||||
}
|
||||
|
||||
type (
|
||||
sitemapData struct {
|
||||
BaseURL string
|
||||
Documents []string
|
||||
}
|
||||
|
||||
robotsData struct {
|
||||
Indexable bool
|
||||
BaseURL string
|
||||
}
|
||||
)
|
||||
|
||||
func (s *Service) RenderSitemap(
|
||||
ctx context.Context,
|
||||
w io.Writer,
|
||||
trustCenterID gid.GID,
|
||||
tenantID gid.TenantID,
|
||||
baseURL string,
|
||||
) error {
|
||||
org, err := s.GetOrganizationByTrustCenterID(ctx, trustCenterID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load organization for sitemap: %w", err)
|
||||
}
|
||||
|
||||
tenantSvc := s.WithTenant(tenantID)
|
||||
|
||||
data := &sitemapData{
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
|
||||
data.Documents, err = s.fetchDocumentIDs(ctx, tenantSvc, org.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot fetch document IDs for sitemap: %w", err)
|
||||
}
|
||||
|
||||
if err := sitemapTmpl.Execute(w, data); err != nil {
|
||||
return fmt.Errorf("cannot render sitemap: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) RenderRobotsTxt(
|
||||
ctx context.Context,
|
||||
w io.Writer,
|
||||
searchEngineIndexing coredata.SearchEngineIndexing,
|
||||
baseURL string,
|
||||
) error {
|
||||
data := &robotsData{
|
||||
Indexable: searchEngineIndexing == coredata.SearchEngineIndexingIndexable,
|
||||
BaseURL: baseURL,
|
||||
}
|
||||
|
||||
if err := robotsTmpl.Execute(w, data); err != nil {
|
||||
return fmt.Errorf("cannot render robots.txt: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) fetchDocumentIDs(ctx context.Context, tenantSvc *TenantService, orgID gid.GID) ([]string, error) {
|
||||
var ids []string
|
||||
|
||||
var cursorKey *page.CursorKey
|
||||
for {
|
||||
cursor := page.NewCursor(
|
||||
page.MaxCursorSize,
|
||||
cursorKey,
|
||||
page.Head,
|
||||
page.OrderBy[coredata.DocumentOrderField]{
|
||||
Field: coredata.DocumentOrderFieldTitle,
|
||||
Direction: page.OrderDirectionAsc,
|
||||
},
|
||||
)
|
||||
|
||||
result, err := tenantSvc.Documents.ListForOrganizationId(ctx, orgID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list documents: %w", err)
|
||||
}
|
||||
|
||||
for _, doc := range result.Data {
|
||||
if doc.TrustCenterVisibility == coredata.TrustCenterVisibilityNone {
|
||||
continue
|
||||
}
|
||||
ids = append(ids, doc.ID.String())
|
||||
}
|
||||
|
||||
if !result.Info.HasNext {
|
||||
break
|
||||
}
|
||||
|
||||
last := result.Data[len(result.Data)-1]
|
||||
ck := last.CursorKey(coredata.DocumentOrderFieldTitle)
|
||||
cursorKey = &ck
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (s *Service) fetchComplianceFrameworks(ctx context.Context, tenantSvc *TenantService, trustCenterID gid.GID) ([]compliancePageFramework, error) {
|
||||
var frameworks []compliancePageFramework
|
||||
|
||||
|
||||
9
pkg/trust/robots.txt.tmpl
Normal file
9
pkg/trust/robots.txt.tmpl
Normal file
@@ -0,0 +1,9 @@
|
||||
{{- if .Indexable }}
|
||||
User-Agent: *
|
||||
Allow: /
|
||||
|
||||
Sitemap: {{ .BaseURL }}/sitemap.xml
|
||||
{{- else }}
|
||||
User-Agent: *
|
||||
Disallow: /
|
||||
{{- end }}
|
||||
18
pkg/trust/sitemap.xml.tmpl
Normal file
18
pkg/trust/sitemap.xml.tmpl
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>{{ .BaseURL }}/overview</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>{{ .BaseURL }}/documents</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>{{ .BaseURL }}/subprocessors</loc>
|
||||
</url>
|
||||
<url>
|
||||
<loc>{{ .BaseURL }}/updates</loc>
|
||||
</url>
|
||||
{{ range .Documents }} <url>
|
||||
<loc>{{ $.BaseURL }}/documents/{{ . }}</loc>
|
||||
</url>
|
||||
{{ end }}</urlset>
|
||||
Reference in New Issue
Block a user