Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatted timestamps in the transcript should link! #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion packages/gatsby-theme-podcast/src/templates/episode-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Link, graphql } from "gatsby";
import get from "lodash.get";
import PodcastPlayer from "syntax-podcast-player";

import { MDXProvider } from '@mdx-js/react'
import { MDXRenderer } from "gatsby-plugin-mdx";
import Layout from "../components/Layout";
import Support from "../components/Support";
Expand All @@ -11,6 +12,51 @@ import SEO from "../components/SEO";
import { rhythm } from "../utils/typography";

import "./player-styles.css";
import "./transcript.css";

const TranscriptParagraph = props => {
let hasTimestamp = false;
const children = React.Children.toArray(props.children).map((child, i) => {
if (i === 0 && typeof child === "string") {
const timestamp = child.match(/^\[(\d\d):(\d\d)(?::(\d\d))?\]/);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check all the p tags, only check the first child in each one (since we are checking for [00:00:00]

Regex: https://regexr.com/

Screen Shot 2019-08-02 at 1 10 49 AM

Also did some simple stuff to compute the number of seconds from the timestamp..

if (timestamp) {

let seconds = 0;
if (timestamp[3]) {
seconds =
Number(timestamp[1]) * 3600 +
Number(timestamp[2]) * 60 +
Number(timestamp[3]);
} else {
seconds = Number(timestamp[1]) * 60 + Number(timestamp[2]);
}
hasTimestamp = seconds;

return (
<a
key={child}
className="timestamp"
href={`#playFrom=${seconds}`}
>
{child}
</a>
);
}
}
return child;
});

return (
<p id={hasTimestamp ? `playFrom=${hasTimestamp}` : ''}>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we want it to move to the correct paragraph we need an id?? It's covered by the player atm though so it would be nice to move the player to the bottom maybe?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example

test

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way heavybit does it, where there's no jump, and the player sticks to the top on scroll https://www.heavybit.com/library/podcasts/jamstack-radio/ep-42-structuring-content-with-simen-svale-skogsrud-and-knut-melvaer-of-sanity-io/

{children}
</p>
);
};

const components = {
p: TranscriptParagraph,
}

class RssItemPageTemplate extends React.Component {
render() {
const rssItem = this.props.data.rssFeedItem;
Expand Down Expand Up @@ -66,7 +112,9 @@ class RssItemPageTemplate extends React.Component {
}}
/>

<MDXRenderer>{rssItem.childMdx.body}</MDXRenderer>
<MDXProvider components={components}>
<MDXRenderer>{rssItem.childMdx.body}</MDXRenderer>
</MDXProvider>

<p>
<a href={discussUrl} target="_blank" rel="noopener noreferrer">
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-theme-podcast/src/templates/transcript.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.timestamp {
float: left;
margin-left: -4.3rem;
}
Loading