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 all commits
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
52 changes: 51 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,49 @@ import SEO from "../components/SEO";
import { rhythm } from "../utils/typography";

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

const TranscriptParagraph = props => {
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]);
}

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

return (
<p>
{children}
</p>
);
};

const components = {
p: TranscriptParagraph,
}

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

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

<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;
}
10 changes: 8 additions & 2 deletions podcast-site/content/episodes/0-intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ ygatsby: meh

## Transcript

Person 1: [00:00](#playFrom=0) So hi, yep, what's up everyone?
[00:00] **Henry**: All right. We decided to make a bonus episode. So Nadia wrote a post a month ago about her reading of a book called ["The Death and Life of Great American Cities"]. It talks about cities and how that relates to open source and communities online, that open source is kind of like a digital city. Same with the internet.

Person 2: [00:29](#playFrom=29) Yep we're making a podcast.
[00:21] **Henry**: That got me looking into my own research on the topic. I found a paper called ["The City as Liturgy"]. And so I thought it'd be cool to bring on the author. So right now we have Dr. Timothy Patitsas, with us. He's a Assistant Professor of Orthodox Christian Ethics at Holy Cross Greek Orthodox School of Theology in Boston. And he wrote a dissertation called, "The King Returns to His City, an Interpretation of the Great Week and Bright Week Cycle of the Orthodox Church". Thanks for joining us today.

[00:57] **Timothy**: Thank you, Henry. And thank you, Nadia. Thanks for bringing me on.

[01:02] **Nadia**: That'll be good if we start just by talking a little bit about this theory that you had about City as Liturgy and your reading of Jane Jacobs' work just for the benefit of everyone who hasn't read her work and, also just as a refresher of like what liturgy is and like how that relates to cities in your mind.

[01:19] **Timothy**: So to start with Jane Jacobs, she did not finish college. She did do a couple of years at Colombia in the 1930s. And when she got to a point where they insisted that she choose a major she quit. She wanted to be free to organize her education any way she saw fit. And I mean to follow the intellectual leads as they came to her.

## Credits

Expand Down