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

add scribe #467

Merged
merged 15 commits into from
Jun 2, 2017
Merged

add scribe #467

merged 15 commits into from
Jun 2, 2017

Conversation

Reettaphant
Copy link
Contributor

@Reettaphant Reettaphant commented May 31, 2017

  • add a scribe editor for adding links and lists to video atom description and trail text
  • when updating youtube description, strip links and html tags off the description. If a published video page exists, add a link to the bottom of the description pointing to it

@akash1810 @jennysivapalan @mbarton
out

val usages: JsValue = (capi.capiQuery("/atom/media/" + atomId + "/usage", true) \ "response" \ "results").get
val usagesList = usages.as[List[String]]

val composerPage = usagesList.find(usage => ".*/video/.*".r.pattern.matcher(usage).matches())
Copy link
Contributor

Choose a reason for hiding this comment

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

Regexing on the ID feels brittle. Perhaps we could hit CAPI for each usage and find the first one where type is video?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will do that.

@@ -141,11 +147,40 @@ case class PublishAtomCommand(id: String, override val stores: DataStores, youTu
}
}

private def parseDescriptionForYoutube(description: String): String = {
val html = Jsoup.parse(description)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of interest, what happens if we send HTML in a description to YouTube? I'm wondering if they clean it or if we just end up with garbage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just end up with an error from the youtube api so we can't even update it.

Copy link
Member

Choose a reason for hiding this comment

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

}
}
catch {
case _ => ""
Copy link
Contributor

Choose a reason for hiding this comment

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

When would we hit this case?

@@ -121,12 +121,15 @@ export default {

function updateArticleField(stage, data, composerUrl, pageId) {
if (data.value || data.belongsTo === 'settings') {
const value = data.isHtml
? data.value.split('"').join('\\"')
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work if we put quotes in the text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, although mentioning this made me realise that having double quotes in any text fields (e.g. title) would break syncing back to composer so I'm fixing this to do it for all the fields wit text input.

Copy link
Member

@akash1810 akash1810 left a comment

Choose a reason for hiding this comment

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

A few minor comments, but this looks great! Can we add a couple of screenshots/gifs too?

@@ -141,11 +147,40 @@ case class PublishAtomCommand(id: String, override val stores: DataStores, youTu
}
}

private def parseDescriptionForYoutube(description: String): String = {
val html = Jsoup.parse(description)
Copy link
Member

Choose a reason for hiding this comment

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

@@ -141,11 +147,41 @@ case class PublishAtomCommand(id: String, override val stores: DataStores, youTu
}
}

private def parseDescriptionForYoutube(description: String): String = {
val html = Jsoup.parse(description)
html.select("a").remove()
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the html tags are stripped in the line below (html.text()) so all the list tags will be stripped away. This line removes all links with their content so in the example you shared, all the contents on the list would be removed. If the list contained text instead of a link, the text inside would remain but the list tags would be removed. I guess it would be simpler to always remove all lists, not sure if there is a case when lists are used without links.

private def updateYoutubeMetadata(previewAtom: MediaAtom, asset: Asset) = {

val description = previewAtom.description.map(description => {
Copy link
Member

Choose a reason for hiding this comment

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

this could be moved here so we can use the builder pattern like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we discussed, this becomes difficult because getting the youtube description requires querying capi so I'm just going to leave this here.

@@ -74,6 +74,11 @@
"redux": "^3.6.0",
"redux-thunk": "^2.1.0",
"reqwest": "^2.0.5",
"scribe": "guardian/scribe#fcf4e16",
Copy link
Member

Choose a reason for hiding this comment

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

why are we using scribe on this commit rather than a release?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because scribe hasn't been released for a while so newer versions are not available on npm. I could look into releasing it later today.

.trim()
.replace(/<(?:.|\n)*?>/gm, '')
.split(/\s+/)
.filter(_ => _.length !== 0);
Copy link
Member

Choose a reason for hiding this comment

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

Ooh using _ in js! Controversial!

this.scribe.on('content-changed', this.onContentChange);
this.refs.editor.innerHTML = this.props.value;
}
//this.props.copiedValue
Copy link
Member

Choose a reason for hiding this comment

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

is the linter happy with this?

@@ -121,12 +121,15 @@ export default {

function updateArticleField(stage, data, composerUrl, pageId) {
if (data.value || data.belongsTo === 'settings') {
const value = data.isFreeText
? data.value.split('"').join('\\"')
Copy link
Member

Choose a reason for hiding this comment

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

this looks like a fancy .replace('"', '\"')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replace only replaces one character so this seemed like the simples way of doing it.

Copy link
Member

@akash1810 akash1810 Jun 1, 2017

Choose a reason for hiding this comment

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

.replace(/"/g, '\\"') should work, but its a minor point, so feel free to ignore 😄

@@ -141,11 +147,41 @@ case class PublishAtomCommand(id: String, override val stores: DataStores, youTu
}
}

private def parseDescriptionForYoutube(description: String): String = {

Choose a reason for hiding this comment

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

Maybe the method could show more intent so, removeHtmlTagsForYouTubeDescription. That might help us in the future to remember why we do this?

@Reettaphant Reettaphant merged commit c3f3ba5 into master Jun 2, 2017
@Reettaphant Reettaphant deleted the rv-add-scribe branch June 2, 2017 12:40
@prout-bot
Copy link

Seen on PROD (merged by @Reettaphant 42 minutes and 40 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants