sitemap

package
v0.0.0-...-2fd717b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: AGPL-3.0 Imports: 24 Imported by: 1

Documentation

Overview

Package sitemap contains functions for generating sitemap files.

Index

Constants

View Source
const (
	PriorityHome     float32 = 1.0
	PriorityCategory float32 = 0.8
	PriorityDetail   float32 = 0.6
)

Variables

View Source
var Registry = echo.NewKVxData[Sitemap, any]().
	Add(`article`, echo.T(`文章`), echo.KVxOptX[Sitemap, any](Sitemap{Do: articleSitemap}))

Functions

func CmdGenerate

func CmdGenerate(rootURL, langCode string, sitemapCfg Config) error

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 LocReceive(ctx echo.Context, sm *smg.Sitemap, item *smg.SitemapLoc, langCodes []string, relativeLink func() string) error

func Register

func Register(k, v string, x Sitemap)

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

func VerifyHost(host string) bool

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 Config struct {
	Mode     string // full(全量生成) / incr(增量生成) / clear(删除)
	Group    string
	AllChild bool // 是否同时生成所有子页面中的网址
}

func NewConfig

func NewConfig() Config

type LocGenerator

type LocGenerator func(ctx echo.Context, lastID string, receiver LocReceiver) (newLastID string, err error)

type LocReceiver

type LocReceiver func(item *smg.SitemapLoc, relativeLink func() string) error

type Sitemap

type Sitemap struct {
	Do LocGenerator
}

func (Sitemap) Run

func (a Sitemap) Run(ctx echo.Context, sm *smg.Sitemap, langCodes []string, name string, subDirName string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL