remove old unsplash photocredit if it is an exact match (#947)

main
Michael Fix 5 years ago committed by GitHub
parent 690a363764
commit 622c8a7722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,6 +42,7 @@ const SnippetToolbar = dynamic(() => import('./SnippetToolbar'), {
}) })
const getConfig = omit(['code']) const getConfig = omit(['code'])
const unsplashPhotographerCredit = /\n\n\/\/ Photo by.+?on Unsplash/
class Editor extends React.Component { class Editor extends React.Component {
static contextType = ApiContext static contextType = ApiContext
@ -292,7 +293,9 @@ class Editor extends React.Component {
if (photographer) { if (photographer) {
this.updateState(({ code = DEFAULT_CODE }) => ({ this.updateState(({ code = DEFAULT_CODE }) => ({
...changes, ...changes,
code: code + `\n\n// Photo by ${photographer.name} on Unsplash`, code:
code.replace(unsplashPhotographerCredit, '') +
`\n\n// Photo by ${photographer.name} on Unsplash`,
preset: null preset: null
})) }))
} else { } else {

Loading…
Cancel
Save