IMprove XSL and podcast XML

This commit is contained in:
JP Hastings-Spital 2025-02-01 10:51:20 +00:00
parent 09de70ba98
commit 9dfeb7ac4e
3 changed files with 34 additions and 8 deletions

View file

@ -6,7 +6,7 @@
{{- end -}} {{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }} {{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
{{- printf "<?xml-stylesheet href=\"/rss.xsl\" type=\"text/xsl\"?>" | safeHTML }} {{- printf "<?xml-stylesheet href=\"/rss.xsl\" type=\"text/xsl\"?>" | safeHTML }}
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel> <channel>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title> <title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink | absURL }}</link> <link>{{ .Permalink | absURL }}</link>
@ -19,6 +19,9 @@
<itunes:image>{{ "profile-512.jpg" | absURL }}</itunes:image>{{ with .Site.Copyright }} <itunes:image>{{ "profile-512.jpg" | absURL }}</itunes:image>{{ with .Site.Copyright }}
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }} <copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }} <lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>{{ end }}
{{- with .OutputFormats.Get "Podcast" -}}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" (.Permalink | absURL) .MediaType | safeHTML }}
{{- end -}}
{{- range $i, $page := $pages -}} {{- range $i, $page := $pages -}}
{{- if not .Page.Params.Audio -}}{{ continue }}{{- end -}} {{- if not .Page.Params.Audio -}}{{ continue }}{{- end -}}
<item>{{ with .Title }} <item>{{ with .Title }}

View file

@ -9,11 +9,13 @@
const title = xmlDoc.querySelector('channel title')?.textContent const title = xmlDoc.querySelector('channel title')?.textContent
const link = xmlDoc.querySelector('channel link')?.textContent const link = xmlDoc.querySelector('channel link')?.textContent
const description = xmlDoc.querySelector('channel description')?.textContent const description = xmlDoc.querySelector('channel description')?.textContent
const image = xmlDoc.querySelector('channel image')?.textContent
const tracks = [...xmlDoc.querySelectorAll('channel item')].map((item) => ({ const tracks = [...xmlDoc.querySelectorAll('channel item')].map((item) => ({
title: item.querySelector('title')?.textContent, title: item.querySelector('title')?.textContent,
link: item.querySelector('link')?.textContent, link: item.querySelector('link')?.textContent,
artist: title, artist: title,
src: item.querySelector('enclosure[type^="audio/"]')?.getAttribute('url'), src: item.querySelector('enclosure[type^="audio/"]')?.getAttribute('url'),
cover: image,
})).filter((track) => !!track.src) })).filter((track) => !!track.src)
return { return {

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/"> <xsl:template match="/">
<xsl:variable name="pageTitle"> <xsl:variable name="pageTitle">
@ -79,12 +79,33 @@
<p> <p>
<xsl:value-of select="/rss/channel/description"/> <xsl:value-of select="/rss/channel/description"/>
</p> </p>
<a hreflang="en" target="_blank"> <ul class="open-in">
<xsl:attribute name="href"> <xsl:if test="/rss/channel/itunes:image">
<xsl:value-of select="/rss/channel/link"/> <li>Use <a hreflang="en" target="_blank">
</xsl:attribute> <xsl:attribute name="href">
Visit this page on my site &#x2192; <xsl:value-of select="concat('podcast:', /rss/channel/atom:link[@rel='self']/@href)" />
</a> </xsl:attribute>
Apple Podcasts &#x2192;
</a></li>
</xsl:if>
<xsl:if test="not(/rss/channel/itunes:image)">
<li>Use <a hreflang="en" target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="concat('feed:', /rss/channel/atom:link[@rel='self']/@href)" />
</xsl:attribute>
Your feed reader &#x2192;
</a></li>
</xsl:if>
<li>
Visit these posts
<a hreflang="en" target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="/rss/channel/link"/>
</xsl:attribute>
on my site instead &#x2192;
</a>
</li>
</ul>
</header> </header>
<main> <main>
<h2>Recent Posts</h2> <h2>Recent Posts</h2>