seo.go 722 B

123456789101112131415161718192021222324252627282930
  1. package admin
  2. import (
  3. "net/http"
  4. "github.com/qor5/admin/example/models"
  5. "github.com/qor5/admin/presets"
  6. "github.com/qor5/admin/seo"
  7. "gorm.io/gorm"
  8. )
  9. // @snippet_begin(SeoExample)
  10. var SeoCollection *seo.Collection
  11. func ConfigureSeo(b *presets.Builder, db *gorm.DB) {
  12. SeoCollection = seo.NewCollection()
  13. SeoCollection.RegisterSEO(&models.Post{}).RegisterContextVariables(
  14. "Title",
  15. func(object interface{}, _ *seo.Setting, _ *http.Request) string {
  16. if article, ok := object.(models.Post); ok {
  17. return article.Title
  18. }
  19. return ""
  20. },
  21. ).RegisterSettingVaribles(struct{ Test string }{})
  22. SeoCollection.RegisterSEOByNames("Product", "Announcement")
  23. SeoCollection.Configure(b, db)
  24. }
  25. // @snippet_end