Skip to content

Commit 1430db6

Browse files
authored
Merge pull request #259 from neural-loop/main
feat: Add video sitemap
2 parents 1ecba48 + 4d32cbb commit 1430db6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

hugo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ target = '$1'
5656

5757
############################# Outputs ############################
5858
[outputs]
59-
home = ["HTML", "RSS"]
59+
home = ["HTML", "RSS", "videoSitemap"]
6060
section = ["HTML", "RSS"] # Add this line
6161
############################# Imaging ############################
6262
[imaging]
@@ -109,6 +109,12 @@ baseName = "searchindex"
109109
isPlainText = true
110110
notAlternative = true
111111

112+
[outputFormats.videoSitemap]
113+
mediaType = "application/xml"
114+
baseName = "video-sitemap"
115+
isPlainText = false
116+
notAlternative = true
117+
112118

113119
############################# Plugins ##############################
114120

layouts/index.videoSitemap.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{- printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | safeHTML -}}
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
3+
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
4+
{{- $eventPages := where site.RegularPages "Section" "workshops" -}}
5+
{{- $eventPages = $eventPages | union (where site.RegularPages "Type" "in" (slice "student-talks" "hacking-hours")) -}}
6+
7+
{{- $videoPages := slice -}}
8+
{{- range $eventPages -}}
9+
{{- if and .Params.video (ne .Params.video "") (ne .Params.upcoming true) -}}
10+
{{- $videoPages = $videoPages | append . -}}
11+
{{- end -}}
12+
{{- end -}}
13+
14+
{{- range $videoPages -}}
15+
{{- $pageSlug := path.Base .File.Dir -}}
16+
{{- $ogImageName := printf "%s-og-16x9.jpg" $pageSlug -}}
17+
{{- $ogImageResource := .Resources.GetMatch $ogImageName -}}
18+
19+
{{- $thumbnail_url := printf "https://i.ytimg.com/vi/%s/maxresdefault.jpg" .Params.video -}}
20+
{{- if $ogImageResource -}}
21+
{{- $thumbnail_url = $ogImageResource.Permalink -}}
22+
{{- end -}}
23+
<url>
24+
<loc>{{ .Permalink }}</loc>
25+
<video:video>
26+
<video:thumbnail_loc>{{ $thumbnail_url }}</video:thumbnail_loc>
27+
<video:title>{{ .Title | plainify }}</video:title>
28+
<video:description>{{ .Description | plainify }}</video:description>
29+
<video:player_loc>https://www.youtube.com/embed/{{ .Params.video }}</video:player_loc>
30+
{{- with .Date -}}
31+
<video:publication_date>{{ .Format "2006-01-02T15:04:05-07:00" }}</video:publication_date>
32+
{{- end -}}
33+
<video:uploader info="{{ site.BaseURL | absLangURL }}">{{ site.Title }}</video:uploader>
34+
<video:live>no</video:live>
35+
</video:video>
36+
</url>
37+
{{- end -}}
38+
</urlset>

0 commit comments

Comments
 (0)