Adding sitemap builder

Changing some links
This commit is contained in:
Andreas Mieke 2015-10-02 15:23:35 +02:00
parent f9d7fd0852
commit 3b41b81725
6 changed files with 116 additions and 8 deletions

View file

@ -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) {

105
gparser/sitemap.go Normal file
View file

@ -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(&LTs)
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)
}
}

View file

@ -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() {

View file

@ -16,14 +16,14 @@
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-6">
{{ range .data }}
<li itemscope itemtype="http://schema.org/Person">
<a class="th" href="/zeige/{{ .AT.Slug.String }}/" itemprop="url">
<a class="th" href="/zeige/{{ .AT.Slug.String }}" itemprop="url">
{{ if .AT.AvatarB.Valid }}
<img alt="" src="{{ .AT.AvatarB.String }}" itemprop="image" />
{{ else }}
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Avatar&w=240&h=240" />
{{ end }}
</a>
<br /><a href="/zeige/{{ .AT.Slug.String }}/"><strong itemprop="name">{{ .AT.Name.String }}</strong></a>
<br /><a href="/zeige/{{ .AT.Slug.String }}"><strong itemprop="name">{{ .AT.Name.String }}</strong></a>
</li>
{{ end }}
</ul>

View file

@ -16,16 +16,16 @@
<ul class="small-block-grid-3 medium-block-grid-5 large-block-grid-5">
{{ range .data }}
<li itemscope itemtype="http://schema.org/TVSeries">
<a class="th" href="/lets-play/{{ .LP.Slug.String }}/" itemprop="url">
<a class="th" href="/lets-play/{{ .LP.Slug.String }}" itemprop="url">
{{ if .LP.PosterS.Valid }}
<img alt="" src="{{ .LP.PosterS.String }}" itemprop="thumbnailUrl" />
{{ else }}
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Cover&w=178&h=265" />
{{ end }}
</a>
<br /><a href="/lets-play/{{ .LP.Slug.String }}/"><strong itemprop="name">{{ .LP.Name.String }}</strong></a>
<br /><a href="/lets-play/{{ .LP.Slug.String }}"><strong itemprop="name">{{ .LP.Name.String }}</strong></a>
<span itemprop="director" itemscope itemtype="http://schema.org/Person">
<br />von <a href="/zeige/{{ .AT.Slug.String }}/" itemprop="url"><span itemprop="name">{{ .AT.Name.String }}</span></a>
<br />von <a href="/zeige/{{ .AT.Slug.String }}" itemprop="url"><span itemprop="name">{{ .AT.Name.String }}</span></a>
</span>
</li>
{{ end }}

View file

@ -16,16 +16,16 @@
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-5">
{{ range .data }}
<li itemscope itemtype="http://schema.org/Movie">
<a class="th" href="/testet/{{ .LT.Slug.String }}/" itemprop="url">
<a class="th" href="/testet/{{ .LT.Slug.String }}" itemprop="url">
{{ if .LT.ThumbS.Valid }}
<img alt="" src="{{ .LT.ThumbS.String }}" itemprop="thumbnailUrl" />
{{ else }}
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Kein%20Thumbnail&w=265&h=149" />
{{ end }}
</a>
<br /><a href="/testet/{{ .LT.Slug.String }}/"><strong itemprop="name">{{ .LT.Name.String }}</strong></a>
<br /><a href="/testet/{{ .LT.Slug.String }}"><strong itemprop="name">{{ .LT.Name.String }}</strong></a>
<span itemprop="director" itemscope itemtype="http://schema.org/Person">
<br />von <a href="/zeige/{{ .AT.Slug.String }}/" itemprop="url"><span itemprop="name">{{ .AT.Name.String }}</span></a>
<br />von <a href="/zeige/{{ .AT.Slug.String }}" itemprop="url"><span itemprop="name">{{ .AT.Name.String }}</span></a>
</span>
</li>
{{ end }}