-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
220 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package sitemap | ||
|
||
const ( | ||
xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9" | ||
xmlnsVideo = "http://www.google.com/schemas/sitemap-video/1.1" | ||
) | ||
|
||
type ChangeFrequency string | ||
|
||
const ( | ||
ALWAYS ChangeFrequency = "always" | ||
HOURLY ChangeFrequency = "hourly" | ||
DAILY ChangeFrequency = "daily" | ||
WEEKLY ChangeFrequency = "weekly" | ||
MONTHLY ChangeFrequency = "monthly" | ||
YEARLY ChangeFrequency = "yearly" | ||
NEVER ChangeFrequency = "never" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package sitemap | ||
|
||
import ( | ||
"encoding/xml" | ||
"os" | ||
"time" | ||
) | ||
|
||
type videoSitemap struct { | ||
XMLName xml.Name `xml:"urlset"` | ||
Xmlns string `xml:"xmlns,attr"` | ||
XmlnsVideo string `xml:"xmlns:video,attr"` | ||
URL []VideoURL | ||
} | ||
|
||
type VideoURL struct { | ||
XMLName xml.Name `xml:"url"` | ||
Loc string `xml:"loc"` | ||
Videos []Video `xml:"video"` | ||
} | ||
|
||
type Video struct { | ||
ThumbnailLoc string `xml:"video:thumbnail_loc"` | ||
Title string `xml:"video:title"` | ||
Description string `xml:"video:description"` | ||
ContentLoc string `xml:"video:content_loc"` | ||
PlayerLoc string `xml:"video:player_loc"` | ||
Duration *int `xml:"video:duration,omitempty"` // Optional | ||
Rating *float64 `xml:"video:rating,omitempty"` // Optional | ||
ViewCount *int `xml:"video:view_count,omitempty"` // Optional | ||
PublicationDate *time.Time `xml:"video:publication_date,omitempty"` // Optional | ||
ExpirationDate *time.Time `xml:"video:expiration_date,omitempty"` // Optional | ||
FamilyFriendly *string `xml:"video:family_friendly,omitempty"` // Optional | ||
Restriction *Restriction `xml:"video:restriction,omitempty"` // Optional | ||
Price *Price `xml:"video:price,omitempty"` // Optional | ||
RequiresSubscription *string `xml:"video:requires_subscription,omitempty"` // Optional | ||
Uploader *Uploader `xml:"video:uploader,omitempty"` // Optional | ||
Live *string `xml:"video:live,omitempty"` // Optional | ||
} | ||
|
||
type Restriction struct { | ||
Relationship string `xml:"relationship,attr"` | ||
Country string `xml:",chardata"` | ||
} | ||
|
||
type Price struct { | ||
Currency string `xml:"currency,attr"` | ||
Amount float64 `xml:",chardata"` | ||
} | ||
|
||
type Uploader struct { | ||
Info string `xml:"info,attr"` | ||
Name string `xml:",chardata"` | ||
} | ||
|
||
func NewVideoSitemap() *videoSitemap { | ||
return &videoSitemap{ | ||
Xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9", | ||
XmlnsVideo: "http://www.google.com/schemas/sitemap-video/1.1", | ||
} | ||
} | ||
|
||
func (v *videoSitemap) AddVideoURL(url VideoURL) (err error) { | ||
v.URL = append(v.URL, url) | ||
xmlBytes, err := xml.MarshalIndent(v, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sitemapFile, err := os.Create("sitemaps/sitemap_video.xml") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer sitemapFile.Close() | ||
|
||
if _, err = sitemapFile.Write([]byte(xml.Header)); err != nil { | ||
return err | ||
} | ||
|
||
if _, err = sitemapFile.Write(xmlBytes); err != nil { | ||
return err | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> | ||
<url> | ||
<loc>https://www.example.com/videos/video1.html</loc> | ||
<video> | ||
<video:thumbnail_loc>https://www.example.com/thumbnail/thumbnail1.png</video:thumbnail_loc> | ||
<video:title>example1</video:title> | ||
<video:description>example1 desc</video:description> | ||
<video:content_loc>https://www.example.com</video:content_loc> | ||
<video:player_loc>https://www.example.com</video:player_loc> | ||
</video> | ||
</url> | ||
<url> | ||
<loc>https://www.example.com/videos/video2.html</loc> | ||
<video> | ||
<video:thumbnail_loc>https://www.example.com/thumbnail/thumbnail2.png</video:thumbnail_loc> | ||
<video:title>example2</video:title> | ||
<video:description>example2 desc</video:description> | ||
<video:content_loc>https://www.example.com</video:content_loc> | ||
<video:player_loc>https://www.example.com</video:player_loc> | ||
</video> | ||
</url> | ||
<url> | ||
<loc>https://www.example.com/videos/video3.html</loc> | ||
<video> | ||
<video:thumbnail_loc>https://www.example.com/thumbnail/thumbnail3.png</video:thumbnail_loc> | ||
<video:title>example3</video:title> | ||
<video:description>example3 desc</video:description> | ||
<video:content_loc>https://www.example.com</video:content_loc> | ||
<video:player_loc>https://www.example.com</video:player_loc> | ||
</video> | ||
</url> | ||
</urlset> |