Adding sitemap builder
Changing some links
This commit is contained in:
parent
f9d7fd0852
commit
3b41b81725
|
@ -67,6 +67,7 @@ func ParseRSSFeeds() {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
bar.FinishPrint("Parsed RSS feed for " + AT.Slug.String)
|
bar.FinishPrint("Parsed RSS feed for " + AT.Slug.String)
|
||||||
}
|
}
|
||||||
|
GenerateSitemap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseFeedEpisode(u string, bar *pb.ProgressBar) {
|
func ParseFeedEpisode(u string, bar *pb.ProgressBar) {
|
||||||
|
|
105
gparser/sitemap.go
Normal file
105
gparser/sitemap.go
Normal 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(<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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ func UpdateAll() {
|
||||||
log.Printf("*** FINISHED UPDATING LETSPLAYS ***")
|
log.Printf("*** FINISHED UPDATING LETSPLAYS ***")
|
||||||
UpdateEpisodes()
|
UpdateEpisodes()
|
||||||
log.Printf("*** FINISHED UPDATING EPISODES ***")
|
log.Printf("*** FINISHED UPDATING EPISODES ***")
|
||||||
|
GenerateSitemap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseAll() {
|
func ParseAll() {
|
||||||
|
@ -28,6 +29,7 @@ func ParseAll() {
|
||||||
log.Printf("*** FINISHED PARSING LETSPLAYS ***")
|
log.Printf("*** FINISHED PARSING LETSPLAYS ***")
|
||||||
ParseEpisodes()
|
ParseEpisodes()
|
||||||
log.Printf("*** FINISHED PARSING EPISODES ***")
|
log.Printf("*** FINISHED PARSING EPISODES ***")
|
||||||
|
GenerateSitemap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartCron() {
|
func StartCron() {
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-6">
|
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-6">
|
||||||
{{ range .data }}
|
{{ range .data }}
|
||||||
<li itemscope itemtype="http://schema.org/Person">
|
<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 }}
|
{{ if .AT.AvatarB.Valid }}
|
||||||
<img alt="" src="{{ .AT.AvatarB.String }}" itemprop="image" />
|
<img alt="" src="{{ .AT.AvatarB.String }}" itemprop="image" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Avatar&w=240&h=240" />
|
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Avatar&w=240&h=240" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</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>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
<ul class="small-block-grid-3 medium-block-grid-5 large-block-grid-5">
|
<ul class="small-block-grid-3 medium-block-grid-5 large-block-grid-5">
|
||||||
{{ range .data }}
|
{{ range .data }}
|
||||||
<li itemscope itemtype="http://schema.org/TVSeries">
|
<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 }}
|
{{ if .LP.PosterS.Valid }}
|
||||||
<img alt="" src="{{ .LP.PosterS.String }}" itemprop="thumbnailUrl" />
|
<img alt="" src="{{ .LP.PosterS.String }}" itemprop="thumbnailUrl" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Cover&w=178&h=265" />
|
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=24&txt=Kein%20Cover&w=178&h=265" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</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">
|
<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>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -16,16 +16,16 @@
|
||||||
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-5">
|
<ul class="small-block-grid-2 medium-block-grid-4 large-block-grid-5">
|
||||||
{{ range .data }}
|
{{ range .data }}
|
||||||
<li itemscope itemtype="http://schema.org/Movie">
|
<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 }}
|
{{ if .LT.ThumbS.Valid }}
|
||||||
<img alt="" src="{{ .LT.ThumbS.String }}" itemprop="thumbnailUrl" />
|
<img alt="" src="{{ .LT.ThumbS.String }}" itemprop="thumbnailUrl" />
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Kein%20Thumbnail&w=265&h=149" />
|
<img alt="" src="https://placeholdit.imgix.net/~text?txtsize=36&txt=Kein%20Thumbnail&w=265&h=149" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</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">
|
<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>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue