mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
add Route.ExcludeSitemap method to exclude a route from sitemap, also exclude the offline routes as requested
This commit is contained in:
parent
6f9a453160
commit
00684f9d2e
|
@ -32,6 +32,10 @@ func newApp() *iris.Application {
|
|||
app.Get("/this/{myparam}/should/not/be/listed", handler)
|
||||
app.Get("/this-should-not-be-listed-offline", handler).SetStatusOffline()
|
||||
|
||||
// These should be excluded as well
|
||||
app.Get("/about", handler).ExcludeSitemap()
|
||||
app.Get("/offline", handler).SetStatusOffline()
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
|
@ -439,6 +439,11 @@ func WithOtherValue(key string, val interface{}) Configurator {
|
|||
// WithSitemap enables the sitemap generator.
|
||||
// Use the Route's `SetLastMod`, `SetChangeFreq` and `SetPriority` to modify
|
||||
// the sitemap's URL child element properties.
|
||||
// Excluded routes:
|
||||
// - dynamic
|
||||
// - subdomain
|
||||
// - offline
|
||||
// - ExcludeSitemap method called
|
||||
//
|
||||
// It accepts a "startURL" input argument which
|
||||
// is the prefix for the registered routes that will be included in the sitemap.
|
||||
|
@ -462,7 +467,7 @@ func WithSitemap(startURL string) Configurator {
|
|||
}
|
||||
|
||||
for _, r := range app.GetRoutes() {
|
||||
if !r.IsStatic() || r.Subdomain != "" {
|
||||
if !r.IsStatic() || r.Subdomain != "" || !r.IsOnline() || r.NoSitemap {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ type Route struct {
|
|||
overlappedLink *Route
|
||||
|
||||
// Sitemap properties: https://www.sitemaps.org/protocol.html
|
||||
NoSitemap bool // when this route should be hidden from sitemap.
|
||||
LastMod time.Time `json:"lastMod,omitempty"`
|
||||
ChangeFreq string `json:"changeFreq,omitempty"`
|
||||
Priority float32 `json:"priority,omitempty"`
|
||||
|
@ -238,6 +239,16 @@ func (r *Route) DeepEqual(other *Route) bool {
|
|||
return r.Equal(other) && r.tmpl.Src == other.tmpl.Src
|
||||
}
|
||||
|
||||
// ExcludeSitemap excludes this route page from sitemap generator.
|
||||
// It sets the NoSitemap field to true.
|
||||
//
|
||||
// See `SetLastMod`, `SetChangeFreq`, `SetPriority` methods
|
||||
// and `iris.WithSitemap`.
|
||||
func (r *Route) ExcludeSitemap() *Route {
|
||||
r.NoSitemap = true
|
||||
return r
|
||||
}
|
||||
|
||||
// SetLastMod sets the date of last modification of the file served by this static GET route.
|
||||
func (r *Route) SetLastMod(t time.Time) *Route {
|
||||
r.LastMod = t
|
||||
|
|
|
@ -43,7 +43,7 @@ func getSourceFileLine(ctrlType reflect.Type, m reflect.Method) (string, int) {
|
|||
// }
|
||||
// but BaseCtrl has not the method, *BaseCtrl does:
|
||||
// (c *BaseCtrl) HandleHTTPError(...)
|
||||
// so we are creating a new temporarly value ptr of that type
|
||||
// so we are creating a new temporary value ptr of that type
|
||||
// and searching inside it for the method instead.
|
||||
typ = reflect.New(typ).Type()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user