-
Notifications
You must be signed in to change notification settings - Fork 3
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
add scribe #467
Conversation
e477402
to
1119653
Compare
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()) |
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.
Regexing on the ID feels brittle. Perhaps we could hit CAPI for each usage and find the first one where type
is video
?
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.
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) |
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.
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
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.
We just end up with an error from the youtube api so we can't even update it.
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.
YT accept all characters except <
and >
(https://developers.google.com/youtube/v3/docs/videos#snippet.description)
} | ||
} | ||
catch { | ||
case _ => "" |
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.
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('\\"') |
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.
Does this work if we put quotes in the text?
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.
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.
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.
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) |
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.
YT accept all characters except <
and >
(https://developers.google.com/youtube/v3/docs/videos#snippet.description)
@@ -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() |
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.
Should we also strip off <ul>
s? e.g. this video https://www.theguardian.com/environment/video/2017/may/31/faceless-fish-rediscovered-in-australian-waters-video-report
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.
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 => { |
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.
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.
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", |
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.
why are we using scribe on this commit rather than a release?
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.
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); |
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.
Ooh using _
in js! Controversial!
this.scribe.on('content-changed', this.onContentChange); | ||
this.refs.editor.innerHTML = this.props.value; | ||
} | ||
//this.props.copiedValue |
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.
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('\\"') |
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.
this looks like a fancy .replace('"', '\"')
?
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.
Replace only replaces one character so this seemed like the simples way of doing it.
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.
.replace(/"/g, '\\"')
should work, but its a minor point, so feel free to ignore 😄
15ab286
to
0dd8bcb
Compare
@@ -141,11 +147,41 @@ case class PublishAtomCommand(id: String, override val stores: DataStores, youTu | |||
} | |||
} | |||
|
|||
private def parseDescriptionForYoutube(description: String): String = { |
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.
Maybe the method could show more intent so, removeHtmlTagsForYouTubeDescription
. That might help us in the future to remember why we do this?
0dd8bcb
to
6f9f81c
Compare
Seen on PROD (merged by @Reettaphant 42 minutes and 40 seconds ago) Please check your changes! |
@akash1810 @jennysivapalan @mbarton