Documentation
¶
Overview ¶
Package sitemap contains functions for generating sitemap files.
Index ¶
- Constants
- Variables
- func CmdGenerate(rootURL, langCode string, sitemapCfg Config) error
- func GenerateIndex(ctx echo.Context, rootURL string, langCodes []string, ...) error
- func GenerateIndexAllLanguage(ctx echo.Context, rootURL string, generateChildPageItems bool, ...) (err error)
- func GenerateSingle(ctx echo.Context, rootURL string, langCodes []string, ...) error
- func GenerateSingleAllLanguage(ctx echo.Context, rootURL string, f *echo.KVx[Sitemap, any], subDir ...string) (err error)
- func LocReceive(ctx echo.Context, sm *smg.Sitemap, item *smg.SitemapLoc, langCodes []string, ...) error
- func Register(k, v string, x Sitemap)
- func RegisterRoute(r echo.RouteRegister, getSubDirName func(echo.Context) string)
- func RemoveAll(subDirs ...string)
- func VerifyHost(host string) bool
- type Config
- type LocGenerator
- type LocReceiver
- type Sitemap
Constants ¶
const ( PriorityHome float32 = 1.0 PriorityCategory float32 = 0.8 PriorityDetail float32 = 0.6 )
Variables ¶
Functions ¶
func CmdGenerate ¶
CmdGenerate 生成sitemap
rootURL: 网站根URL
langCode: 语言代码,多个语言代码用逗号分隔
sitemapCfg: sitemap配置
sitemapCfg.Mode:
full: 全量生成sitemap
incr: 增量生成sitemap
clear: 删除sitemap
sitemapCfg.Group:
如果为空,那么将生成所有组的sitemap
否wise将生成指定组的sitemap
sitemapCfg.AllChild:
是否同时生成所有子页面中的网址
func GenerateIndex ¶
func GenerateIndex(ctx echo.Context, rootURL string, langCodes []string, generateChildPageItems bool, subDir ...string) error
GenerateIndex 生成sitemap索引文件
ctx: Context对象
rootURL: 网站根URL
langCodes: 语言代码,多个语言代码用逗号分隔
generateChildPageItems: 是否生成所有子页面中的网址
subDir: 生成sitemap文件的子目录,可选
生成的sitemap文件将被保存在public/sitemap/目录下
func GenerateIndexAllLanguage ¶
func GenerateIndexAllLanguage(ctx echo.Context, rootURL string, generateChildPageItems bool, subDir ...string) (err error)
GenerateIndexAllLanguage generates the sitemap index file for all languages.
It is a shorthand for calling GenerateIndex with config.FromFile().Language.AllList.
See GenerateIndex for more information.
func GenerateSingle ¶
func GenerateSingle(ctx echo.Context, rootURL string, langCodes []string, f *echo.KVx[Sitemap, any], subDir ...string) error
GenerateSingle 生成sitemap单个文件
ctx: Context对象
rootURL: 网站根URL
langCodes: 语言代码,多个语言代码用逗号分隔
f: 需要生成sitemap的函数
subDir: 生成sitemap文件的子目录,可选
生成的sitemap文件将被保存在public/sitemap/目录下
func GenerateSingleAllLanguage ¶
func GenerateSingleAllLanguage(ctx echo.Context, rootURL string, f *echo.KVx[Sitemap, any], subDir ...string) (err error)
GenerateSingleAllLanguage generates the sitemap index file for a single sitemap generator.
It is a shorthand for calling GenerateSingle with config.FromFile().Language.AllList.
See GenerateSingle for more information.
func LocReceive ¶
func RegisterRoute ¶
func RegisterRoute(r echo.RouteRegister, getSubDirName func(echo.Context) string)
RegisterRoute registers the following endpoints to the given router:
- `/sitemap.xml`: Sitemap XML file
- `/sitemap_index.xml`: Sitemap index XML file
- `/sitemaps/*`: Static Sitemap files
The endpoints are registered with the permGuest meta, which means that they are accessible to all users.
The getSubDirName parameter is a function that takes a context and returns a string representing the subdirectory name for the Sitemap files.
func RemoveAll ¶
func RemoveAll(subDirs ...string)
RemoveAll removes all sitemap files from the public/sitemap/ directory.
If subDirs is empty, it will remove the entire public/sitemap/ directory.
Otherwise, it will remove the specified subdirectories from the public/sitemap/ directory.
For example, if subDirs is ["zh-CN", "en-US"], it will remove the public/sitemap/zh-CN/ and public/sitemap/en-US/ directories.
Note that this function will not return an error even if the directory does not exist.
func VerifyHost ¶
VerifyHost checks if the given host is valid. A valid host is one that only contains characters of [a-zA-Z0-9-] and at least one period (.). The host must also end with a period.
Types ¶
type Config ¶
type LocGenerator ¶
type LocReceiver ¶
type LocReceiver func(item *smg.SitemapLoc, relativeLink func() string) error