-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] First setup for social previews in the backend, facebook an…
…d twitter (WIP)
- Loading branch information
Showing
23 changed files
with
404,808 additions
and
3,679 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
|
||
import {FacebookPreview as YoastFacebookPreview} from '@yoast/social-metadata-previews'; | ||
|
||
class FacebookPreview extends React.Component { | ||
|
||
render() { | ||
return ( | ||
<React.Fragment> | ||
<YoastFacebookPreview {...this.props} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
siteUrl: state.facebookPreview.siteBase, | ||
title: state.facebookPreview.title, | ||
description: state.facebookPreview.description, | ||
imageUrl: state.facebookPreview.imageUrl | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(FacebookPreview); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
import {TwitterPreview as YoastTwitterPreview} from '@yoast/social-metadata-previews'; | ||
|
||
class TwitterPreview extends React.Component { | ||
|
||
render() { | ||
return ( | ||
<React.Fragment> | ||
<YoastTwitterPreview {...this.props} /> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
siteUrl: state.twitterPreview.siteBase, | ||
title: state.twitterPreview.title, | ||
description: state.twitterPreview.description, | ||
imageUrl: state.twitterPreview.imageUrl | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(TwitterPreview); |
This file contains 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
41 changes: 41 additions & 0 deletions
41
Build/resources/javascript/redux/actions/facebookPreview.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const UPDATE_FACEBOOK_PREVIEW = 'UPDATE_FACEBOOK_PREVIEW'; | ||
|
||
export function getFacebookData(imageUrl, siteBase) { | ||
return dispatch => { | ||
|
||
let ogTitle = getInputValue(YoastConfig.fieldSelectors.ogTitle); | ||
if (ogTitle === '') { | ||
ogTitle = getInputValue(YoastConfig.fieldSelectors.pageTitle); | ||
} | ||
let ogDescription = getInputValue(YoastConfig.fieldSelectors.ogDescription); | ||
console.log(ogDescription + '?'); | ||
if (ogDescription === '') { | ||
ogDescription = getInputValue(YoastConfig.fieldSelectors.description); | ||
} | ||
|
||
dispatch({ | ||
type: UPDATE_FACEBOOK_PREVIEW, | ||
payload: { | ||
title: ogTitle, | ||
description: ogDescription, | ||
siteBase: siteBase, | ||
imageUrl: imageUrl | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
function getInputValue(fieldName) { | ||
let inputField = document.querySelector('[name="' + fieldName + '"]'); | ||
if (inputField) { | ||
return inputField.value; | ||
} | ||
return ''; | ||
} | ||
|
||
export function updateFacebookData(content) { | ||
return { | ||
type: UPDATE_FACEBOOK_PREVIEW, | ||
payload: content | ||
}; | ||
} |
This file contains 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
40 changes: 40 additions & 0 deletions
40
Build/resources/javascript/redux/actions/twitterPreview.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const UPDATE_TWITTER_PREVIEW = 'UPDATE_TWITTER_PREVIEW'; | ||
|
||
export function getTwitterData(imageUrl, siteBase) { | ||
return dispatch => { | ||
|
||
let twitterTitle = getInputValue(YoastConfig.fieldSelectors.twitterTitle); | ||
if (twitterTitle === '') { | ||
twitterTitle = getInputValue(YoastConfig.fieldSelectors.pageTitle); | ||
} | ||
let twitterDescription = getInputValue(YoastConfig.fieldSelectors.twitterDescription); | ||
if (twitterDescription === '') { | ||
twitterDescription = getInputValue(YoastConfig.fieldSelectors.description); | ||
} | ||
|
||
dispatch({ | ||
type: UPDATE_TWITTER_PREVIEW, | ||
payload: { | ||
title: twitterTitle, | ||
description: twitterDescription, | ||
siteBase: siteBase, | ||
imageUrl: imageUrl | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
function getInputValue(fieldName) { | ||
let inputField = document.querySelector('[name="' + fieldName + '"]'); | ||
if (inputField) { | ||
return inputField.value; | ||
} | ||
return ''; | ||
} | ||
|
||
export function updateTwitterData(content) { | ||
return { | ||
type: UPDATE_TWITTER_PREVIEW, | ||
payload: content | ||
}; | ||
} |
12 changes: 12 additions & 0 deletions
12
Build/resources/javascript/redux/reducers/facebookPreview.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {UPDATE_FACEBOOK_PREVIEW} from '../actions/facebookPreview'; | ||
|
||
const initialState = ''; | ||
|
||
export default (state = initialState, action) => { | ||
switch(action.type) { | ||
case UPDATE_FACEBOOK_PREVIEW: | ||
return {...state, ...action.payload}; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains 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
12 changes: 12 additions & 0 deletions
12
Build/resources/javascript/redux/reducers/twitterPreview.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {UPDATE_TWITTER_PREVIEW} from '../actions/twitterPreview'; | ||
|
||
const initialState = ''; | ||
|
||
export default (state = initialState, action) => { | ||
switch(action.type) { | ||
case UPDATE_TWITTER_PREVIEW: | ||
return {...state, ...action.payload}; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,9 @@ | |
"languageteam": "Yoast Translate <[email protected]>", | ||
"lasttranslator": "Yoast Translate Team <[email protected]>" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@yoast/social-metadata-previews": "^2.0.0-alpha.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/YoastSeoForTypo3/t3ext-yoast-seo.git" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,3 +250,9 @@ div.yoast-analysis { | |
} | ||
} | ||
} | ||
|
||
#facebookPreview { | ||
span.screen-reader-text { | ||
display: none; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.