Git Product home page Git Product logo

sitemap's Introduction

sitemap GoDoc

Generates sitemaps and index files based on the sitemaps.org protocol.

sitemap.NewSitemapGroup(dir string,name string)

Creates a new group of sitemaps that used a common name.

group := sitemap.NewSitemapGroup("/var/www/blog/public/sitemaps/","blog")

If the sitemap exceed the limit of 50k urls, new sitemaps will have a numeric suffix to the name. Example:

  • blog_1.xml.gz
  • blog_2.xml.gz

group.Add(url sitemap.URL)

Add sitemap.URL to group

now := time.Now()
group.Add(sitemap.URL{
    Loc: "http://example.com/blog/1/",
    ChangeFreq: sitemap.Hourly,
    LastMod: &now,
    Priority: 0.9
    })

group.CloseGroup()

Mandatory operation, handle the rest of the url that has not been added to any sitemap and add, in addition to clean variables and close the channel group

Creating the index file

Currently we have 2 ways to create the index, searching for files in the directory or passing a slice of urls to sitemaps. To generate the slice of sitemaps generated in the last run we GetSavedSitemaps function.

sitemap.GetSavedSitemaps() []string

Returns an array of urls in the sitemaps created script execution

savedSitemaps := sitemap.GetSavedSitemaps()

sitemap.CreateIndexBySlice(savedSitemaps, path) sitemap.Index

index := sitemap.CreateIndexBySlice(savedSitemaps, "http://example.com.br/sitemaps/")

#####OR

sitemap.CreateIndexByScanDir(sitemaps_dir,index_path, path) sitemap.Index

Search all the xml.gz sitemaps_dir directory, uses the modified date of the file as lastModified

path_index is included for the function does not include the url of the index in your own content, if it is present in the same directory.

index := sitemap.CreateIndexByScanDir("/var/www/blog/public/sitemaps/", "/var/www/blog/public/index.xml.gz", "http://example.com.br/sitemaps/")

Warning: this release do not control old sitemaps, when using this method the index can be created with sitemaps that are no longer used. In case you need to delete manually.

sitemap.CreateSitemapIndex(path, sitemap.Index)

creates and gzip the xml index

sitemap.CreateSitemapIndex("/var/www/blog/public/index.xml.gz", index)

sitemap.PingSearchEngines(public_index_path)

Sends a ping to search engines indicating that the index has been updated.

Currently supports Google and Bing.

sitemap.PingSearchEngines("http://exemple.com/index.xml.gz")

##Example There is a very simple example of using the example folder.

sitemap's People

Contributors

vitalbh avatar soktherat avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.