-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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))?\]/); | ||
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}` : ''}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.timestamp { | ||
float: left; | ||
margin-left: -4.3rem; | ||
} |
There was a problem hiding this comment.
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/
Also did some simple stuff to compute the number of seconds from the timestamp..