Open schmidtsonian opened 5 years ago
Had the same issue as @schmidtsonian and think this works as a solution:
import React from 'react';
class SubscribeButton extends React.Component {
componentDidMount() {
const {
title,
imageUrl,
feedUrl,
itunesLink
} = this.props;
if (typeof window === 'undefined') {
return;
}
const dataKey = `podcastData-${feedUrl}`
window[dataKey] = {
title: title,
subtitle: '',
description: '',
cover: imageUrl,
feeds: [
{
type: 'audio',
format: 'mp3',
url: feedUrl,
'directory-url-itunes': itunesLink
}
]
}
const script = document.createElement('script');
script.async = true;
script.src = 'https://cdn.podlove.org/subscribe-button/javascripts/app.js';
script.setAttribute('class', 'podlove-subscribe-button')
script.setAttribute('data-language', 'en')
script.setAttribute('data-size', 'medium')
script.setAttribute('data-json-data', dataKey)
script.setAttribute('data-color', '#469cd1')
script.setAttribute('data-format', 'rectangle')
script.setAttribute('data-style', 'filled')
this.span.appendChild(script);
}
render() {
const { feedUrl } = this.props;
return <span ref={el => (this.span = el)}>
<noscript>
<a href={feedUrl}>Subscribe to feed</a>
</noscript>
</span>
}
}
export default SubscribeButton;
I'm doing a custom component in next.js with typescript:
but there is an error in the console: