forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use neutral language in comments and docs (go-gitea#20135) Fix remove file on initial comment (go-gitea#20127) Add doctor command to write commit-graphs (go-gitea#20007) Add sitemap support (go-gitea#18407) Use new config options (go-gitea#20125) Remove depricated queue indexer usage (go-gitea#20124) Disable status checks in template if none found (go-gitea#20088) Fix typos related to ErrTaskDoesNotExist error (go-gitea#20118)
- Loading branch information
Showing
27 changed files
with
372 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package sitemap | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
"fmt" | ||
"io" | ||
"time" | ||
) | ||
|
||
// sitemapFileLimit contains the maximum size of a sitemap file | ||
const sitemapFileLimit = 50 * 1024 * 1024 | ||
|
||
// Url represents a single sitemap entry | ||
type URL struct { | ||
URL string `xml:"loc"` | ||
LastMod *time.Time `xml:"lastmod,omitempty"` | ||
} | ||
|
||
// SitemapUrl represents a sitemap | ||
type Sitemap struct { | ||
XMLName xml.Name | ||
Namespace string `xml:"xmlns,attr"` | ||
|
||
URLs []URL `xml:"url"` | ||
} | ||
|
||
// NewSitemap creates a sitemap | ||
func NewSitemap() *Sitemap { | ||
return &Sitemap{ | ||
XMLName: xml.Name{Local: "urlset"}, | ||
Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9", | ||
} | ||
} | ||
|
||
// NewSitemap creates a sitemap index. | ||
func NewSitemapIndex() *Sitemap { | ||
return &Sitemap{ | ||
XMLName: xml.Name{Local: "sitemapindex"}, | ||
Namespace: "http://www.sitemaps.org/schemas/sitemap/0.9", | ||
} | ||
} | ||
|
||
// Add adds a URL to the sitemap | ||
func (s *Sitemap) Add(u URL) { | ||
s.URLs = append(s.URLs, u) | ||
} | ||
|
||
// Write writes the sitemap to a response | ||
func (s *Sitemap) WriteTo(w io.Writer) (int64, error) { | ||
if len(s.URLs) > 50000 { | ||
return 0, fmt.Errorf("The sitemap contains too many URLs: %d", len(s.URLs)) | ||
} | ||
buf := bytes.NewBufferString(xml.Header) | ||
if err := xml.NewEncoder(buf).Encode(s); err != nil { | ||
return 0, err | ||
} | ||
if err := buf.WriteByte('\n'); err != nil { | ||
return 0, err | ||
} | ||
if buf.Len() > sitemapFileLimit { | ||
return 0, fmt.Errorf("The sitemap is too big: %d", buf.Len()) | ||
} | ||
return buf.WriteTo(w) | ||
} |
Oops, something went wrong.