Created
March 25, 2021 19:02
-
-
Save ricealexander/09e330fac20efa66d865783c2cb5060e to your computer and use it in GitHub Desktop.
Rigging a Shared Module for Transcripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Transcripts | |
// One possible way to associate transcripts with Grove posts may involve Shared Modules | |
// 1. Insert a Module at the bottom of the news post. | |
// 2. Select Shared Module and create a new Shared Module. | |
// 3. Select RichText Module and give it a subhead at the top titled "Transcript". | |
// 4. Copy/Paste the transcript from Google Docs into the RichText body. | |
// 5. Publish! | |
// | |
// This provides some benefits for us over other strategies: | |
// * Text is the most accessible format for our audience. | |
// * This method can be used by story editors without leaving the story. | |
// * It is just as easy to add a transcript before or after the story is published. | |
// * The transcript travels alongside the story in the Story API | |
// * If the transcript code breaks, the transcript will be printed at the bottom of the story | |
// | |
// With such an approach, we'll need JavaScript that determines whether the story has a transcript | |
// and if so, it should copy the transcript contents and remove the Shared Module. | |
function scrapeTranscript () { | |
let richTextModules = document.querySelectorAll('.RichTextModule') | |
let transcriptModule = null | |
// Find the Transcript Module | |
for (let module of richTextModules) { | |
let subhead = module.querySelector('h2') | |
let heading = subhead && subhead.textContent.trim().toLowerCase() | |
if (heading === 'transcript') { | |
transcriptModule = module | |
break | |
} | |
} | |
if (!transcriptModule) { | |
console.info('No transcript found') | |
return null | |
} | |
let transcriptBody = transcriptModule.querySelector('.RichTextBody') | |
if (!transcriptBody) { | |
console.error('Transcript found, but could not be scraped') | |
} | |
let transcript = transcriptBody.innerHTML // Save the transcript | |
transcriptModule.remove() // Remove the transcript Shared Module | |
console.info('Found a Transcript') | |
console.info(transcript) | |
return transcript | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment