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

Fix youtube and embed links #14

Merged
merged 21 commits into from
Aug 27, 2021
Merged

Fix youtube and embed links #14

merged 21 commits into from
Aug 27, 2021

Conversation

cansavvy
Copy link
Contributor

@cansavvy cansavvy commented Aug 25, 2021

Summary

This fixes two of the three things to fix mentioned on: #6 (comment)

Fix one:

Markua needs the "watch" version of youtube links.
So where we have a link like: "https://www.youtube.com/embed/" we actually need: "https://www.youtube.com/watch?v="

I've added this change to the existing replace_image_data() function of this package. This function appears to parse out all the html attributes so its the perfect time to fix youtube links.

This works when I've run it locally.

Fix two:

I added the type and poster specification for youtube links as prescribed by @carriewright11 here: #6 (comment)

Edit:

Fix three:

I believe I've made the changes needed for adding the links for instances where knitr::include_url() are used.

@cansavvy
Copy link
Contributor Author

I also ran the code through styler

na_empty(get_html_attr(x = x, name = name, element = element))
})
names(out) = attributes
names(out) <- attributes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the brand new chunk of code that does the youtube link switching.

'height: "{height}",',
'width: "{width}",',
'align: "{align}"',
'type: "{type}"',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added these two new attributes so we can specify the youtube poster image. 🎉

@cansavvy cansavvy changed the title Make youtube links switch to "watch" link Fix youtube links Aug 25, 2021
@cansavvy cansavvy changed the title Fix youtube links Fix youtube and embed links Aug 26, 2021
@cansavvy
Copy link
Contributor Author

I believe this closes #6 and makes leanbuild that much more functional. @carriewright11 do you want to see if this does what you need?

@cansavvy
Copy link
Contributor Author

Oh great. 😩 Windows fails because it wants a Git token to install a dependency. I'll have to fix that.

@cansavvy
Copy link
Contributor Author

The lazy/efficient way around this problem is to use functions that aren't part of stringr so we don't have that dependency. I will probably do this.

@carriewright11
Copy link
Member

I believe this closes #6 and makes leanbuild that much more functional. @carriewright11 do you want to see if this does what you need?

Taking a look now.

@carriewright11
Copy link
Member

Great work! Yeah, looks good. I should test on my files (although maybe you did that?) Can we add instructions to the video conversions - so people know how to expand the videos in Leanpub?(maybe I missed that though).

Does the exclamation mark need to move to the end here:
x <- paste0(x, paste0("Check out this ![link](", myenv$src, ")."))

@cansavvy
Copy link
Contributor Author

Great work! Yeah, looks good. I should test on my files (although maybe you did that?)

I was using the 05-promoting_diversity.Rmd file from your course to test and it looked like what it should be as far as my knowledge but I didn't have the ability to push to Leanpub for the final test.

Can we add instructions to the video conversions - so people know how to expand the videos in Leanpub?(maybe I missed that though).

Sounds good!

Does the exclamation mark need to move to the end here:
x <- paste0(x, paste0("Check out this ![link](", myenv$src, ")."))

The exclamation there is a part of the link but we can certainly make the sentence itself exclamatory. Should there not be a ! in front of the brackets? Perhaps Markua doesn't like that?

@cansavvy
Copy link
Contributor Author

If you would be able to test on Leanpub for real, that'd be great. If you want to do a full test of this before we merge:

  1. Checkout this branch
  2. Run devtools::load_all("leanbuild") from your console
  3. Switch to your cancer leadership course directory.
  4. Run leanbuild::bookdown_to_leanpub()
  5. Commit those changes on a new branch
  6. Preview on leanpub but switch to the new branch you have.

@carriewright11
Copy link
Member

If you would be able to test on Leanpub for real, that'd be great. If you want to do a full test of this before we merge:

  1. Checkout this branch
  2. Run devtools::load_all("leanbuild") from your console
  3. Switch to your cancer leadership course directory.
  4. Run leanbuild::bookdown_to_leanpub()
  5. Commit those changes on a new branch
  6. Preview on leanpub but switch to the new branch you have.

I actually published my course yesterday... so I'd need to look into how that works... if you can preview without modifying the published course. Otherwise we could use the template?

@carriewright11
Copy link
Member

The exclamation there is a part of the link but we can certainly make the sentence itself exclamatory. Should there not be a ! in front of the brackets? Perhaps Markua doesn't like that?

Since these aren't image links, we wouldn't want the ! though right? or maybe I am missing something. And yeah I kinda like the sentence being exclamatory :P but it depends on people's writing styles I suppose.

@carriewright11
Copy link
Member

Should there not be a ! in front of the brackets? Perhaps Markua doesn't like that?

Markua is fine with that for images.

@carriewright11
Copy link
Member

OK I am testing from the template... You can see the test now when you look at the latest preview version on leanpub


## Set defaults for items that haven't been specified

# Default for align is center
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added these two defaults.

R/replace_html.R Outdated
}

# If its an image, use ! otherwise don't
if (!is.null(element) | element == "img") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding logic to handle whether there should be a ! or not

@cansavvy
Copy link
Contributor Author

This is working as far as I can tell, but the one thing that's odd/not working really is the corner part in the videos are gone?

Screen Shot 2021-08-26 at 8 24 20 PM

This is what the tags for the above look like (also note that "middle" doesn't work -- only "center").

{height: "400px", width: "672", align: "middle" type: "video" poster: "http://img.youtube.com/vi/VOCYL-FNbr0/mqdefault.jpg"}
![Click on the lower right corner to expand the screen](https://www.youtube.com/watch?v=VOCYL-FNbr0).
{height: "400px", width: "672", align: "middle" type: "video" poster: "http://img.youtube.com/vi/VOCYL-FNbr0/mqdefault.jpg"}
![Click on the lower right corner to expand the screen](https://www.youtube.com/watch?v=VOCYL-FNbr0).

@cansavvy
Copy link
Contributor Author

This PR has gotten a bit out of hand. I'm going to merge it since it is fixing things and then file separate issues for these new things popping up.

@cansavvy cansavvy merged commit 9c5863e into master Aug 27, 2021
@carriewright11
Copy link
Member

This is working as far as I can tell, but the one thing that's odd/not working really is the corner part in the videos are gone?

They aren't gone... it shows up after pressing play... but idk how to convey that more concisely/ assumed people when they saw the word video would press play. They can actually press twice on the right corner (on nothing) and it will expand- you don't have to click the center to play.

The text appears to be centered but not the video... let me check how I did that...

@carriewright11
Copy link
Member

This is working as far as I can tell, but the one thing that's odd/not working really is the corner part in the videos are gone?

They aren't gone... it shows up after pressing play... but idk how to convey that more concisely/ assumed people when they saw the word video would press play. They can actually press twice on the right corner (on nothing) and it will expand- you don't have to click the center to play.

The text appears to be centered but not the video... let me check how I did that...

Ok here is an example of mine:

{type: video, poster: 'http://img.youtube.com/vi/VOCYL-FNbr0/mqdefault.jpg',height: "400px", width: "100%", align: "middle"}
Click lower right corner of video to expand

I noticed that the comma is missing before align:"middle:" on the code so maybe that is why? Also I only tested with type:video, poster: at the beginning. Idk but maybe that makes a difference.

@cansavvy
Copy link
Contributor Author

I noticed that the comma is missing before align:"middle:" on the code so maybe that is why? Also I only tested with type:video, poster: at the beginning. Idk but maybe that makes a difference.

Perhaps. It's also odd the comma isn't showing up. I'll look into that.

@cansavvy cansavvy mentioned this pull request Aug 27, 2021
@cansavvy cansavvy deleted the cansavvy/link-splitters branch September 28, 2021 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants