sitemap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: MIT Imports: 11 Imported by: 0

README

sitemap

XML Sitemap generator

Test

Install

go get github.com/radulucut/sitemap

Usage

package main

import (
	"fmt"
	"os"

	"github.com/radulucut/sitemap"
)

func main() {
	file, err := os.Create("sitemap.xml")
	if err != nil {
		fmt.Printf("Error creating sitemap.xml: %v", err)
	}
	defer file.Close()

	s := sitemap.New()
	sitemap.LastMod = time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)
	sitemap.ChangeFreq = "monthly"

	url := "https://example.com"
	err = s.Generate(file, &url)
	if err != nil {
		fmt.Printf("Error generating sitemap: %v", err)
	}
}

sitemap.xml

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2023-01-01T00:00:00Z</lastmod>
    <priority>1.0</priority>
	<changefreq>monthly</changefreq>
  </url>
</urlset>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sitemap

type Sitemap struct {
	sync.Mutex
	IgnoreQuery bool      // Ignore query string in URLs (i.e. example.com/?foo=bar)
	ChangeFreq  string    // Add <changefreq> to URLs (not added if empty)
	LastMod     time.Time // Add custom <lastmod> to URLs (default is time.Now())
	Verbose     bool      // Verbose logging
	// contains filtered or unexported fields
}

func New

func New() *Sitemap

func (*Sitemap) Generate

func (s *Sitemap) Generate(w io.Writer, url *string) error

Will generate a XML Sitemap for the given URL and write it to the given writer.

type URL

type URL struct {
	Loc   string
	Level int
}

Jump to

Keyboard shortcuts

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