diff --git a/gparser/feedparser.go b/gparser/feedparser.go index e37013b..430a638 100644 --- a/gparser/feedparser.go +++ b/gparser/feedparser.go @@ -67,6 +67,7 @@ func ParseRSSFeeds() { wg.Wait() bar.FinishPrint("Parsed RSS feed for " + AT.Slug.String) } + GenerateSitemap() } func ParseFeedEpisode(u string, bar *pb.ProgressBar) { diff --git a/gparser/sitemap.go b/gparser/sitemap.go new file mode 100644 index 0000000..6e0089e --- /dev/null +++ b/gparser/sitemap.go @@ -0,0 +1,105 @@ +package main + +import ( + "encoding/xml" + "io/ioutil" + "log" + "time" + + "git.1750studios.com/gronkhDE/gogronkh/config" + "git.1750studios.com/gronkhDE/gogronkh/database" +) + +type urlset struct { + Xmlns string `xml:"xmlns,attr"` + Url []URL `xml:"url"` +} + +type URL struct { + Location string `xml:"loc"` + LastMod time.Time `xml:"lastmod"` + ChangeFreq string `xml:"changefreq"` + Priority float32 `xml:"priority"` +} + +func WriteSitemap(path string, sitemap urlset) (error) { + smap, err := xml.Marshal(sitemap) + if err != nil { + return err + } + out := xml.Header + string(smap) + log.Printf("%s", out) + err = ioutil.WriteFile(path, []byte(out), 0644) + return err +} + +func GenerateSitemap() { + var uset urlset + uset.Xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9" + var temp URL + temp.Location = config.C.SiteUrl + "/" + temp.LastMod = time.Now() + temp.ChangeFreq = "hourly" + temp.Priority = 1.0 + uset.Url = append(uset.Url, temp) + temp.Location = config.C.SiteUrl + "/lets-play/" + temp.LastMod = time.Now() + temp.ChangeFreq = "monthly" + temp.Priority = 0.75 + uset.Url = append(uset.Url, temp) + temp.Location = config.C.SiteUrl + "/testet/" + temp.LastMod = time.Now() + temp.ChangeFreq = "monthly" + temp.Priority = 0.75 + uset.Url = append(uset.Url, temp) + temp.Location = config.C.SiteUrl + "/zeige/" + temp.LastMod = time.Now() + temp.ChangeFreq = "yearly" + temp.Priority = 0.75 + uset.Url = append(uset.Url, temp) + genLPs(&uset) + genLTs(&uset) + genEPs(&uset) + WriteSitemap(config.C.AssetsDirectory + "sitemap.xml", uset) +} + +func genLPs(uset *urlset) { + var LPs []database.LetsPlay + database.Db.Find(&LPs) + for _, LP := range LPs { + var temp URL + temp.Location = config.C.SiteUrl + "/lets-play/" + LP.Slug.String + temp.LastMod = LP.Aired + temp.ChangeFreq = "daily" + temp.Priority = 0.5 + uset.Url = append(uset.Url, temp) + } +} + +func genLTs(uset *urlset) { + var LTs []database.LetsTest + database.Db.Find(<s) + for _, LT := range LTs { + var temp URL + temp.Location = config.C.SiteUrl + "/testet/" + LT.Slug.String + temp.LastMod = LT.Aired + temp.ChangeFreq = "never" + temp.Priority = 0.5 + uset.Url = append(uset.Url, temp) + } +} + +func genEPs(uset *urlset) { + var EPs []database.Episode + database.Db.Find(&EPs) + for _, EP := range EPs { + var LP database.LetsPlay + database.Db.Model(&EP).Related(&LP) + var temp URL + temp.Location = config.C.SiteUrl + "/lets-play/" + LP.Slug.String + "/" + EP.Slug.String + temp.LastMod = EP.Aired + temp.ChangeFreq = "never" + temp.Priority = 0.5 + uset.Url = append(uset.Url, temp) + } +} diff --git a/gparser/utils.go b/gparser/utils.go index d8bed39..49378c5 100644 --- a/gparser/utils.go +++ b/gparser/utils.go @@ -17,6 +17,7 @@ func UpdateAll() { log.Printf("*** FINISHED UPDATING LETSPLAYS ***") UpdateEpisodes() log.Printf("*** FINISHED UPDATING EPISODES ***") + GenerateSitemap() } func ParseAll() { @@ -28,6 +29,7 @@ func ParseAll() { log.Printf("*** FINISHED PARSING LETSPLAYS ***") ParseEpisodes() log.Printf("*** FINISHED PARSING EPISODES ***") + GenerateSitemap() } func StartCron() { diff --git a/gserver/templates/ats.html b/gserver/templates/ats.html index 820e00e..c25dc35 100644 --- a/gserver/templates/ats.html +++ b/gserver/templates/ats.html @@ -16,14 +16,14 @@ diff --git a/gserver/templates/lps.html b/gserver/templates/lps.html index 53a2dfa..90cb700 100644 --- a/gserver/templates/lps.html +++ b/gserver/templates/lps.html @@ -16,16 +16,16 @@